2

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?

2
  • 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
    Commented Mar 22, 2013 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
    Commented Mar 22, 2013 at 11:42

1 Answer 1

6

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

2
  • This is exactly what I was looking for. Thank you.
    – Michael K
    Commented Mar 22, 2013 at 11:36
  • @MichaelK you're welcome :)
    – Federico
    Commented Mar 22, 2013 at 12:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .