# Create a table with three columns above two columns

I'm making a document header (full width of page) for which I would like three columns on the first row and two in the second. The tricky part (I think) is that I would like the bottom two cells to take up half the width of the table each (i.e. not a split of 2 then 1 cells as I've got in the example.) I've got something close to what I want, but the extra padding is being added on the left of the cell contents, I would like it on the right. Then also have the bottom row as described.

\documentclass[a4paper,10pt]{article}
\begin{document}

\begin{center}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}|l|l|l|}
\hline
Date: 16/12/11&Ref:  Title&Rev: No.\\
\hline
\multicolumn{2}{|l|}{Author: Author Name} & \multicolumn{1}{l|}{Client:
Company Name}\\
\hline
\end{tabular*}
\end{center}

\end{document}

-
 Do you want this to be a header for every page, or just a one-time item? – Mico Dec 16 '11 at 12:11 Just a one off. I've got a couple of separate images that form the actual header for the document, but this goes at the top of the first page. – beacon_bonanza Dec 16 '11 at 12:17

You can use two tabular-like environments; in the first example below I kept the vertical rules; in the second one I removed them and used the features provided by the booktabs package:

\documentclass[a4paper,10pt]{article}
\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}

\noindent\begin{tabularx}{\textwidth}{|X|X|X|}  \hline
Date: 16/12/11 & Ref:  Title & Rev: No.\\
\end{tabularx}\offinterlineskip

\noindent\begin{tabularx}{\textwidth}{|X|X|}  \hline
Author: Author Name & Client:  Company Name\\ \hline
\end{tabularx}

\vspace{1cm}

\noindent\begin{tabularx}{\textwidth}{@{}XXX@{}}  \toprule
Date: 16/12/11 & Ref:  Title & Rev: No.\\
\end{tabularx}\offinterlineskip

\noindent\begin{tabularx}{\textwidth}{@{}XX@{}}  \midrule
Author: Author Name & Client:  Company Name\\ \bottomrule
\end{tabularx}

\end{document}


-
 Excellent, that makes the use of the tabularx environment nice and clear. Thanks. – beacon_bonanza Dec 16 '11 at 13:09 +1 Could you use tabular* instead of tabularx? – cmhughes Dec 16 '11 at 17:33 @cmhughes: yes, but it is longer; the first tabular* would be something like \noindent\begin{tabular*}{\textwidth}{|p{\dimexpr.33\textwidth-2\tabcolsep+0.53‌​pt\relax}|p{\dimexpr.33\textwidth-2\tabcolsep+0.53pt\relax}|p{\dimexpr.33\textwid‌​th-2\tabcolsep+0.53pt\relax}|} \hline Date: 16/12/11 & Ref: Title & Rev: No.\\ \end{tabular*}\offinterlineskip – Gonzalo Medina Dec 16 '11 at 23:30
\documentclass[a4paper,10pt]{article}
\usepackage{tabularx}
\def\MC#1{\multicolumn{3}{@{}c@{}}{%
\tabular{|p{\dimexpr 0.5\textwidth-2\tabcolsep} |
p{\dimexpr 0.5\textwidth-2\tabcolsep} |}
#1\endtabular}}
\begin{document}

\begin{center}
\begin{tabularx}{\textwidth}{|X|X|X|}  \hline
Date: 16/12/11 & Ref:  Title & Rev: No.\\  \hline
\MC{Author: Author Name & Client:  Company Name}\\ \hline
\end{tabularx}
\end{center}

\end{document}

-
 That's great, thanks very much. Do you know why the borders don't quite meet up on the right hand side (at least when I process it)? – beacon_bonanza Dec 16 '11 at 12:11 I adjusted the -2's slightly (to 2.2 and 2.01 respectively) and was able to line up the borders properly. A bit of a hack, but it does the job. Thanks again. – beacon_bonanza Dec 16 '11 at 13:03

You note

but the extra padding is being added on the left of the cell contents, I would like it on the right.

I interpret this requirement as stating that the contents of the cells should be left-aligned. Here's an MWE that satisfies this requirement. Note that I've eliminated the vertical lines because I think the information looks less "boxy" without them. For the sake of the example, I've also place the date, ref, etc information in italics mode, but how exactly you want to typeset that is clearly up to you.

The MWE also uses the commands \toprule, \midrule, and \bottomrule of the booktabs package to get (IMHO) better vertical spacing than is possible with the \hline command. Note that the middle horizontal line, produced with the command \midrule, is slightly lighter than the top and bottom lines. If you want all three lines to have the same (heavy) weight, you can simply replace \midrule with \midrule[\heavyrulewidth].

\documentclass[a4paper,10pt]{article}
\usepackage{tabularx,booktabs}
\begin{tabularx}{\textwidth}{@{}XXX@{}}
\toprule
Date: \emph{12/16/2011}  &Ref:  \emph{Title}& Rev.~No. \emph{1234}\\
\midrule
\end{tabularx}
\begin{tabularx}{\textwidth}{@{}XX@{}}
Author: \emph{Author Name} & Client:  \emph{Company Name}\\
\bottomrule
\end{tabularx}}

\begin{document}
\end{document}


-
 Thanks for your answer, I'd agree that the table probably looks better with the booktabs style, but I was trying to replicate a table from a word document as closely as possible... – beacon_bonanza Dec 16 '11 at 13:05

If it turns out to be important that you keep everything within a single table, you could also use a 6-column table like this:

\begin{tabular}{llllll} \hline
\multicolumn{2}{|l|}{Date: 16/12/11} & \multicolumn{2}{l|}{Ref: Title} & \multicolumn{2}{l|}{Rev: No.} \\ \hline
\multicolumn{3}{|l|}{Author: Author Name} & \multicolumn{3}{l|}{Client: Company Name} \\
\hline
\end{tabular}
`
-