程式碼如下所示。當第一行不包含特殊儲存格(儲存格中有兩行)時,實際上不會發生這種情況。但我不太確定如何解決它。
\documentclass[12pt]{article}
\usepackage{amsmath}
\renewcommand*{\arraystretch}{1.3}
\usepackage{graphicx}
\usepackage{xspace}
\usepackage{tabu} % tabular
\usepackage{multirow} % tables
\usepackage{setspace}
\onehalfspacing % or \doublespacing
\newcommand{\specialcell}[2][c]{\begin{tabu}[#1]{@{}c@{}}#2\end{tabu}} % two lines in a table cell
\tabulinesep=1.8mm % tabu vertical spacing/need {tabu} package
\begin{document}
\begin{table}[htbp]
\begin{tabu}{cccccc}
\hline
& \specialcell{aaa\\bbb} & \specialcell{aaa\\bbb} & \specialcell{aaa\\bbb} & \specialcell{aaa\\bbb} & \specialcell{aaa\\bbb}\\
\hline
a & a & a & a & a & a\\
\hline
b & b & b & b & b & b\\
\hline
c & c & c & c & c & c\\
\hline
\end{tabu}
\end{table}
\end{document}
答案1
這裡我只是重新定義\specialcell
為使用堆疊,而不是tabu
.
\documentclass[12pt]{article}
\usepackage{amsmath}
\renewcommand*{\arraystretch}{1.3}
\usepackage{graphicx}
\usepackage{xspace}
\usepackage{tabu} % tabular
\usepackage{multirow} % tables
\usepackage{setspace}
\onehalfspacing % or \doublespacing
%\newcommand{\specialcell}[2][c]{\begin{tabu}[#1]{@{}c@{}}#2\end{tabu}} % two lines in a table cell
\tabulinesep=1.8mm % tabu vertical spacing/need {tabu} package
\usepackage[usestackEOL]{stackengine}
\newcommand\specialcell[2][c]{\Centerstack[#1]{#2}}
\begin{document}
\begin{table}[htbp]
\begin{tabu}{cccccc}
\hline
& \specialcell{aaa\\bbb} & \specialcell{aaa\\bbb} & \specialcell{aaa\\bbb} & \specialcell{aaa\\bbb} & \specialcell{aaa\\bbb}\\
\hline
a & a & a & a & a & a\\
\hline
b & b & b & b & b & b\\
\hline
c & c & c & c & c & c\\
\hline
\end{tabu}
\end{table}
\end{document}
堆疊的基線跳過可以更改,例如,聲明
\setstackgap{L}{22pt}
導致