![为什么我的标题单元格超出了线宽?](https://linux22.com/image/369078/%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E7%9A%84%E6%A0%87%E9%A2%98%E5%8D%95%E5%85%83%E6%A0%BC%E8%B6%85%E5%87%BA%E4%BA%86%E7%BA%BF%E5%AE%BD%EF%BC%9F.png)
我遇到了一个问题,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}