# Vertical align center and horizontal align left in tabular

I found this small piece of code on here, which creates a new column type. However, when I apply it to my tabular, only the left column is vertically aligned. The right has not been affected at all.

\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash} m{#1} }


Below, I setup my table and I use this new column type L. However, as you can probably see, only the first column is affected.

\begin{center}
\noindent\begin{tabular}{ | L{\dimexpr 0.4\linewidth-2\tabcolsep} | L{\dimexpr 0.4\linewidth-2\tabcolsep} | }
\hline

TEXT
&
MORE TEXT \\[3ex]
\hline

TEXT
&
MORE TEXT \\[3ex]
\hline

\end{tabular}
\end{center}\break


How do I make both columns be affected?

The explicit spacing in \\[3ex] affects vertical alignment. Use \renewcommand\arraystretch instead.

\documentclass{article}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash} m{#1} }
\begin{document}
\renewcommand\arraystretch{1.3}
\begin{tabular}{ | L{\dimexpr 0.4\linewidth-2\tabcolsep} | L{\dimexpr 0.4\linewidth-2\tabcolsep} | }
\hline
TEXT TEXT TEXT TEXT TEXT
TEXT TEXT TEXT TEXT TEXT
TEXT TEXT TEXT TEXT TEXT
TEXT TEXT TEXT TEXT TEXT
&
MORE TEXT \\
\hline
TEXT
&
MORE TEXT MORE TEXT MORE TEXT
MORE TEXT MORE TEXT MORE TEXT
MORE TEXT MORE TEXT MORE TEXT
MORE TEXT MORE TEXT MORE TEXT \\
\hline
\end{tabular}
\end{document}


• What if I don't want that specific height on all my rows? – MortenMoulder Nov 15 '16 at 14:28
• @MortenMoulder Then post another question ;-) Seriously: The solution depends on why you want to have extra space in particular rows. One can add struts (=rules of zero width but with an appropriate depth or height) at the beginning or end of a table entry to increase the offset above or below. – gernot Nov 15 '16 at 14:46
• Why should I post another question, when my post makes perfectly sense? You can see that I have an 2ex header and the rest are 3ex. If I wanted all to be 3ex, I wouldn't have specified all of them individually? – MortenMoulder Nov 15 '16 at 14:49
• I went with your solution anyway. Thanks for the piece of code. As you can see in your screenshot, the text is sliiiightly aligned wrong vertically. The "MORE TEXT" in the top right is slightly above the center of that column. – MortenMoulder Nov 16 '16 at 9:34
• @MortenMoulder Set \arraystretch to a bigger value, say 3 or 4. Then you will see that the asymmetries grow. The text is still centered, if you subtract the white space around the lines. See also the comment by Piet van Oostrum. Centering vertically does not really mean centering between the lines. Therefore it is relevant what your intentions really are. If you just don't like the spacing around the lines: you are right, this is less than optimal with standard tabulars, therefore there are packages like booktabs. – gernot Nov 16 '16 at 17:43

I think there is a misunderstanding about what the m{} column specifier means. It is not vertically center the text in the cell. Rather it is that the baseline of the text is in the vertical center of the text. And then all the baselines of the cells in the same row are aligned. It appears that the \\[3ex] vertical space is added below the text in the last column. So the baseline there is in the vertical center of that space which is the whole cell. And that keeps the text on the top. And even when you use a p{} for the first column, then the first cell will still be vertically centered, as its baseline (the bottom of the text in this case) will be aligned with the baseline of the second cell.

Try this experiment: Add an L{1mm} column to the right and keep it empty. Now the first two columns are both vertically centered, even when you change them to p{} columns.

\noindent\begin{tabular}{ | p{2cm} | p{3cm} | L{1pt}}
\hline
TEXT
&
MORE TEXT & \\[3ex]
\hline
TEXT
&
MORE TEXT & \\[3ex]
\hline
\end{tabular}

• Now I have an empty column with no right border. – MortenMoulder Nov 15 '16 at 14:47
• Yes, it was only an experiment to show how things work. – Pieter van Oostrum Nov 15 '16 at 14:56
• Ah, right okay. – MortenMoulder Nov 15 '16 at 15:00
• But if you change the extra column specifier to  @{}L{0pt}@{} it becomes invisible, but you must add the & at the end of each row. – Pieter van Oostrum Nov 15 '16 at 16:34