1

I would like to rotate the two-lines label of one of my table's column header by ~60°. I tried to use \rotatebox as some examples indicates. However, this macro rotate the whole box without pushing the second line of the text a little more to make both lines start at the same horizontal alignment.

    \documentclass{article}
    \usepackage{graphicx}
    \usepackage{booktabs}

    \begin{document}
    \begin{tabular}{lll}
      Thing & \rotatebox{60}{Height} &
        \rotatebox{60}{\parbox{6em}{Width \\ (end to end)}} \\
      \midrule

      House & 10m & 10m \\
      Car & 1m & 5m \\
      Crane & 15m & 20m \\
      \bottomrule
    \end{tabular}
    \end{document}

I still can hack that by adding manually a space (a \quad or a ~ for example) at the beginning of the second line… but that's not really beautiful and may be annoying while modifying the text or with many more lines.

Is there another way to rotate the text while keeping it vertically aligned along the table's \midrule?

1
  • 1
    pe of the first leerIt is geometrically impossivle: the correction depends on the shape of the first letter, and TeX manipulates rectangular boxes.
    – Bernard
    Commented Jul 25, 2019 at 14:28

1 Answer 1

2

While not perfect, due to the geometry of letters, I suggest to rotate each line of text, in the case of multiline column heads. Furthermore, I think the last two columns should be right aligned , except for the column heads, which should be left aligned. This leads to use \rlapto keep the column heads aboce the below cells, and to compensate the spacing w.r.t. the text above with \addlinespace:

\documentclass{article}
\usepackage{graphicx}
\usepackage{booktabs}

\begin{document}

Some text. Some other text. Some more text. Some more text. 

\begin{tabular}{lrr}
\addlinespace[2ex ]
  Thing & \multicolumn{1}{l}{\,\,\rlap{\rotatebox{60}{Height}}} &
   \multicolumn{1}{l}{ \rlap{\rotatebox[origin = lb]{60}{Width}\hspace{-0.75em}\rotatebox[origin = lb]{60}{(end to end)}}} \\
  \midrule
  House & 10m & 10m \\
  Car & 1m & 5m \\
  Crane & 15m & 20m \\
  \bottomrule
\end{tabular}

\end{document} 

enter image description here

3
  • addlinespace should be \addlinespace
    – Black Mild
    Commented Jul 25, 2019 at 22:27
  • Yes. Bad copy-paste. Thanks for warning ma!
    – Bernard
    Commented Jul 25, 2019 at 22:55
  • OK. As you say, not perfect as it still requires e.g. arbitrary (and required) \hspace{-0.75em}, but still relatively easy to code and with beautiful output. Thanks.
    – audeoudh
    Commented Jul 26, 2019 at 8:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .