1

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}
\renewcommand\theadalign{lb}
\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}

enter image description here

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
2

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}
\renewcommand\theadalign{lb}
\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}

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.