# Vertical Centering in Tables

I'm trying to vertically center some text inside a table. From this (and other) answer(s), the following example should work...

\documentclass{article}
\usepackage{array}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}

\begin{document}

\begin{table}[ht]
\begin{tabular}{|M{4cm}|M{4cm}|N}
\hline
\textbf{Text} & \textbf{Text} &\\[50pt]
\hline
text & text&\\[50pt]
\hline
\end{tabular}
\end{table}

\end{document}


In the linked answer it produces the desired output. What's funnier is even on my other device, it produces the desired output. It's only on this one laptop that I'm getting this:

The only difference is that I'm using the portable version of MikTex on this device, but I can't work out what's going on. The fact that it works on another device but not on this one is really quite bothering...

• from time of writing of the answer on your link the package array was upgraded. changed are code for m column specifier ... consequently this solution doesn't work anymore on the way as you expected. test your mwe with the following replacement for the first row with for example with \textbf{Text} & \textbf{Text} & \rule{0pt}{50pt}\\  and observe difference. or put longer text in one cell and you will see, that text will be vertical centered. – Zarko Sep 3 '18 at 22:38
• Thanks, that's interesting - so I guess my other computer is also using an outdated version of the package? Do you know if the replacement would work with the older version of the package? I sync files between the two devices and versioning might become an issue :( – Platehead Sep 3 '18 at 23:00
• it should. you need to load array as \usepackage{array}[=2016-10-06] (not tested). – Zarko Sep 3 '18 at 23:46

## 1 Answer

Slightly modifying the definition of the N column type with the help of makecell yields more or less what you want, I think:

\documentclass{article}
\usepackage{array, makecell}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}>{\Gape [30pt] [30pt]{}}m{0pt}@{}}

\begin{document}

\begin{table}[ht]
\begin{tabular}{|M{4cm}|M{4cm}|N}
\hline
\textbf{Text} &\textbf{Text} & \\
\hline
text & text & \\
\hline
\end{tabular}
\end{table}

\end{document}


• Thanks for that. Would there be a way to keep each row height of the table customisable? It seems like this would enforce the same height across the entire table – Platehead Sep 3 '18 at 23:17
• In this table, the \Gape{30pt}{30pt} command adds 30 pt at the top and the bottom of an empty cell. You can change the values for top and bottom (independently). – Bernard Sep 3 '18 at 23:27