Latex:如何在表格内的多行中打破行

kok*_*ing 29 latex tabular multirow

我无法找到如何在表格中打破多行内部的行.我需要制作一些表格,其中我有一个单元格,两行高,我有长文本,但它不会破坏行,文本与左侧的另一个单元格重叠.

有什么建议?

代码示例:

\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}
Run Code Online (Sandbox Code Playgroud)

Tom*_*art 35

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}
Run Code Online (Sandbox Code Playgroud)

乳胶文件中的parbox

  • @lllllllllllll只需将“ \ centering”添加到“ parbox”内容中,例如:“ {\ centering要打破的长文本}” (3认同)

Ste*_*joa 11

你可以尝试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}
Run Code Online (Sandbox Code Playgroud)

但是,在您的特定情况下,我的建议只是放松其他列的限制,因为那里浪费了太多空间.每个都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}
Run Code Online (Sandbox Code Playgroud)


lov*_*sus 11

对我来说是最短最实用的答案:

使用\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}
Run Code Online (Sandbox Code Playgroud)

而已!

唯一可能的问题是,在不可能的情况下,其他单元格中的文本非常短,可能看起来像这样: 正确宽度的文字破碎但遗憾地走出桌子

但是,如果通常你的表在其他单元格上的文本比"sth1"更多,那么它看起来会很棒: 在此输入图像描述


小智 7

对我来说,它使用了"multirow"的内置命令 - {*}是"{width}"