宏包 makecell 應用(四)

宏包 makecell 應用(四)

 

多行表頭與單元格

 

 

首先,要在導言區(Preamble)將以下兩個宏包包含進來。

 

\usepackage{multirow} 

\usepackage{makecell}

 

缺一不可。否則,會出現\multirowthead與\multirowcell中文字不豎向居中!

 

①\multirowhead命令

 

\multirowhead{<nrow>}[<vmove>][<hor alignment >]{<contents>}

 

②\multirowcell命令

 

\multirowcell{<nrow>}[<vmove>][<hor alignment >]{<contents>}

 

[對照:multirow宏包應用:

multirow宏包有命令:\multirow{<nrow>}[<njot>]{<width>}[<vmove>]{<contents>}

]

 

\multirowcell中省略了[<njot>]和{<width>}。表格中文字垂直位移的微調可以採用[<vmove>],而不用[<njot>],故省略了。\multirowcell使用{<contents>}中文字的自然寬度,相當於{<width>}=*。

 

\multirowcell中增加了[<hor alignment >]參數。表示水平對齊方式。

 

[對照:multirow宏包用命令參數\multirowsetup來改變文本在格子中被排版的方式。這個參數的默認定義就是\raggedright,即文本在格子中左對齊,因而命令 \renewcomand{\multirowsetup}{\centering}使文本在格子中居中排列。

]

 

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{CJK}

\usepackage{multirow}
\usepackage{makecell}

\begin{document}
\begin{CJK*}{GBK}{song}
\CJKtilde
\renewcommand\theadfont{\normalsize} %默認表頭文字大小是 \small

\setcellgapes{8pt}  %在表格所有單元中產生單元格上下 邊線之間的垂直間隙。
\makegapedcells  %使能 \setcellgapes [<t or b>]{<value>}。


\renewcommand\theadset{\def\arraystretch{.85}}%
\begin{tabular}{|l|c|c|}
\hline
\multirowthead{4}[0em]{First Column head}&\multicolumn{2}{c|}{\thead{Multicolumn head}}\\
\cline{2-3}
& \thead{Second \\multlined\\ column head} & \thead{Third\\column head}\\
\hline
Cell text & A &\multirowcell{3}{28--31}\\
\cline{1-2}
\makecell{Multilined\\Cell text} & B& \\
\hline
\makecell[l]{Left aligned \\ cell text} & C & \multirowcell{4}[1ex][l]{37--43}\\
\cline{1-2}
\makecell[r]{Right aligned \\ cell text} & D & \\
\hline
\makecell[b]{Bottom aligned \\ cell text} & E & \multirowcell{5}[1ex][r]{37--43\\52--58}\\
\cline{1-2}
\makecell[{{p{5cm}}}]{Cell long long long long text with predefined width} & F & \\
\cline{1-2}
\makecell[{{>{\parindent1em}p{5cm}}}]{Cell long long long long text with predefined width} & G & \\
\hline

\end{tabular}

\end{CJK*}
\end{document}

運行結果:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章