8

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:

Table

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}
1
  • Apologies, I posted the old code. I have since fixed it.
    – Veridian
    Mar 19, 2014 at 16:08

3 Answers 3

3

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.

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}
\usepackage{rotating}
\usepackage{lipsum}
\usepackage{multirow}
\begin{document}

\let\svtabcolsep\tabcolsep
\setlength\tabcolsep{0pt}
\newcommand\RotText[1]{\fontsize{9}{9}\selectfont
  \rotatebox[origin=c]{90}{\parbox{2.6cm}{%
\centering#1}}}
\newcolumntype{G}{>{\centering\arraybackslash}m{.35cm}}
\newcolumntype{U}{>{\centering\arraybackslash}m{.62cm}}

\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}

\lipsum

\end{document}

enter image description here

Note you could even dispense with the G and U column types, making them instead c, and using a small, finite value of \tabcolsep to achieve your goal.

\let\svtabcolsep\tabcolsep
\setlength\tabcolsep{.3pt}
\newcolumntype{G}{c}
\newcolumntype{U}{c}
14
  • Not to be picky, but the rotated "Lorem Ipsum"s still aren't centered.
    – Veridian
    Mar 19, 2014 at 16:35
  • .0625cm wide table columns are distinctly odd, but you are suggesting changing them to be 0cm wide? Mar 19, 2014 at 16:40
  • Thanks looks good. I'm not a huge fan of "hacks" with magic numbers. I wish latex packages would have more automatic handling of centering.
    – Veridian
    Mar 19, 2014 at 16:44
  • @DavidCarlisle I am not a tabular whiz, so in this case, rather than redoing it from scratch, I started with the OP's code, and "tweaked." Tweaking is under-rated. I was doing it long before that Miley whats-her-name girl. Mar 19, 2014 at 16:45
  • @sphere latex will centre automatically with no problems but not if you ask it to centre visible text in a column that is only half a millimetre wide, it can't centre it so it sticks it out one side/ Mar 19, 2014 at 16:55
5

Your box was far wider than the specified width of the column, so centreing could not work. Also don't put the table inside a center environment it will float away leaving spurious vertical space from the center display with nothing in it.

enter image description here

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}
\usepackage{rotating}
\usepackage{lipsum}
\usepackage{multirow}
\begin{document}

\newcommand\RotText[1]{\rotatebox[origin=c]{90}{\parbox{2.6cm}{\centering#1}}}
\newcolumntype{G}{>{\centering\arraybackslash}m{.6cm}}
\newcolumntype{U}{>{\centering\arraybackslash}m{.6cm}}

\setlength\extrarowheight{3pt}
\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}


\lipsum

\end{document}
2
  • Thank you for your help, however this doesn't fix my problem. The columns are too wide now. You modified the newcolumntype and when I go back to adjust it, the same problem occurs.
    – Veridian
    Mar 19, 2014 at 16:21
  • @sphere well make them smaller (but not as small as you had it which doesn't leave room for visible text at all .0625cm is really very narrow. Latex warns on the command line for every overfull box so just reduce the font size till it fits. Mar 19, 2014 at 16:39
1

If you really want to pack them in tight...

table

\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{C}{@{\hspace{2pt}}c@{\hspace{1pt}}}

\begin{table}[ht]\caption{Lorem Ipsum Table}
\footnotesize
\centering
\begin{tabular}{|c|C|C|C|C|C|C|C|C|C|}
\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}


\lipsum

\end{document}

You must log in to answer this question.

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