1

I'm trying to put a table in the header of a document. In this document, width of the header is larger than the text body. The header needs to be exactly 183 mm wide and, in it, there is a table 183 mm wide with the width of the columns of 70, 93 and 20 mm. So I set the document as this

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyheadoffset[L]{0.9cm} %header offset
\fancyheadoffset[R]{0.9cm} %header offset

whith those settings (and other that I've omitted) the width of the header is 183 mm (correct!)

Then I try to put the table in the header

\fancyhead[C]{
\begin{tabular}{|p{70mm}|p{93mm}|p{20mm}|}
\hline
first & second & third\\
\hline
\end{tabular}
}

This results in a table whose cells are wider than the value that I've used (something like 4 mm wider) and I have an overfull warning. For example, only to be clear, the first column is 74 mm wide rather than 70. I think that the difference is due to the fact that with p{70mm} I set the text width and not the column width and this give me a small offset on both margins (in fact there is a little space between the column line and the first letter).

Is there a way to set the column width as the distance between the two lines? Otherwise, I need to decrease the width of the columns of a few millimeters resulting in a less precise work.

Thanks!

  • How wide is the textblock? What's the significance of the 0.9cm header offsets? – Mico Nov 26 '16 at 19:10
2

You need to subtract 2\tabcolsep from each column like this:

\begin{tabular}{|p{\dimexpr70mm-2\tabcolsep}|p{\dimexpr93mm-2\tabcolsep}|p{\dimexpr20mm-2\tabcolsep}|}
\hline
first & second & third\\
\hline
\end{tabular}

But this method will leave some space before and after the first and last columns, respectively. If you want to remove that space use this column specification:

{|@{}p{\dimexpr70mm-\tabcolsep}|p{\dimexpr93mm-2\tabcolsep}|p{\dimexpr20mm-\tabcolsep}@{}|}
  • Note that the tabular env. has 4 vertical rules. If the array package is loaded -- which is quite often the case automatically, esp if packages such as tabularx are loaded -- one also needs to subtract 1.333\arrayrulewidth (default value of \arrayrulewidth: 0.4pt) as well. Separately, I don't think the second solution (the one without padding at the outer edges, "works" if there's a vertical rule at the left-hand edge. – Mico Nov 26 '16 at 18:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.