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?

  • 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
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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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