lvjr / tabularray

Typeset tabulars and arrays with LaTeX3
https://ctan.org/pkg/tabularray
258 stars 22 forks source link

Long caption gets wrapped within table width #255

Open atxy-blip opened 2 years ago

atxy-blip commented 2 years ago

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

lvjr commented 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.

image

atxy-blip commented 2 years ago

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.

lvjr commented 2 years ago

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.

atxy-blip commented 2 years ago

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

Skillmon commented 1 year ago

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