1

I am having an issue where the tablehead and tablefirsthead cells are extending past the text width. As you can see by my example, I use \textwidth and a decimal number to specify that I want each column to be a percentage of the textwidth. This strategy works for the body cells but not for the header cells. Why is this so? How can I fix this?

\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}

enter image description here

  • 3
    Any column is padded on either side by \tabcolsep space on either side. And there are also three rules, each \arrayrulewidth wide. So you have an excess of 8\tabcolsep+3\arrayrulewidth on each row. – egreg Jan 22 '18 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.