如何水平对齐旋转文本下方行中的文本?

如何水平对齐旋转文本下方行中的文本?

我有一个表格,最上列的文本是旋转的,但在某些行中,X 不是水平居中。我以为使用 \centering 或 origin=c 命令可以解决这个问题,但并没有。

该表如下所示: 在此处输入图片描述

以下是代码:

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

答案1

您的许多阴谋诡计都可以被消除。关键是修改长度\tabcolsep以缩小列。我现在使用简单的c列,没有\vspaces 也没有单独的\RotText版本等。

已修改以保留 OP 所需的列宽。我按照 OP 的定义将2\tabcolsep=添加到和列宽12pt中,然后设置为。希望结果保留 OP 所需的宽度,同时正确居中列。注意:我确实必须在第 1 列周围重新插入 6pt,以恢复原始外观,因为它既不是也不是列。GU\tabcolsep0ptGU

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

在此处输入图片描述


原始答案,使用可变宽度的列。

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

在此处输入图片描述

相关内容