madio 发表于 2013-2-20 07:05

Latex 表格单元格内自动换行(转载)

Latex 表格单元格内换行
问题:如何同时让表格同一行一个单元格的文字能垂直居中?比如说文字超长超出页面范围需要分行显示
答:(来源于smth)
方案一:
\newcommand{\tabincell}{\begin{tabular}{@{}#1@{}}#2\end{tabular}}%放在导言区%

然后使用&\tabincell{c}{}&就可以在表格中自动换行
%比如这么用
\begin{tabular}{|c|c|}
\hline1 & the first line \\
\hline2 & \tabincell{c}{haha\\ heihei\\zeze} \\
\hline
\end{tabular}
注:好用,已试过,以下为一例子,可直接存为.tex文件编译运行
\documentclass{article}
\usepackage{CJK}
\begin{document}
\begin{CJK*}{GBK}{song}
\newcommand{\tabincell}{\begin{tabular}{@{}#1@{}}#2\end{tabular}}
%然后使用&\tabincell{c}{}&就可以在表格中自动换行
%比如这么用
\begin{tabular}{|c|c|}
\hline1 & the first line \\
\hline2 & \tabincell{c}{haha\\ heihei\\zeze \\fgf \\asgr} \\
\hline
\end{tabular}
\end{CJK*}
\end{document}


方案二:\usepackage{longtable}

唯世 发表于 2013-5-11 08:58

好棒!!!!!!!!!!

唯世 发表于 2013-5-11 08:59

果断收藏!!!!!!!!!

YHP494 发表于 2016-1-25 15:44

谢谢楼主的分享!!!
页: [1]
查看完整版本: Latex 表格单元格内自动换行(转载)