首页 > 代码库 > LaTeX中表格多行显示的最简单设置方法
LaTeX中表格多行显示的最简单设置方法
这其实是一个很简单的问题,但是这两天发现我之前的解决方案太麻烦了。简单介绍一下这种最简单的方法:
之前设置多行显示的时候,用类似于下面这种方法进行多行显示:
\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}这种方法限制了第二列的最大宽度。就这么简单的经验,记录一下。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。