I'm trying to find a method which allows me to have columns with automatic width which are also centered in horizontal and vertical direction, just like tabularx
's X
columntype just centered.
So here is was I tried so far:
\documentclass{article}
\usepackage{tabularx,booktabs}
\newcolumntype{Z}[0]{>{\centering\arraybackslash\let\newline\\\hspace{0pt}}X}%
\begin{document}
\begin{table}
\begin{tabularx}{7cm}{l|X|X}
& long\newline heading 1 & short heading\\
\toprule
row 1 & 2314 & 2134
\end{tabularx}
\end{table}
\begin{table}
\begin{tabularx}{7cm}{l|Z|Z}
& long\linebreak heading 1 & short heading\\
\toprule
row 1 & 2314 & 2134
\end{tabularx}
\end{table}
\end{document}
The second is already almost what I want, just the vertical centering of the third column is missing. How to fix this?
Best Answer
for vertical centering you want an
m
column rather than ap
column to sit behindX