使用 tabularray 包的带有 \RaggedRight 的表格

使用 tabularray 包的带有 \RaggedRight 的表格

我可以将表格列设置为左右,但我的问题是是否有更简单的方法将列设置为不规则的:

在此处输入图片描述

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

在此处输入图片描述

相关内容