tabularray icon indicating copy to clipboard operation
tabularray copied to clipboard

Long caption gets wrapped within table width

Open atxy-blip opened this issue 2 years ago • 5 comments

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, using talltblr 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 that tabularray will unify the width with normal \caption command, or width will be added as an available key for the element of caption?

\documentclass{article}
\usepackage{tabularray}

\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}

\end{document}

image

atxy-blip avatar May 30 '22 14:05 atxy-blip

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.

image

lvjr avatar May 31 '22 00:05 lvjr

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.

atxy-blip avatar May 31 '22 12:05 atxy-blip

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.

lvjr avatar Jun 01 '22 00:06 lvjr

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 : )

atxy-blip avatar Jun 01 '22 01:06 atxy-blip

Would be even better to use \linewidth to make it correctly work in \parbox.

Skillmon avatar May 27 '23 20:05 Skillmon