I am trying to horizontally align text that has been rotated in a table. I want the rotated "Lorem Ipsum" and the rotated "Lorem Ipsum & Lorem Ipsum" text to be horizontally centered in the cell. When I adjust the width of each column manually, the alignment is no longer centered. I need to modify the width of each column so that my table will fit in the width of a single column.
I tried using the \multirow
command from How can I align rotated text in a table at the bottom? but I was only able to modify the vertical alignment.
Here is what my table looks like:
Here is the code (apologies if I included some unnecessary packages):
\documentclass{article}
\usepackage{array}
\usepackage{tabularx}
\usepackage{rotating}
\usepackage{lipsum}
\usepackage{multirow}
\begin{document}
\newcommand\RotText[1]{\fontsize{9}{9}\selectfont \rotatebox[origin=c]{90}{\parbox{2.6cm}{\centering#1}}}
\newcolumntype{G}{>{\centering\arraybackslash}m{.0625cm}}
\newcolumntype{U}{>{\centering\arraybackslash}m{.375cm}}
{\centering
\begin{center}\begin{table}[ht]\caption{Lorem Ipsum Table}
\footnotesize
\centering
\begin{tabular}{|c|G|U|U|U|U|G|G|G|U|}
\hline
& \multicolumn{9}{c|}{Lorem Ipsum} \\
\cline{2-10}
Instruction & \RotText{Lorem Ipsum} & \RotText{Lorem Ipsum \& Lorem Ipsum} & \RotText{Lorem Ipsum \& Lorem Ipsum} & \RotText{Lorem Ipsum \& Lorem Ipsum} &
\RotText{Lorem Ipsum \& Lorem Ipsum} & \RotText{Lorem Ipsum} & \RotText{Lorem Ipsum} & \RotText{Lorem Ipsum} & \RotText{Lorem Ipsum \& Lorem Ipsum} \\
\hline
Lorem Ipsum &
& & X & & & & & & \\
\hline
\end{tabular}
\end{table}
\end{center}
}
\lipsum
\end{document}
Best Answer
REVISED SOLUTION
One of the problems with your MWE and my earlier tweak thereof was that it did not account for the natural space allocated, by default, between columns, defined by the length
\tabcolsep
. If narrow is desired, the first thing to do is turn that off, with\setlength\tabcolsep{0pt}
. Then, there are no\vspace
tweaks required, and the problem becomes determining the column width that satisfies your requirement.Here, I strove to make the columns as narrow as possible, again, with no tweaking. Note, I saved a copy of
\tabcolsep
into\svtabcolsep
, if I need to reinstate it later.Note you could even dispense with the
G
andU
column types, making them insteadc
, and using a small, finite value of\tabcolsep
to achieve your goal.