我无法找到如何在表格中打破多行内部的行。我需要制作一些表格,其中我有一个单元格,两行高,我有长文本,但它不会破坏行,文本与左侧的另一个单元格重叠。
有什么建议?
代码示例:
\begin{center}
\begin{tabular}{|p{1cm}|p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
\hline
\multirow{2}{*}{Long text to break} % HERE IS A PROBLEM
& Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3}
\\ \cline{2-6}
& sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\ \hline
\hline
\end{tabular}
\end{center}
你可以尝试minipage
它:
\begin{center}
\begin{tabular}{|l|l|l|l|l|l|}
\hline
\multirow{2}{*}{\begin{minipage}{0.5in}Long text to break\end{minipage}}
& Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3} \\
\cline{2-6}
& sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\
\hline
\hline
\end{tabular}
\end{center}
但是,在您的特定情况下,我的建议只是放松其他列的限制,因为那里浪费了太多空间。使用每个p{}
,强制其他列为一定宽度,因此第一列没有足够的空间。
编译时,下面的代码看起来像我:
\begin{center}
\begin{tabular}{|l|l|l|l|l|l|}
\hline
\multirow{2}{*}{Long text to break}
& Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3} \\
\cline{2-6}
& sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\
\hline
\hline
\end{tabular}
\end{center}
p
专栏和\parbox
也有效:
\usepackage{multirow}
\begin{document}
\begin{center}
\begin{tabular}{|p{1.5cm}|l|l|l|l|l|}
\hline
\multirow{2}{*}{\parbox{1.5cm}{Long text to break}}
& Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3} \\
\cline{2-6}
& sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\
\hline
\hline
\end{tabular}
\end{center}
\end{document}
对我来说是最短最实用的答案:
使用\linewidth
作为{width}
参数的长度。
\usepackage{multirow}
\begin{document}
\begin{center}
\begin{tabular}{|p{1cm}|p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
\hline
\multirow{2}{\linewidth}{Long text to break} % HERE IS A PROBLEM
& Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3}
\\ \cline{2-6}
& sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\ \hline
\hline
\end{tabular}
\end{center}
\end{document}
而已!
唯一可能的问题是,在不可能的情况下,其他单元格中的文本非常短,可能看起来像这样:
但是,如果通常你的表在其他单元格上有比“sth1”更多的文本,它看起来会很棒:
对我来说,它使用了“multirow”的内置命令 - {*}是“{width}”
另外,使用parbox
和\\
:
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{center}
\begin{tabular}{|p{1cm}|p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
\hline
\multirow{2}{*}{\parbox{1cm}{Long\\ text\\ to\\ break}} % NOT A PROBLEM?
& Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3}
\\ \cline{2-6}
& sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\ \hline
\hline
\end{tabular}
\end{center}
\end{document}
无论如何要小心,不要超过细胞的边缘。