我可以将表格列设置为左右,但我的问题是是否有更简单的方法将列设置为不规则的:
\documentclass{scrbook}
\usepackage{tabularx}
\usepackage{tabularray}
\usepackage{ragged2e}
\begin{document}
\begin{center}
% Style changes
\small\renewcommand{\arraystretch}{1.4}
% tabular
\small
\begin{tblr}{width=0.9\textwidth, colspec={X[l]|X[c]|X[r]}}
\hline
variable (left) &
variable (center) &
variable (right) \\ \hline
%
text which is considerably longer than the width of the column &
text which is considerably longer than the width of the column &
text which is considerably longer than the width of the column \\
\hline
\end{tblr}
%Using RaggedRight and RaggedLeft
\begin{tblr}{width=0.9\textwidth, colspec={>{\RaggedRight\arraybackslash\hspace{0pt}}X|>{\Centering\arraybackslash\hspace{0pt}}X|>{\RaggedLeft\arraybackslash\hspace{0pt}}X}}
\hline
variable (left) &
variable (center) &
variable (right) \\ \hline
%
text which is considerably longer than the width of the column &
text which is considerably longer than the width of the column &
text which is considerably longer than the width of the column \\
\hline
\end{tblr}
\end{center}
\end{document}
答案1
您可以重新定义\TblrAlign...
宏:
\documentclass{scrbook}
\usepackage{tabularray}
\usepackage{ragged2e}
\begin{document}
\begin{center}
\small
\RenewDocumentCommand\TblrAlignLeft{}{\RaggedRight}
\RenewDocumentCommand\TblrAlignCenter{}{\Centering}
\RenewDocumentCommand\TblrAlignRight{}{\RaggedLeft}
\begin{tblr}{width=0.9\textwidth, colspec={X[l]|X[c]|X[r]}}
\hline
variable (left) &
variable (center) &
variable (right) \\ \hline
%
text which is considerably longer than the width of the column &
text which is considerably longer than the width of the column &
text which is considerably longer than the width of the column \\
\hline
\end{tblr}
\end{center}
\begin{center}
\small
\begin{tblr}{width=0.9\textwidth, colspec={X[l]|X[c]|X[r]}}
\hline
variable (left) &
variable (center) &
variable (right) \\ \hline
%
text which is considerably longer than the width of the column &
text which is considerably longer than the width of the column &
text which is considerably longer than the width of the column \\
\hline
\end{tblr}
\end{center}
\end{document}