首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Latex:如何在表格中的多行中换行

Latex:如何在表格中的多行中换行
EN

Stack Overflow用户
提问于 2010-10-22 03:41:40
回答 5查看 89.2K关注 0票数 34

我找不到如何在表格中将多行中的行断开。我需要制作一些表格,其中我有一个两行高的单元格,其中有很长的文本,但它不会中断行,并且文本与左侧的另一个单元格重叠。

有什么建议吗?

代码示例:

代码语言:javascript
复制
\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}
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2010-10-22 05:01:23

你可以尝试minipage它:

代码语言:javascript
复制
\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{},这会强制其他列具有一定的宽度,因此没有足够的空间容纳第一列。

当我编译以下代码时,它看起来还不错:

代码语言:javascript
复制
\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}
票数 15
EN

Stack Overflow用户

发布于 2012-03-27 20:38:07

p列和\parbox也有效:

代码语言:javascript
复制
\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}

票数 38
EN

Stack Overflow用户

发布于 2015-02-02 23:08:31

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

使用\linewidth作为{width}参数的长度。

代码语言:javascript
复制
\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“,它将看起来很棒:

票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3991259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档