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 use \rotatebox to create a table with vertical headers, like so:

\documentclass{article}

\usepackage{rotating}

\begin{document} 

\begin{table}
\begin{tabular}{|l|l|l|}
\hline
\rotatebox{90}{Header 1} &
\rotatebox{90}{Header 2} &
\rotatebox{90}{Header 3}\\
\hline
Content & Content & Content\\
\hline
\end{tabular}
\end{table}

\end{document}

Now, I have a header that is awkwardly long (and cannot be abbreviated in a meaningful way). I would like to break the header into two lines. However, I can't seem to get this to work with \linebreak or \\, so apparently some trickery is needed.

Help?

share|improve this question
    
Rotating the column headers isn't a great solution. Is spreading them out over two or more lines an acceptable solution? –  Marc van Dongen Jan 8 '12 at 21:12
    
@MarcvanDongen: I'm working on a book translation, with the original in a rather cramped layout (which I still want to conserve). The actual table has 27 columns. Rotated headers is about the only way to get this done, and the way the original book did it, too. Unfortunately, the German headers are quite a bit longer than the English ones, and with 77 rows I'm running out of vertical space. Hence, it's a line break in the vertical header, or spreading this sea of numbers over multiple pages, which wouldn't help the document any... –  DevSolar Jan 8 '12 at 21:17
    
Would you mind giving an example of one such table? –  Marc van Dongen Jan 8 '12 at 21:21
    
Have you thought of rotating the table? That would give you some extra space. –  Marc van Dongen Jan 8 '12 at 21:25
    
Duplicate: Wrapping table column headings in -turn- environment? (in terms of the answer). –  Werner Jan 8 '12 at 21:27
show 5 more comments

3 Answers

up vote 4 down vote accepted

How about putting the "problematic" header into a \parbox and manually adding \\ (which works inside the box) where necessary?

\documentclass{article}

\usepackage{rotating}

\begin{document} 

\begin{table}
\begin{tabular}{|l|l|l|}
\hline
\rotatebox{90}{Header 1} &
\rotatebox{90}{Header 2} &
\rotatebox{90}{\parbox{4cm}{An awkwardly long \\header that cannot be \\abbreviated in a \\meaningful way}}\\
\hline
Content & Content & Content\\
\hline
\end{tabular}
\end{table}

\end{document}

enter image description here

share|improve this answer
    
Excellent, that did it. –  DevSolar Jan 8 '12 at 21:33
add comment

You can use \adjustbox{minipage=<width>,rotate=<angle>}{some text\\with line break} from the adjustbox package to create rotated box with the given width which can have manual and automatic line breaks.

share|improve this answer
add comment

You can wrap the long header in a \parbox:

enter image description here

\documentclass{article}

\usepackage{rotating}

\begin{document} 

\begin{table}
\begin{tabular}{|l|l|l|}
\hline
\rotatebox{90}{Header 1} &
\rotatebox{90}{Header 2} &
\rotatebox{90}{\parbox{1.5cm}{Long Header Over Several Lines}}\\
\hline
Content & Content & Content\\
\hline
\end{tabular}
\end{table}

\end{document}
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.