如何允许多行列自动扩展以适合换行的文本段落(而无需嵌套其他列)?我正在尝试寻找一种比在相邻列中添加人工空间更优雅的解决方案,因为第一列中的文本在不同版本中的长度会有所不同。
\documentclass{article}
\usepackage{index}
\usepackage{array}
\usepackage{multirow}
\usepackage{multicol}
\begin{document}
\begin{table}[]
\centering
\begin{tabular}{|p{4cm}|cc|}
\hline
\multirow{3}{4cm}{This is a long paragraph of important information that should not spill over into the cell below, but as you can see, it is indeed spilling.}
& \multicolumn{1}{c|}{\multirow{2}{*}{xxx}} & xxx \\ \cline{3-3}
& \multicolumn{1}{c|}{} & xxx \\ \cline{2-3}
& \multicolumn{2}{c|}{xxx} \\ \hline
\end{tabular}
\end{table}
\end{document}
答案1
这实际上超出了 的合理范围multirow
。正如另一个答案所示,有时您可以解决它,但它需要一些猜测,并且在更复杂的情况下会变得太难。
更好的解决方案是使用tabularray
包;它就是为此而设计的。
\documentclass{article}
\usepackage{index}
\usepackage{array}
\usepackage{tabularray}
\usepackage{multirow}
\begin{document}
\begin{table}
\centering
\begin{tblr}{|p{4cm}|c|c|}
\hline
\SetCell[r=3]{l}{This is a long paragraph of important information that should not spill over into the cell below, but as you can see, it is indeed spilling.}
& \SetCell[r=2]{c}{xxx} & xxx \\ \cline{3-3}
& & xxx \\ \cline{2-3}
& \SetCell[c=2]{c}{xxx} & \\ \hline
\end{tblr}
\end{table}
\end{document}
答案2
使用垂直扩展单元格\renewcommand{\arraystretch}{<factor>}
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}[htp!]
\centering
\renewcommand{\arraystretch}{2.3} % added <<<<<<<<<<
\begin{tabular}{|p{4cm}|cc|}
\hline
\multirow{3}{4cm}{This is a long paragraph of important information that should not spill over into the cell below, but as you can see, it is indeed spilling.}
& \multicolumn{1}{c|}{\multirow{2}{*}{xxx}} & xxx \\ \cline{3-3}
& \multicolumn{1}{c|}{} & xxx \\ \cline{2-3}
& \multicolumn{2}{c|}{xxx} \\ \hline
\end{tabular}
\end{table}
\end{document}