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 am trying to get a table cell with vertical text alignment.

My current code is:

\begin{tabularx}{\linewidth}{|X|}
\hline
\cellcolor{gray!20}Hardware\\
\hline
\end{tabularx}

Is there an easy solution to center the text vertically?

share|improve this question
    
I don't understand what do you mean with "center the text vertically", since it is a single line in a narrow row... Did you mean horizontally? –  JLDiaz Mar 22 '13 at 11:19
    
@JLDiaz With my code, the text in the row was not vertically centered. It was a lot closer to the upper line then to the lower one. –  Michael K Mar 22 '13 at 11:42
add comment

1 Answer

up vote 6 down vote accepted

Using a tabu environment instead of tabularx the solution is as follows:

\begin{tabu} to \linewidth{|X[1,m,j]|} % m = vertical alignment, j = justified (horizontal alingmnet
\hline
\cellcolor{gray!20}Hardware\\
\hline
\end{tabu}

if you want additional vertical space you can specify \tabulinesep=^Xmm_Ymm at the beginning of the document

share|improve this answer
    
This is exactly what I was looking for. Thank you. –  Michael K Mar 22 '13 at 11:36
    
@MichaelK you're welcome :) –  Federico Mar 22 '13 at 12:04
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.