# Vertically align vertical text in booktabs and multirows

I am trying to create a table such as the one presented here, but the text within the first two columns should be centered vertically. However, I am not able to achieve it. What am I doing wrong? I have a warning of "bad \vbox", which I guess its causing the problem, but I do not know how to solve it.

The MWE:

\documentclass[
ngerman,
accentcolor=9c,% Farbe für Hervorhebungen auf Basis der Deklarationen in den
type=intern,
marginpar=false
]{tudapub}
\usepackage[english, main=ngerman]{babel}
\usepackage[autostyle]{csquotes}

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{mwe}

\begin{document}
\begin{table}[!h]
\centering
\begin{tabular}{ccccccc}
\toprule
&%
& Central Layer%
& \multicolumn{4}{c}{Top Layer}%
\\
\cmidrule(lr){3-3}
\cmidrule(lr){4-7}
&%
& X = 0 \& Z = -2b%
& X = 0 \& Z = 0%
& X = 0 \& Z = 2b%
& X = 0 \& Z = -2b%
& X = ann \& Z = 0%
\\%
\midrule
\multirow{2}{*}{\rotatebox[origin=c]{90}{Resonance frequency, $f_\mathrm{0}$ = 81.3 GHz}}%
& \rotatebox[origin=c]{90}{E-field}%
& \includegraphics[width=3cm,height=4cm]{example-image}%
& 2%
& 3%
& 4%
& 5%
\\%
&\rotatebox[origin=c]{90}{H-field}%
& \includegraphics[width=3cm,height=4cm]{example-image}%
& 2%
& 3%
& 4%
& 5%
\\%
\bottomrule
\end{tabular}
\end{table}
\end{document}

• What about the vertical alignment of the contents in the "Top Layer" columns. Do you want these contents vertically centered with respect to the image as well? If so, add valign=c to the options of \includegraphics and place \usepackage[export]{adjustbox} in the preamble of the document. Feb 17 '21 at 18:17
• @leandriis worked like a charm! If you want to write it as an answer, I will mark it as accepted :) Thank you
– Jes
Feb 17 '21 at 19:35
• @leandriis I tried a little bit more and its only the "E-field" and "H-field" the text that is centered now. The part corresponding to "Resonance frequency" still is bottom-aligned, owing to a bad box. Do you have any idea of what is going on here?
– Jes
Feb 17 '21 at 20:02

## 1 Answer

With the help of valign=c from adjustbox, \Block and NiceTabular from nicematrix and \makebox[0pt]:

\documentclass[
ngerman,
accentcolor=9c,% Farbe für Hervorhebungen auf Basis der Deklarationen in den
type=intern,
marginpar=false
]{tudapub}
\usepackage[english, main=ngerman]{babel}
\usepackage[autostyle]{csquotes}

\usepackage{nicematrix}
\usepackage{booktabs}
\usepackage[export]{adjustbox}

\begin{document}
\begin{table}[!h]
\centering
\begin{NiceTabular}{ccccccc}
\toprule
&%
& Central Layer%
& \Block{1-4}{Top Layer}%
\\
\cmidrule(lr){3-3}
\cmidrule(lr){4-7}
&%
& X = 0 \& Z = -2b%
& X = 0 \& Z = 0%
& X = 0 \& Z = 2b%
& X = 0 \& Z = -2b%
& X = ann \& Z = 0%
\\%
\midrule
\Block{2-1}{\rotate Resonance frequency, $f_\mathrm{0}$ = 81.3 GHz}%
& \Block{1-1}{\rotate \makebox[0pt]{E-field}}
& \includegraphics[width=3cm,height=4cm, valign=c]{example-image}%
& 2%
& 3%
& 4%
& 5%
\\%
& \Block{1-1}{\rotate \makebox[0pt]{H-field}}
& \includegraphics[width=3cm,height=4cm, valign=c]{example-image}%
& 2%
& 3%
& 4%
& 5%
\\%
\bottomrule
\end{NiceTabular}
\end{table}
\end{document}

• Worked perfectly, thank you!
– Jes
Feb 18 '21 at 8:11