LaTeX中表格多行显示的最简单设置方法

这事实上是一个非常easy的问题,可是这两天发现我之前的解决方式太麻烦了。简介一下这样的最简单的方法:

之前设置多行显示的时候,用类似于以下这样的方法进行多行显示:

\begin{table}
\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}
  \centering
  \begin{tabular}{|c|c|c|}
        \hline
            \tabincell{c}{1\\2\\3\\4\\5} &
            \tabincell{c}{1\\2\\3\\4\\5} &
            \tabincell{c}{1\\2\\3\\4\\5}
            \\
        \hline
    \end{tabular}
\end{table}

可是这样的方法有个问题,有时候我们并不知道单元格在什么时候应该换行(比如单元格里有非常多文字,可是非常难精确地把这些文字划分到每一行中,这时候用以下这样的方法,能够让LaTeX自己主动分行:

\begin{table}
  \centering
  \begin{tabular}{|c|p{3cm}|}
        \hline a & bbb\\
        \hline a & This is a very long sentence that may exceed the bound of this table.\\
        \hline
  \end{tabular}
\end{table}

用p{3cm}这样的方法限制了第二列的最大宽度。就这么简单的经验,记录一下。





posted @ 2014-11-11 11:16  yxwkaifa  阅读(4262)  评论(0编辑  收藏  举报