数学建模社区-数学中国

标题: Latex 表格单元格内自动换行(转载) [打印本页]

作者: madio    时间: 2013-2-20 07:05
标题: Latex 表格单元格内自动换行(转载)
Latex 表格单元格内换行/ @& q9 b* B+ L  y9 Q# z
问题:如何同时让表格同一行一个单元格的文字能垂直居中?比如说文字超长超出页面范围需要分行显示
  Q) y7 v  J) B# d( o答:(来源于smth)
9 k! K  s8 e+ I) W: {% \方案一:9 t2 \6 s) {4 f9 U: S
\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}%放在导言区%+ j2 x' G2 j; s' i
4 i' z: i7 @% v  k% ^2 t0 ]4 \
然后使用&\tabincell{c}{}&就可以在表格中自动换行
8 c9 F$ S4 x0 g. y! w4 d! G+ u%比如这么用% g2 ]4 n2 O3 Q: y. w5 G; t
\begin{tabular}{|c|c|}: O7 a1 a. J9 R$ ^
\hline1 & the first line \\
$ {0 g) w8 d6 B3 E\hline2 & \tabincell{c}{haha\\ heihei\\zeze} \\
( }* r" N# r8 _/ R" K\hline
2 n: X3 i0 l; x# U% ]3 ?3 B* p: H\end{tabular}
8 N, F/ r/ K( E1 E* ^8 [注:好用,已试过,以下为一例子,可直接存为.tex文件编译运行
3 ^- ~' i2 R) f& z+ C\documentclass[a4paper,12pt]{article}
  @% ^: P1 b9 z2 `* q: n  }\usepackage{CJK}2 K- N5 o- I4 Z3 T5 c$ I( C
\begin{document}4 j$ v# d" z& l/ ?: {5 T# L
\begin{CJK*}{GBK}{song}
4 Q! F( t+ H3 d% j* `6 Z& d\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}
/ i! [* |* k( J) N% f" f' \& ]: p5 n%然后使用&\tabincell{c}{}&就可以在表格中自动换行
, p1 a+ X, w/ q1 p. Q  C$ r% {%比如这么用# Y8 A+ R* O8 Y- c; f1 a5 n/ J
\begin{tabular}{|c|c|}
, \. [& r6 [- G: v) U' Y3 Q' A. A\hline1 & the first line \\
! H5 o2 H$ N: H+ {& B8 P\hline2 & \tabincell{c}{haha\\ heihei\\zeze \\fgf \\asgr} \\
- y, b, T( F+ z: ~* G" Z& x\hline
5 j3 A8 y2 l6 q! J, u. [- t9 ~\end{tabular}2 K* o5 d! D! V$ ?# u( p
\end{CJK*}, B1 l; M- Z# n
\end{document}
" J' H" y) D& X3 {
. a2 C2 Y. ?. p% m# u: h. @
4 w! \; e$ I- o: y5 o方案二:\usepackage{longtable}
作者: 唯世    时间: 2013-5-11 08:58
好棒!!!!!!!!!!
作者: 唯世    时间: 2013-5-11 08:59
果断收藏!!!!!!!!!
作者: YHP494    时间: 2016-1-25 15:44
谢谢楼主的分享!!!# ~! L% J1 m: B+ K





欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5