# Long table header vertical alignment

Consider the example, with two long headings to a table (one is longer):

\documentclass{article}
\usepackage{graphicx}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}
\begin{table}
\begin{tabular}{|C{2em}|C{2em}|}\hline
\rotatebox{90}{Long long heading 1~} & \rotatebox{90}{Long long longer longer heading 2~}\\ \hline %%%%%%%%%%% ~ is inserted at end of headings to keep the margin away
Text 1 & Text 2\\ \hline
\end{tabular}
\end{table}
\end{document}


Note that both the headings are centrally aligned in the y-axis. What I want is, the table headings are aligned at the bottom in the y-axis. In other words, the highlighted space would not be there.

• That is normal: your C column type is based on the m{} columntype. Use the $p{}$ column type with a \multicolumn for theses two headings. Jul 23, 2020 at 22:22

A solution as I suggested in a comment, and a simpler one, based on eqparbox:

  \documentclass{article}
\usepackage{graphicx}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\usepackage{eqparbox}

\begin{document}

\begin{table}
\centering
\begin{tabular}{|C{2em}|C{2em}|}\hline
\multicolumn{1}{|p{2em}}{\centering\rotatebox[origin = l]{90}{Long long heading 1}~} &\multicolumn{1}{|p{2em}|}{\centering \rotatebox[origin = l]{90}{Long long longer longer heading 2~}}\\ \hline %%%%%%%%%%% ~ is inserted at end of headings to keep the margin away
Text 1 & Text 2\\ \hline
\end{tabular}
\begin{tabular}{|C{2em}|C{2em}|}\hline
\rotatebox{90}{\eqmakebox[H][l]{Long long heading 1}~} & \rotatebox{90}{\eqmakebox[H][l]{Long long longer longer heading 2}~}\\ \hline %%%%%%%%%%% ~ is inserted at end of headings to keep the margin away
Text 1 & Text 2\\ \hline
\end{tabular}
\end{table}

\end{document}


Two cases with use of the rotating and makecell packages:

\documentclass[12pt]{article}
\usepackage{rotating}
\usepackage{makecell}

\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{|c|c|}
\hline
& \rothead{Long Long longer longer heading 2} \\
\hline
\makecell{Text\\ 1} & \makecell{Text\\ 2}   \\
\hline
\end{tabular}
\end{table}
or table design which I more prefer:
\begin{table}[ht]
\centering
\begin{tabular}{|c|c|}
\hline
& \rothead{Long Long longer longer heading 2} \\
\hline
\makecell{Text\\ 1} & \makecell{Text\\ 2}   \\
\hline
\end{tabular}
\end{table}
\end{document}


My proposal....

\documentclass[12pt]{article}
\usepackage{amsmath}

\usepackage{graphicx}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|c|c|}
\hline
\rotatebox{90}{Long Long heading~} & \rotatebox{90}{Long Long longer longer heading 2~} \\ \hline
\multicolumn{1}{|c|}{\begin{tabular}[c]{@{}c@{}}Text\\ 1\end{tabular}} & \begin{tabular}[c]{@{}c@{}}Text\\ 2\end{tabular} \\ \hline
\end{tabular}
\end{table}
\end{document}


• Thanks, but wanted to use C column-type for the actual body of the table,
– hola
Jul 23, 2020 at 22:37
• @xxx--- You're welcome :-)...However...do you want that remove my answer? There is not problem. Jul 23, 2020 at 22:44
• No issues, please keep the answer. Stay safe during corona virus!
– hola
Jul 23, 2020 at 23:18
• @xxx--- Thank you very much...and also for you "safe during COVID19. Best regards. Jul 24, 2020 at 11:50

In {NiceTabular} of nicematrix, you have a built-in command \rotate to do that. However, you have to rebuild c columns with multicolumn since you want to use your C type columns elsewhere.

\documentclass{article}
\usepackage{nicematrix}

\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\NiceMatrixOptions{cell-space-top-limit=2pt}

\begin{document}
\begin{table}
\begin{NiceTabular}{C{2em}C{2em}}[hvlines]
\multicolumn{1}{c}{\rotate Long long heading 1}
& \multicolumn{1}{c}{\rotate Long long longer longer heading 2}\\
Text 1 & Text 2\\
\end{NiceTabular}
\end{table}
\end{document}