Open atxy-blip opened 2 years ago
You can define a template for this use case:
\documentclass{article}
\usepackage{tabularray}
\DefTblrTemplate{firsthead}{caption}{%
\makebox[\tablewidth]{\parbox{\columnwidth}{%
\UseTblrTemplate{caption}{normal}%
}}%
}
\SetTblrTemplate{firsthead}{caption}
\begin{document}
\begin{table}[htbp]
\centering
\begin{talltblr}[
caption = {long long long long long long long long caption}
] {cc}
\hline
first & second \\
\hline
\end{talltblr}
\end{table}
\begin{table}[htbp]
\centering
\caption{long long long long long long long long caption}
\begin{tblr}{cc}
\hline
first & second \\
\hline
\end{tblr}
\end{table}
\end{document}
It is better to use \columnwidth
instead of \textwidth
since it works for both onecolumn and twocolumn documents.
Many thanks for your timely aid! The patch provided above works perfectly in my case.
However, I would still like to restate my standpoint that the caption in talltblr
and longtblr
should work in accord with normal captions. People would expect the caption to expand as its natural width. In other words, please consider taking the patch as the default setup of those environments.
Sorry, it is not a patch, but a template, because I don't think it is a bug. In many aspects, tabularray
is different from traditional tables.
Also, making breaking changes is dangerous, and will probably bring complaints from users, since more and more people are using this package.
But it is quite possible that I will add this template to the package in a future release and document it in the manual.
But it is quite possible that I will add this template to the package in a future release and document it in the manual
Then I will leave this issue as opened and patiently wait for the doc improvement to take effect : )
Would be even better to use \linewidth
to make it correctly work in \parbox
.
Hi! When using
tabularray
as a general solution to typesetting tables, I would encounter some relatively tight tables with extra long captions. The traditional\caption
solution leaves the caption text naturally spread to page width. On the other hand, usingtalltblr
will cause the caption text to be confined within table width, as is shown in the following MWE.I believe
\tablewidth
will work fine for\TblrNote
, yet not suitable for captions. So far I haven't found an explicit way to modify this by referring the package documentation. So, is it possible thattabularray
will unify the width with normal\caption
command, orwidth
will be added as an available key for the element of caption?