2

I have a table with rotated text in the uppermost columns, however in certain rows the X's are not horizontally centered. I thought that having the \centering or perhaps the origin=c command would fix this, but it hasn't.

Here is what the table looks like: enter image description here

Here is the code:

\documentclass{article}
\usepackage{array}
\usepackage{rotating}
\usepackage{lipsum}

\begin{document}

\newcolumntype{G}{>{\centering\arraybackslash}m{.0535cm}}
\newcolumntype{U}{>{\centering\arraybackslash}m{.450cm}}
\newcommand\RotTextTwo[1]{\fontsize{9}{9}\selectfont
  \rotatebox[origin=c]{90}{\parbox{2.6cm}{\vspace{-.4\ht\strutbox}\centering#1}}}
\newcommand\RotTextThree[1]{\fontsize{9}{9}\selectfont
  \rotatebox[origin=c]{90}{\parbox{2.6cm}{\vspace{-.15\ht\strutbox}\centering#1}}}


\begin{table}[t]\caption{This is a table I am using}
\footnotesize
\centering
\begin{tabular}{|c|G|U|U|G|U|G|G|G|U|}
\hline
 & \multicolumn{9}{c|}{Some Text} \\ 
\cline{2-10}

Bunch of Text & \RotTextTwo{Garbage Text} & \RotTextThree{Garbage Text Garbage} & \RotTextThree{Garbage Text Garbage} & \RotTextTwo{Garbage Text} & 
\RotTextThree{Garbage Text Garbage} & \RotTextTwo{Garbage Text} & \RotTextTwo{Garbage Text} & \RotTextTwo{Garbage Text} & \RotTextThree{Garbage TextGarbage } \\
\hline
\textit{Meaningless Text 2} & 
& & X   & & & & & & \\
\hline
\textit{Meaningless Text 3} & 
& & X   & & & & & & \\
\hline
\textit{Meaningless Text 4} & 
& X & & & & & & & \\
\hline
\textit{Meaningless Text 5} & 
& X &   X   & & & & & & \\
\hline
\textit{Meaningless Text 6} & 
& X & X & & & & & & \\
\hline
\textit{Meaningless Text 7} & 
& X & X & & & & & & \\
\hline                      
\textit{Meaningless 8} & 
& & & & & & X & & \\
\hline      
\textit{Meaningless Text 9} & 
& & & X & & & & & \\
\hline
\textit{Meaningless 10} & 
& & & X & & & & & \\
\hline
\textit{Meaningless Text 11} & 
& & & & & & & X & \\
\hline
\textit{Meaningless 12} & 
& & & & X   & & & & \\
\hline
\textit{Meaningless Text 13} &
& & & & X   & & & & \\
\hline
\textit{Meaningless 14} & 
& & & & & & & & X \\
\hline
\end{tabular}
\label{tab:nada}
\end{table}

\lipsum

\end{document}
2

Much of your machinations could be removed. The key was to modify the length \tabcolsep to narrow the columns. I now use simple c columns, no \vspaces nor separate \RotText versions, etc.

REVISED to retain OP's desired column widths. I added 2\tabcolsep = 12pt to the G and U column widths, as defined by the OP, but then set \tabcolsep to 0pt. Hopefully, the result retains the widths desired by the OP, while centering the columns properly. Note: I did have to reinsert 6pt around column 1, in order to recover original look, since it was neither a G nor U column.

\documentclass{article}
\usepackage{array}
\usepackage{rotating}
\usepackage{lipsum}  
\begin{document}
\newcolumntype{G}{>{\centering\arraybackslash}m{\dimexpr.0535cm+12pt\relax}}
\newcolumntype{U}{>{\centering\arraybackslash}m{\dimexpr.450cm+12pt\relax}}
\newcommand\RotText[1]{\fontsize{9}{9}\selectfont
  \rotatebox[origin=c]{90}{\parbox{2.6cm}{\centering#1}}}
\begin{table}[t]\caption{This is a table I am using}
\setlength\tabcolsep{0pt}
\footnotesize
\centering
\begin{tabular}{|@{\hspace{6pt}}c@{\hspace{6pt}}|G|U|U|G|U|G|G|G|U|}
\hline
 & \multicolumn{9}{c|}{Some Text} \\ 
\cline{2-10}
Bunch of Text & \RotText{Garbage Text} & \RotText{Garbage Text Garbage} & \RotText{Garbage Text Garbage} & \RotText{Garbage Text} & 
\RotText{Garbage Text Garbage} & \RotText{Garbage Text} & \RotText{Garbage Text} & \RotText{Garbage Text} & \RotText{Garbage TextGarbage } \\
\hline
\textit{Meaningless Text 2} & 
& & X   & & & & & & \\
\hline
\textit{Meaningless Text 3} & 
& & X   & & & & & & \\
\hline
\textit{Meaningless Text 4} & 
& X & & & & & & & \\
\hline
\textit{Meaningless Text 5} & 
& X &   X   & & & & & & \\
\hline
\textit{Meaningless Text 6} & 
& X & X & & & & & & \\
\hline
\textit{Meaningless Text 7} & 
& X & X & & & & & & \\
\hline                      
\textit{Meaningless 8} & 
& & & & & & X & & \\
\hline      
\textit{Meaningless Text 9} & 
& & & X & & & & & \\
\hline
\textit{Meaningless 10} & 
& & & X & & & & & \\
\hline
\textit{Meaningless Text 11} & 
& & & & & & & X & \\
\hline
\textit{Meaningless 12} & 
& & & & X   & & & & \\
\hline
\textit{Meaningless Text 13} &
& & & & X   & & & & \\
\hline
\textit{Meaningless 14} & 
& & & & & & & & X \\
\hline
\end{tabular}
\label{tab:nada}
\end{table}

\lipsum
\end{document}

enter image description here


ORIGINAL ANSWER, using variable width columns.

\documentclass{article}
\usepackage{array}
\usepackage{rotating}
\usepackage{lipsum}  
\begin{document}
\newcommand\RotText[1]{\fontsize{9}{9}\selectfont
  \rotatebox[origin=c]{90}{\parbox{2.6cm}{\centering#1}}}
\begin{table}[t]\caption{This is a table I am using}
\footnotesize
\centering
\let\svtabcolsep\tabcolsep
\setlength\tabcolsep{3pt}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
\hline
 & \multicolumn{9}{c|}{Some Text} \\ 
\cline{2-10}

Bunch of Text & \RotText{Garbage Text} & \RotText{Garbage Text Garbage} & \RotText{Garbage Text Garbage} & \RotText{Garbage Text} & 
\RotText{Garbage Text Garbage} & \RotText{Garbage Text} & \RotText{Garbage Text} & \RotText{Garbage Text} & \RotText{Garbage TextGarbage } \\
\hline
\textit{Meaningless Text 2} & 
& & X   & & & & & & \\
\hline
\textit{Meaningless Text 3} & 
& & X   & & & & & & \\
\hline
\textit{Meaningless Text 4} & 
& X & & & & & & & \\
\hline
\textit{Meaningless Text 5} & 
& X &   X   & & & & & & \\
\hline
\textit{Meaningless Text 6} & 
& X & X & & & & & & \\
\hline
\textit{Meaningless Text 7} & 
& X & X & & & & & & \\
\hline                      
\textit{Meaningless 8} & 
& & & & & & X & & \\
\hline      
\textit{Meaningless Text 9} & 
& & & X & & & & & \\
\hline
\textit{Meaningless 10} & 
& & & X & & & & & \\
\hline
\textit{Meaningless Text 11} & 
& & & & & & & X & \\
\hline
\textit{Meaningless 12} & 
& & & & X   & & & & \\
\hline
\textit{Meaningless Text 13} &
& & & & X   & & & & \\
\hline
\textit{Meaningless 14} & 
& & & & & & & & X \\
\hline
\end{tabular}
\label{tab:nada}
\end{table}

\lipsum

\end{document}

enter image description here

  • Thank you for your solution, however I need to specify columns widths manually for my purposes. – Veridian Apr 4 '14 at 16:35
  • @sphere Please see revision. Your original definition of a G column as 0.0535cm doesn't make sense, which is why you needed \vspace corrections. So what I did was to specify the column widths to what you actually want them, while setting \tabcolsep to 0pt. – Steven B. Segletes Apr 4 '14 at 17:33

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.