我遇到了一个问题,tablehead 和 tablefirsthead 单元格超出了文本宽度。正如您在我的示例中所看到的,我使用 \textwidth 和一个小数来指定我希望每列占文本宽度的百分比。此策略适用于正文单元格,但不适用于标题单元格。为什么会这样?我该如何解决这个问题?
\documentclass{book}
\usepackage[margin=1.0in]{geometry}
\usepackage{supertabular}
\usepackage[table]{xcolor}
\usepackage{makecell}
\pagestyle{plain}
\setlength\extrarowheight{2pt}
\newcommand{\TableCell}[1]{
\makecell*[{{p{\linewidth}}}]{
\begin{flushleft}
#1
\end{flushleft}
}
}
\newcommand{\thickline}{
\Xhline{4\arrayrulewidth}
}
\begin{document}
\tablehead{
\multicolumn{1}{>{\centering}m{0.4\textwidth}|}{\cellcolor{gray!25}{Header 1}} &
\multicolumn{1}{|>{\centering}m{0.2\textwidth}|}{\cellcolor{gray!25}{Header \\ 2}} &
\multicolumn{1}{|>{\centering}m{0.2\textwidth}}{\cellcolor{gray!25}{Header \\ 3}} &
\multicolumn{1}{|>{\centering}m{0.2\textwidth}}{\cellcolor{gray!25}{Header \\ 4}}\\\hline
}
\tablefirsthead{
\multicolumn{1}{>{\centering}m{0.4\textwidth}|}{\cellcolor{gray!25}{Header 1}} &
\multicolumn{1}{|>{\centering}m{0.2\textwidth}|}{\cellcolor{gray!25}{Header \\ 2}} &
\multicolumn{1}{|>{\centering}m{0.2\textwidth}}{\cellcolor{gray!25}{Header \\ 3}} &
\multicolumn{1}{|>{\centering}m{0.2\textwidth}}{\cellcolor{gray!25}{Header \\ 4}}\\\hline
}
\tabletail{\thickline}
\tablelasttail{\thickline}
\begin{supertabular*}{\textwidth}{m{0.4\textwidth}|m{0.2\textwidth}|m{0.2\textwidth}|m{0.2\textwidth}}
\TableCell{Content 1} &
\TableCell{Content 2} &
\TableCell{Content 3} &
\TableCell{Content 4} \\
\end{supertabular*}
\end{document}