0

Consider following MWE :

\documentclass{report}
\usepackage{tabularx}
\usepackage{graphicx}
\begin{document}
\begin{tabular}{|c|c|}
\hline a & b \\ \hline
\rotatebox[origin=c]{90}{Hello} & d \\ \hline
e & f \\ \hline
\end{tabular}
\vspace{1cm}
\begin{tabular}{|c|c|}
\hline a & b \\ \hline
\rotatebox[origin=c]{90}{There} & \includegraphics[height=2cm]{dummy.png} \\ \hline
e & f \\ \hline
\end{tabular}
\end{document}

enter image description here

  • In the second line of the first table, the rotated text ("Hello") is vertically aligned with the text ("d") of its adjacent cell.

  • In the second table, there is a problem with the vertical alignment : the text seems to be aligned at the bottom [or left before rotation], and there is a whitespace below the figure. How can one obtain vertical alignment in this case?

I found this related question but it seems my problem is caused by the fact of adding an image in the adjacent cell.

2
  • 1
    to see why you get the layout you show draw in the baseline for the second table row, it passes through the centre of There (as you used origin=c) and along the bottom of the image, so space has to be added under the image to allow both to sit on the baseline. – David Carlisle Sep 9 '20 at 18:35
  • 1
    It should be noted that in many cases the baseline is slightly below the center. One can ishow the location of the baseline using \llap{\rule{1in}{0.5pt}} AFTER the text. – John Kormylo Sep 10 '20 at 15:04
1

For the second table with image:

\documentclass{report}
\usepackage{tabularx}
\usepackage[export]{adjustbox}

\begin{document}
\begin{tabular}{|c|c|}
\hline a & b \\ \hline
\rotatebox[origin=c]{90}{There} 
         & \includegraphics[height=2cm,valign=c,
                            margin= 0pt 3pt 0pt 3pt]{example-image-duck} \\
         \hline
e       & f \\ 
        \hline
\end{tabular}
\end{document}

enter image description here

2
  • How to choose the margins? Do they depend on the chosen height of the image? – Karlo Sep 10 '20 at 13:09
  • 1
    @Karlo, margin size is determined absolutely, it is independent from image size. it is defined as margin= <left> <above> <below> <right>.sinceon the left and tight size of image are already space \tabcolspace (6pt), You only need add space above and below of image. If you like to have the same space above/below as is left/right, than margin= 0pt 6pt 0pt 6pt. For details see documentation for adjustbox package. – Zarko Sep 10 '20 at 13:29

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.