3

Consider the solution https://tex.stackexchange.com/a/12762/4011 to the problem of fixing the height of a cell in tabular. This essentially adds some space above the cell content, so it is not warranted that it is always vertically centered. Just changing p-cell to m-cell doesn't solve this. So how can I modify this to ensure a vertical centering of the every cell content?

\documentclass[a4paper]{article}
\usepackage{array}  

\begin{document} 

\newcolumntype{C}[1]{%
 >{\vbox to 5ex\bgroup\vfill\centering}%
 p{#1}%
 <{\egroup}}  

\begin{tabular}{|c | C{3cm} | C{5cm} |} 
 \hline 
 Short Text & Short Text & Short Text \tabularnewline \hline
Short Text  & Short Text & Loooooooooo  oooooooooooong Text \tabularnewline \hline  
Short Text  & Short Text & Loooooooooooooooooooooong Text \tabularnewline \hline 
\end{tabular}    
\end{document}
1
+50

You can just add a \vfill before the \egroup, but then you will notice the result is too high, by about \baselineskip, so you should backup by this amount too:

Sample output

\documentclass[a4paper]{article}
\usepackage{array}  

\begin{document} 

\showoutput

\newcolumntype{C}[1]{%
 >{\vbox to 5ex\bgroup\vfill\centering\arraybackslash}%
 p{#1}%
 <{\vskip-\baselineskip\vfill\egroup}}  

 \begin{tabular}{|c | C{3cm} | C{5cm} |}
   \hline 
   Short Text & Short Text & Short Text \\ \hline
   Short Text  & Short Text & Loooooooooo  oooooooooooong Text \\ \hline  
   Short Text  & Short Text & Loooooooooooooooooooooong Text \\ \hline
   Short Text  & Several pieces of text to fill up this box & Not much
   \\ \hline   
 \end{tabular}    
\end{document}

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.