# How to align rotated table cells

I need help with aligning rotated cell text. The problem is that I don't know in advance the text that appears in the table, so I can't use something like \settowidth\rotheadsize{text}.

This is what I have so far.

\documentclass{article}
\usepackage{graphicx}
\usepackage{makecell, rotating}
\begin{document}

\small

\noindent\begin{tabular}{@{}|p{2.5cm}|l|p{2cm}|l|l|p{16mm}|p{13mm}|@{}}
\hline
A & \rothead{text} & a long text that spans over multiple lines  & b & c & d & \rothead{efg} \\
\hline
\multicolumn{7}{|c|}{sometext} \tabularnewline
\hline
\end{tabular}

\end{document}


I would like to have the word 'text' and 'efg' at the bottom of the table cell so that it aligns nicely with the last baseline of “a long text ... multiple lines”.

Not sure if this is important: I use tabularx for the tables.

• a normal \rotatebox wouldn't hide the size of the rotated text so it would never over-print the lines and use a b column not p for the long text so the reference point of that text is its bottom line. – David Carlisle Nov 27 '19 at 9:40
• @DavidCarlisle I have never heard of b{...}. This seems to solve my problems. I'll do more tests and report back. – topskip Nov 27 '19 at 9:44
• texdoc array :-) – David Carlisle Nov 27 '19 at 9:48
• I wouldn't have thought that b solves your problem: it will move the A B and C too. – Ulrike Fischer Nov 27 '19 at 10:34

If you want everything (e.g. also the A) at the bottom using the [b] column type for the long column should work. If they should stay at the top, you will probably have to measure the large column, e.g. like this:

\documentclass{article}
\usepackage{graphicx}
\usepackage{makecell, rotating}
\usepackage{zref-savepos}
\begin{document}

\small

\newlength\startstopdistance
\startstopdistance=\dimexpr \zposy{stop}sp-\zposy{start}sp+\baselineskip+\arrayrulewidth\relax

\noindent\begin{tabular}{@{}|p{2.5cm}|l|p{2cm}|l|l|p{16mm}|p{13mm}|@{}}
\hline\noalign{\zsavepos{start}}
A & \raisebox{\startstopdistance}[0pt][0pt]{\rotatebox{90}{text}}& a long text that spans over multiple lines  & b & c & d &
\raisebox{\startstopdistance}[0pt][0pt]{\rotatebox{90}{efg}} \\
\hline\noalign{\zsavepos{stop}}
\multicolumn{7}{|c|}{sometext} \tabularnewline
\hline
\end{tabular}

\end{document}


• Thank you for anticipating my next problem together with a solution! – topskip Nov 27 '19 at 14:30