1

I have a tabularx table that has been rotated 90 degrees using rotatebox, contained in a figure.

Something is preventing LaTeX from centring the figure on the page: it is close, but slightly too far towards the top of the page.

Does anyone know what is going on here? Any assistance would be greatly appreciated.

MWE:

\documentclass[11pt, a4paper]{book}
\usepackage{pifont,tabularx,adjustbox,booktabs}

\begin{document}

\begin{figure}
    \newcolumntype{R}[2]{%
    >{\adjustbox{angle=#1,lap=\width-(#2)}\bgroup}%
    l%
    <{\egroup}%
}
\newcommand*\rot{\multicolumn{1}{R{30}{1em}}}
\newcommand*\sq{\mathbin{\vcenter{\hbox{\rule{.2ex}{.2ex}}}}}

\scriptsize
\rotatebox[origin=bl]{90}{
\begin{tabularx}{\textwidth}{lcccccccccccccccccccc}
& \multicolumn{18}{c}{\textsc{Data 1}}\\
 & \rot{Name A} & \rot{Name B} & \rot{Name C} & \rot{Name D} & \rot{Name E} & \rot{Name F} & \rot{Name G} & \rot{Name H} & \rot{Name I} & \rot{Name J} & \rot{Name K} & \rot{Name L} & \rot{Name M} & \rot{Name N} & \rot{Name O} & \rot{Name P} & \rot{Name Q} & \rot{Name R} & \\
\cmidrule{2-20}
\textsc{Data 2} & & & & & & & & & & & & & & & & & & & \\
Name S & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & \ding{51} & \\
\end{tabularx}
}
    \caption{This is a caption.}
\end{figure}

\end{document}
2
  • Wouldn't it be simpler to use the sidewaystable environment?
    – Bernard
    Commented Aug 9, 2019 at 11:15
  • Yes, it would be. The problem that I encountered is that sidewaystable didn't appear to play nicely with \adjustbox (I ma be wrong about that); but in any event sidewaystable didn't want to compile.
    – Craig
    Commented Aug 10, 2019 at 8:35

1 Answer 1

3

Your table is wider than \textwidth. However, a tabularx makes only sense if you use the column specifier X.

\documentclass[11pt, a4paper]{book}
\usepackage{pifont,tabularx,adjustbox,booktabs}
\usepackage{showframe}

\begin{document}

\begin{figure}
    \newcolumntype{R}[2]{%
            >{\adjustbox{angle=#1,lap=\width-(#2)}\bgroup}%
            l%
            <{\egroup}%
        }
        \newcommand*\rot{\multicolumn{1}{R{30}{1em}}}
        \newcommand*\sq{\mathbin{\vcenter{\hbox{\rule{.2ex}{.2ex}}}}}
        \scriptsize\centering
        \rotatebox[origin=bl]{90}{%
            \begin{tabular}{lcccccccccccccccccccc}
                & \multicolumn{18}{c}{\textsc{Data 1}}\\
                & \rot{Name A} & \rot{Name B} & \rot{Name C} & \rot{Name D} & \rot{Name E} & \rot{Name F} & 
                \rot{Name G} & \rot{Name H} & \rot{Name I} & \rot{Name J} & \rot{Name K} & \rot{Name L} & 
                \rot{Name M} & \rot{Name N} & \rot{Name O} & \rot{Name P} & \rot{Name Q} & \rot{Name R} & \\
                \cmidrule{2-20}
                \textsc{Data 2} & & & & & & & & & & & & & & & & & & & \\
                Name S & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & 
                $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & $\sq$ & \ding{51} & \\
            \end{tabular}%
        }
        \caption{This is a caption.}
    \end{figure}

\end{document}

enter image description here

1
  • Bingo. Thanks very much!
    – Craig
    Commented Aug 10, 2019 at 8:41

You must log in to answer this question.

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