I'm trying to create a longtable
which spans the entire \textwidth
. Additionally, although the contents of the table use different alignments, all of the header cells should be centered. Based upon e.g. this question, I have come up with the following code:
\documentclass[letterpaper,12pt]{report}
\usepackage[margin=1in]{geometry}
\usepackage{longtable}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\begin{document}
\noindent
\begin{longtable}{@{\extracolsep{\fill}} | l | c | c | r | r | }
\hline
\multicolumn{1}{|c|}{\textbf{Header 1}} &
\multicolumn{1}{c|}{\textbf{Header 2}} &
\multicolumn{1}{c|}{\textbf{Header 3}} &
\multicolumn{1}{c|}{\textbf{Header 4}} &
\multicolumn{1}{c|}{\textbf{Header 5}} \\
\hline
\endhead
\end{longtable}
\end{document}
When rendered with pdflatex
, however, the first column is correctly centered, but the remaining columns seem to be right-aligned instead. I believe that the problem is that I'm misunderstanding how @{\extracolsep{\fill}}
works in the longtable
definition.
What am I doing wrong?
\noindent
before longtable (or any display environment) it won't affect the indentation, just add a blank line of spurious space. `\extracolsep and vertical lines don't really work together in normal tabular either so it's not all my fault they don't really work in lingtable:-)