数学建模社区-数学中国
标题:
Latex 表格单元格内自动换行(转载)
[打印本页]
作者:
madio
时间:
2013-2-20 07:05
标题:
Latex 表格单元格内自动换行(转载)
Latex 表格单元格内换行
c$ R( l: u+ m) \
问题:如何同时让表格同一行一个单元格的文字能垂直居中?比如说文字超长超出页面范围需要分行显示
/ M7 s. ? R$ p$ F
答:(来源于smth)
0 L) {: Z4 O T. V! J/ t/ {
方案一:
5 }) S9 S+ `% j2 t
\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}%放在导言区%
+ O. R# O& [' L( q2 R
0 X* ~8 O1 t, f+ f6 S- A
然后使用&\tabincell{c}{}&就可以在表格中自动换行
3 n9 {( ?) A* j3 F$ ~+ {- F
%比如这么用
0 }% ~2 D% }1 x% f( P- D
\begin{tabular}{|c|c|}
8 q7 B# `) t, I$ `: c" J7 b
\hline1 & the first line \\
. w6 q* b9 S8 t6 }9 ?
\hline2 & \tabincell{c}{haha\\ heihei\\zeze} \\
; H4 @4 I$ d' t1 ~, U' i, Q8 ]
\hline
# q* I3 b7 h4 G
\end{tabular}
8 h) C$ @# b8 Z) R9 D3 s9 l& S/ l
注:好用,已试过,以下为一例子,可直接存为.tex文件编译运行
0 _, i }: \- J
\documentclass[a4paper,12pt]{article}
: a9 t; \7 I2 z' R1 v3 P7 d
\usepackage{CJK}
- g3 z/ F9 z0 W
\begin{document}
3 w% b; D" J. h1 K- W) w# v9 A
\begin{CJK*}{GBK}{song}
& M4 a1 U( N) I; ?( t$ h; k
\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}
9 ]; P2 X5 p! k+ x' ^' e1 q
%然后使用&\tabincell{c}{}&就可以在表格中自动换行
9 V( D8 _1 ?- G0 W/ a0 x
%比如这么用
; t3 t9 L; W& C, M I' g
\begin{tabular}{|c|c|}
5 S& T: b2 E5 d' }( k
\hline1 & the first line \\
, U. [$ E3 Q: c+ _( j5 g# ^: N
\hline2 & \tabincell{c}{haha\\ heihei\\zeze \\fgf \\asgr} \\
/ t3 Y3 G" j0 n. x- x
\hline
1 o2 b0 f4 W. B7 D
\end{tabular}
$ Z+ Q4 j4 K7 g. i' j7 N5 i& r1 c
\end{CJK*}
/ {- F' r u/ H8 k. y
\end{document}
, n) f. G. m+ W
+ E3 J+ c' w! K: `
! P' F3 @( R) r) v
方案二:\usepackage{longtable}
作者:
唯世
时间:
2013-5-11 08:58
好棒!!!!!!!!!!
作者:
唯世
时间:
2013-5-11 08:59
果断收藏!!!!!!!!!
作者:
YHP494
时间:
2016-1-25 15:44
谢谢楼主的分享!!!
8 i* a3 V7 z q5 S8 c' k
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5