代码如下所示。当第一行不包含特殊单元格(一个单元格中有两行)时,这种情况实际上不会发生。但我不太清楚如何修复它。
\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}
导致