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.

Another question led me to use tabu for the purpose of fitting one column to its content while allowing the others to stretch equally. This is my current code:

\documentclass{article}
\usepackage{tabu} 

\begin{document}
\noindent
\begin{tabu}{|X[m,c]|c|X[m,c]|}
    Left content centered \newline between margin and title &
    {\Huge Title} &
    Right content \newline also centered
\end{tabu}

\end{document}

However this produces two problems: some weird horizontal alignment on the two-line cells, and the title is not vertically centered with the left and right cell.

What is causing these issues and how can I fix them?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

tabu also allows the use of negative coefficients to use on X columns so that one can have all the features of the X columns without the scaling part. This therefore eliminates the need to the raisebox "hack". All you need is change your c column to X[-1,m,c]

\documentclass{article}
\usepackage{tabu} 

\begin{document}
\noindent
\begin{tabu}{|X[m,c]|X[-1,m,c]|X[m,c]|}
    Left content centered \linebreak between margin and title &
    \Huge Title &
    Right content \linebreak also centered
\end{tabu}

\end{document}

enter image description here

share|improve this answer
1  
Ah OK +1 I can't complain that you stole the green tick from me:-) –  David Carlisle Oct 3 '12 at 10:38

Seems like you need \linebreak not \newline. The X columns are vertically centred on the baseline of the the c column not the middle of the text so you need to move the text or make other adjustments.

enter image description here

\documentclass{article}
\usepackage{tabu} 

\begin{document}
\noindent
\begin{tabu}{|X[m,c]|c|X[m,c]|}
    Left content centered \linebreak between margin and title &
    \raisebox{-.3\height}{\Huge Title} &
    Right content \linebreak also centered
\end{tabu}

\end{document}
share|improve this answer
    
\linebreak works. But I'm not sure what you mean about the centering — if I make the table even taller, it doesn't seem that the alignment of the X column has to do with the baseline of the c column but perhaps the center of it — see here: cl.ly/image/3W2O2m2V2R25 –  jtbandes Oct 2 '12 at 21:42
    
Your image shows the same thing, the baselines of the three columns are all at the same vertical position, the two X columns have a baseline in the center of the cell and the c one has a baseline at the baseline of the text it is (exactly) like going $\vcenter{lots of stuff}\hbox{Title}\vcenter{lots more stuff}$ –  David Carlisle Oct 2 '12 at 21:56
    
Ah, I understand. So is there a way to dynamically determine the center of the c column and set its baseline there instead of the baseline of the text? I know you used -.3\height but can this be done automatically based on the contents of the cell? –  jtbandes Oct 2 '12 at 21:58
    
It's pretty independent of the contents (given that you have teh \huge as it is some rough measure (by eye) of the relative heights of the normal and huge font. It's a bit late to think about ot but probably you could do a calcualtion taking into acountthe height and depth of the text (which are available as \height and \depth in the \raisebox argument and the height and \depth of the strut used for the table row (which depends on \arraystretch and \extrarowheight and things –  David Carlisle Oct 2 '12 at 22:10
    
but to be honest I wouldn't bother: you could work out an exact adjustment based on the exact bounding box of the texts and it would still look wrong due to letter shapes and things go with something simple like .3\height and tune after a few examples:-) –  David Carlisle Oct 2 '12 at 22:10

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.