我感觉你可以使用复制列tabulary
的行为L
tabularray
但我无法让它工作。我想要的是,只要表格的自然宽度低于某个阈值(此处为\linewidth
),列就会按其自然宽度排版,但只要表格的自然宽度超出阈值,列就会收缩以确保表格的实际宽度等于阈值。
在我的示例中,我发布了四个表格:
- 两个用
tabulary
和 - 两个用 做成的
tabularray
。
每对表格都有两种形式:
- 其中第一个单元格包含一段短文本(以确保表格的自然宽度小于
\linewidth
)和 - 其中第一个单元格包含长文本(以确保表格的自然宽度超过
\linewidth
)。
我所追求的是一个表格的通用列规范tabularray
,使它们表现得像tabulary
表格一样。
\documentclass{article}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\usepackage{tabularray}
\usepackage{tabulary}
\begin{document}
\section*{\texttt{tabulary}}
\begin{table}[ht]
\begin{tabulary}{\linewidth}{@{} L *{4}{c} @{}}
\hline
The text in this cell can be short & A & B & C & D \\
\hline
\end{tabulary}
\end{table}
\begin{table}[ht]
\begin{tabulary}{\linewidth}{@{} L *{4}{c} @{}}
\hline
But it can also be really, really, really, really long. So long in fact the line needs to wrap in order to make room for it & A & B & C & D \\
\hline
\end{tabulary}
\end{table}
\newpage
\section*{\texttt{tabularray}}
\begin{table}[ht]
\begin{tblr}{
colspec={@{}X[-1,l,h,]*{4}{Q[c, h]}@{}},
}
\hline
The text in this cell can be short & A & B & C & D \\
\hline
\end{tblr}
\end{table}
\begin{table}[ht]
\begin{tblr}{
colspec={@{}X[-1,l,h,]*{4}{Q[c, h]}@{}},
}
\hline
But it can also be really, really, really, really long. So long in fact the line needs to wrap in order to make room for it & A & B & C & D \\
\hline
\end{tblr}
\end{table}
\end{document}