我声明了一个这样的宏:
\newcommand{\itemcell}[1]{%
\begin{tabular}[t]{@{}l@{}}#1\end{tabular}
}
然而,我现在正在为此苦苦挣扎,因为它不再允许自动换行。请参见以下示例:
\begin{longtable}{p{4cm}p{1.5cm}p{1.2cm}p{1.2cm}p{1.2cm}p{\dimexpr\columnwidth-9.1cm-12\tabcolsep\relax}}
\toprule
Title 1 & Title 2 & Title 3 & Title 4 & Title 5 & Title 6 \\
\midrule
a & b & c & d & e & \itemcell{This is a very long description which won't fit in 1 line, it should break, but it won't\\And this is a second line} \\
\bottomrule
\end{longtable}
的内容\itemcell{}
不会在列尾换行,超出范围hbox
则会传入。
我该如何安排这个宏来恢复默认行为?
答案1
p
列允许换行,因此根本不需要宏,只需使用
\begin{longtable}{p{4cm}p{1.5cm}p{1.2cm}p{1.2cm}p{1.2cm}p{\dimexpr\columnwidth-9.1cm-12\tabcolsep\relax}}
\toprule
Title 1 & Title 2 & Title 3 & Title 4 & Title 5 & Title 6 \\
\midrule
a & b & c & d & e &
This is a very long description which won't fit in 1 line, it should break, but it won't
And this is a second line\\
\bottomrule
\end{longtable}
在一c
列中,您可以在本地使用嵌套表格来允许多行手动换行,但您的定义添加了虚假的空白,因为它缺少%
\newcommand{\itemcell}[1]{%
\begin{tabular}[t]{@{}l@{}}#1\end{tabular}%%%%
}