Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
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
add comment

4 Answers 4

up vote 11 down vote accepted

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}

enter image description here

share|improve this answer
    
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
add comment
\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}
share|improve this answer
    
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
add comment

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}
\newcommand{\headerlines}{%
   \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}
\noindent\headerlines
\end{document}

enter image description here

share|improve this answer
    
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
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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