将行标签集中在表格中

将行标签集中在表格中

我有一张桌子,它很好,但我想将其中一行标签集中起来。

我尝试使用\centralizing之前\multirow\begin{center}Integration\end{center}\vspace\hspace(因为它在\begin{sideways}INTEGRATION内部\end{sideways},所以没有得到任何结果。

这是表格代码,后面是一张突出显示我想要集中的标签的图片。

\begin{table*}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{|c|l|l|r|r|r|r|r|r|r|}
\cmidrule{5-10}    \multicolumn{1}{r}{} & \multicolumn{1}{r}{} & \multicolumn{1}{r}{} &       & \multicolumn{2}{c|}{2016} & \multicolumn{2}{c|}{2017} & \multicolumn{2}{c|}{2018} \\
    \midrule
    \multicolumn{1}{|l|}{Set} & Item  & Description & $\alpha$    & M     & (SD)  & M     & (SD)  & M     & (SD) \\
    \midrule
    \multirow{4}[8]{*}{\begin{sideways}YYYYYYYYYYYYY\end{sideways}} & postQ16 & xxxxxxxxxxxxxxxxx.  & 0.89  & 4     & 0.44  & 4     & 0.67  & 0     & (NA) \\
\cmidrule{2-10}          & postQ17 & xxxxxxxxxxxxxxxxx. & 0.91  & 4     & 0.68  & NA    & NA    & 1     & (NA) \\
\cmidrule{2-10}          & postQ18 & xxxxxxxxxxxxxxxxx. & 0.88  & 4     & 0.67  & 4     & 0.76  & 2     & (NA) \\
\cmidrule{2-10}          & postQ19 & xxxxxxxxxxxxxxxxx. & 0.86  & NA    & NA    & NA    & NA    & 3     & (NA) \\
    \midrule
    \multirow{3}[6]{*}{\begin{sideways}YYYYYYYYYYY\end{sideways}} & postQ20 & \multicolumn{1}{p{29.1em}|}{xxxxxxxxxxxxxxxxxxxxxx\newline{}xxxxxxxxxxxxxxxxxxxx \newline{}xxxxxxxxxxxxxxxxxxxxxxx. } & 0.88  & 4     & 0.45  & 4     & 0.71  & 0     & (NA) \\
\cmidrule{2-10}          & postQ21 & xxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.88  & 4     & 0.57  & 4     & 0.73  & 1     & (NA) \\
\cmidrule{2-10}          & postQ22 & \multicolumn{1}{p{29.1em}|}{xxxxxxxxxxxxxxxxxxxxxxxx.} & 0.93  & 4     & 0.56  & 5     & 0.71  & 2     & (NA) \\
    \midrule
    \multirow{4}[8]{*}{\begin{sideways}YYYYYYYY\end{sideways}} & postQ26 & xxxxxxxxxxxxxxxxxxxxx. & 0.86  & 4     & 0.61  & 4     & 0.62  & 0     & (NA) \\
\cmidrule{2-10}          & postQ27 & xxxxxxxxxxxxxxxxxxxxx. & 0.89  & 4     & 0.68  & NA    &       & 1     & (NA) \\
\cmidrule{2-10}          & postQ28 & xxxxxxxxxxxxxxxxxxxxx. & 0.85  & 4     & 0.68  & 4     & 0.79  & 2     & (NA) \\
\cmidrule{2-10}          & postQ29 & \multicolumn{1}{p{29.1em}|}{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \newline{}xxxxxxxxxxxxxxxxxxxxxxx.} & 0.85  & 4     & 0.58  & 4     & 0.64  & 3     & (NA) \\
    \midrule
    \multirow{4}[8]{*}{\begin{sideways}YYYYYY\end{sideways}} & postQ32 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.93  & 4     & 0.91  & NA    & NA    & 0     & (NA) \\
\cmidrule{2-10}          & postQ33 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.88  & 3     & 1.13  & NA    & NA    & 1     & (NA) \\
\cmidrule{2-10}          & postQ34 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.92  & NA    & NA    & NA    & NA    & 2     & (NA) \\
\cmidrule{2-10}          & postQ35 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.89  & 4     & 1.02  & NA    & NA    & 3     & (NA) \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table*}%

在此处输入图片描述

答案1

您的表格存在许多问题:

  • 非常长的非自然单词,无法用连字符连接(在下面的 MWE 中,我用可以连字符连接的单词间空格来打断它们)。
  • 在表格中你定义的很长cells,在这种情况下第三列有很多空白
  • 使用水平规则booktabs不适合使用垂直线
  • 旋转后的文本比单元格中的可用长度长得多multirow。您应该考虑用更多行来编写此文本
  • 您没有提供任何有关文档布局的信息,也没有提供表格是否可以横向显示

无论如何,我猜测下表可能就是您要找的:

在此处输入图片描述

(红线表示文本边框)

\documentclass[twocolumn]{article}
\usepackage{ragged2e}
\usepackage{rotating}
\usepackage{cellspace, multirow, tabularx}
    \setlength\cellspacetoplimit{5pt}
    \setlength\cellspacebottomlimit{5pt}
\newcolumntype{L}{>{\RaggedRight\hspace{0pt}}X}
    \addparagraphcolumntypes{L}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{table*}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabularx}{\linewidth}{|c|l|S{L}|c|r|r|r|r|r|r|}
    \cline{5-10}    
\multicolumn{4}{c|}{}   & \multicolumn{2}{c|}{2016} 
                            & \multicolumn{2}{c|}{2017}
                                & \multicolumn{2}{c|}{2018} \\
    \hline
   {Set} & Item  & Description & $\alpha$ & M & (SD) & M & (SD)  & M & (SD) \\
    \hline
\multirow{4}{*}{\begin{sideways}\parbox{6em}{\centering AAA AAAA AAA AAA}\end{sideways}} 
    & postQ16 & xxxxxx xxxxxxxxxxx.  & 0.89  & 4     & 0.44  & 4     & 0.67  & 0     & (NA) \\
    \cline{2-10}          
    & postQ17 & xxxxxxxx xxxxxxxxx. & 0.91  & 4     & 0.68  & NA    & NA    & 1     & (NA) \\
    \cline{2-10}          
    & postQ18 & xxxxx xxxx xxxx xxxx. & 0.88  & 4     & 0.67  & 4     & 0.76  & 2     & (NA) \\
    \cline{2-10}          
    & postQ19 & xxxxxx xxxxx xxxxxx. & 0.86  & NA    & NA    & NA    & NA    & 3     & (NA) \\
    \hline
    \multirow{5}{*}{\begin{sideways}\parbox{6em}{\centering BBB BBBBB BBB}\end{sideways}} 
    & postQ20 & {xxxxxx xxxxx xxxxx xxxxxx xxxxxx xxxx xxxxxxxxxx xxxxx xxxxxxxxx xxxxxxxxx. } & 0.88  & 4     & 0.45  & 4     & 0.71 & 0     & (NA) \\
    \cline{2-10}          
    & postQ21 & xxxxxx xxxxxxxxxxx xxxxxxxxx. & 0.88 & 4 & 0.57 & 4  & 0.73  & 1 & (NA) \\
    \cline{2-10}          
    & postQ22 & {xxxxx xxxxxxxxx xxxxx xxxxx.} & 0.93 & 4 & 0.56 & 5 & 0.71  & 2 & (NA) \\
    \hline
    \multirow{6}[8]{*}{\begin{sideways}CCCCCCCC\end{sideways}} 
    & postQ26 & xxxx xxxxxxxxxxx xxx xxx. & 0.86 & 4 & 0.61 & 4  & 0.62  & 0  & (NA) \\
    \cline{2-10}          
    & postQ27 & xxxx xxxx xxxx xxxxx xxxx. & 0.89 & 4 & 0.68  & NA &   & 1 & (NA) \\
    \cline{2-10}         
    & postQ28 & xxxxxx xxxxx xxxx xxxxxx. & 0.85  & 4 & 0.68  & 4 & 0.79  & 2 & (NA) \\
    \cline{2-10}         
    & postQ29 & {xxxxxxx xxxxxxx xxxxxxxx xxxxxxxxxx xxxxxxx xxxxxxxxxxx xxxxx.} 
        & 0.85  & 4  & 0.58  & 4 & 0.64 & 3  & (NA) \\
    \hline
    \multirow{8}{*}{\begin{sideways}DDDDDD\end{sideways}} 
    & postQ32 & xxxxxxxxxxxx xxxxxxx xxxxxxxx xxxxxxxx. & 0.93  & 4 & 0.91 & NA & NA & 0     & (NA) \\
    \cline{2-10}          
    & postQ33 & xxxxx xxxxxxxx xxxxxxx xxxxxxxxxxx. 
        & 0.88  & 3 & 1.13 & NA & NA & 1 & (NA) \\
    \cline{2-10}          
    & postQ34 & xxxxxxxx xxxx xxxx xxxxx xxxxx xxxxx. 
        & 0.92  & NA    & NA    & NA    & NA    & 2     & (NA) \\
    \cline{2-10}          
    & postQ35 & xxxx xxxxx xxxxx xxxxxxx xxxxx xxxxx. 
        & 0.89  & 4     & 1.02  & NA    & NA    & 3     & (NA) \\
    \hline
    \end{tabularx}%
  \label{tab:addlabel}%
\end{table*}%
\end{document}

答案2

您的问题是 YYYY 标签的字符太多,超出了可用空间。如果您缩短它们,就会出现问题。您有几种选择:缩短文本、减小字体大小、使用多行。

我更改了表格以简化代码。首先,最右边的七列应具有相同的宽度。我使用七个固定宽度的w大批-package。另外,我将表格改为表格型并将第三列设置为X-column,其中 tabularx 计算正确的宽度。由于 X 列是段落列,因此您可以删除\multirow几个位置。此外,我删除了垂直线。

如果您的侧向标题很长,并且标题需要多行,我添加了第二个示例来执行此操作。我定义了一个\swthead有两个参数的宏,第一个参数是您希望标题向上移动到中心的距离,另一个参数是标题本身。宏将表格放在 中rotatebox,这也意味着您必须使用 自行换行。正如我所说,您可以通过在宏中\\添加距离作为第一个参数来对齐标题。pt

示例 1

在此处输入图片描述

\documentclass{article}
\usepackage{array, booktabs, rotating, pdflscape, multirow, tabularx}

\begin{document}
\begin{landscape}
\begin{table*}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabularx}{\linewidth}{@{}cl>{\raggedright\arraybackslash}X*{7}{wr{0.75cm}}@{}}
\cmidrule{5-10}    \multicolumn{4}{r}{}    & \multicolumn{2}{c}{2016} & \multicolumn{2}{c}{2017} & \multicolumn{2}{c@{}}{2018} \\
    \midrule
    \multicolumn{1}{l}{Set} & Item  & Description & $\alpha$    & M     & (SD)  & M     & (SD)  & M     & (SD) \\
    \midrule
    \multirow{4}[8]{*}{\begin{sideways}\centering\small YYYY\end{sideways}} & postQ16 & xxxxxxxxxxxxxxxxx.  & 0.89  & 4     & 0.44  & 4     & 0.67  & 0     & (NA) \\
\cmidrule{2-10}          & postQ17 & xxxxxxxxxxxxxxxxx. & 0.91  & 4     & 0.68  & NA    & NA    & 1     & (NA) \\
\cmidrule{2-10}          & postQ18 & xxxxxxxxxxxxxxxxx. & 0.88  & 4     & 0.67  & 4     & 0.76  & 2     & (NA) \\
\cmidrule{2-10}          & postQ19 & xxxxxxxxxxxxxxxxx. & 0.86  & NA    & NA    & NA    & NA    & 3     & (NA) \\
    \midrule
    \multirow{3.5}[6]{*}{\begin{sideways}\centering\small YYYYYY\end{sideways}} & postQ20 & xxxxxxxxxxxxxxxxxxxxxx  xxxxxxxxxxxxxxxxxxxx  xxxxxxxxxxxxxxxxxxxxxxx & 0.88  & 4     & 0.45  & 4     & 0.71  & 0     & (NA) \\
\cmidrule{2-10}          & postQ21 & xxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.88  & 4     & 0.57  & 4     & 0.73  & 1     & (NA) \\
\cmidrule{2-10}          & postQ22 & xxxxxxxxxxxxxxxxxxxxxxxx & 0.93  & 4     & 0.56  & 5     & 0.71  & 2     & (NA) \\
    \midrule
    \multirow{4.25}[8]{*}{\begin{sideways}\centering\small YYYYYYYY\end{sideways}} & postQ26 & xxxxxxxxxxxxxxxxxxxxx. & 0.86  & 4     & 0.61  & 4     & 0.62  & 0     & (NA) \\
\cmidrule{2-10}          & postQ27 & xxxxxxxxxxxxxxxxxxxxx. & 0.89  & 4     & 0.68  & NA    &       & 1     & (NA) \\
\cmidrule{2-10}          & postQ28 & xxxxxxxxxxxxxxxxxxxxx. & 0.85  & 4     & 0.68  & 4     & 0.79  & 2     & (NA) \\
\cmidrule{2-10}          & postQ29 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxx & 0.85  & 4     & 0.58  & 4     & 0.64  & 3     & (NA) \\
    \midrule
    \multirow{3.5}[8]{*}{\begin{sideways}\centering\small YYYYYY\end{sideways}} & postQ32 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.93  & 4     & 0.91  & NA    & NA    & 0     & (NA) \\
\cmidrule{2-10}          & postQ33 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.88  & 3     & 1.13  & NA    & NA    & 1     & (NA) \\
\cmidrule{2-10}          & postQ34 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.92  & NA    & NA    & NA    & NA    & 2     & (NA) \\
\cmidrule{2-10}          & postQ35 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.89  & 4     & 1.02  & NA    & NA    & 3     & (NA) \\
    \bottomrule
    \end{tabularx}%
  \label{tab:addlabel}%
\end{table*}%

\end{landscape}

\end{document}

示例 2

在此处输入图片描述

\documentclass{article}
\usepackage{array, booktabs, rotating, pdflscape, multirow, tabularx}

\newcommand*{\swthead}[2]{%
\raisebox{#1}[0pt][0pt]{\rotatebox[origin=c]{90}{\small\begingroup
    \renewcommand*{\arraystretch}{1}%
    \begin{tabular}[c]{c} #2\end{tabular}%
  \endgroup%
}}}


\begin{document}
\begin{landscape}

\begin{table*}[htbp]
\centering
\caption{Add caption}
\begin{tabularx}{\linewidth}{@{}ll>{\raggedright\arraybackslash}X*{7}{wr{0.75cm}}@{}}
\cmidrule(l{\tabcolsep}){5-10}
\multicolumn{4}{r}{} & \multicolumn{2}{c}{2016} &
\multicolumn{2}{c}{2017} & \multicolumn{2}{c@{}}{2018} \\
\midrule
\multicolumn{1}{l}{Set} & Item  & Description & $\alpha$ &
 M & (SD) & M & (SD) & M & (SD)\\
\midrule
  & postQ16 & xxxxxxxxxxxxxxxxx & 0.89 & 4 & 0.44  & 4     & 0.67  & 0     & (NA) \\
\cmidrule(l{\tabcolsep}){2-10}
  & postQ17 & xxxxxxxxxxxxxxxxx & 0.91 & 4 & 0.68  & NA    & NA    & 1     & (NA) \\
\cmidrule(l{\tabcolsep}){2-10}
  & postQ18 & xxxxxxxxxxxxxxxxx & 0.88 & 4 & 0.67  & 4     & 0.76  & 2     & (NA) \\
\cmidrule(l{\tabcolsep}){2-10}
\swthead{25pt}{YYYYYYYY\\ZZZ} & postQ19 & xxxxxxxxxxxxxxxxx. & 0.86 & NA & NA & NA & NA & 3 & (NA) \\
\midrule
  & postQ20 & xxxxxxxxxxxxxxxxxxxxxx  xxxxxxxxxxxxxxxxxxxx  xxxxxxxxxxxxxxxxxxxxxxx & 0.88 & 4 & 0.45 & 4 & 0.71  & 0 & (NA) \\
\cmidrule(l{\tabcolsep}){2-10}
  & postQ21 & xxxxxxxxxxxxxxxxxxxxxxxxxx & 0.88 & 4 & 0.57 & 4 & 0.73 & 1 & (NA) \\
\cmidrule(l{\tabcolsep}){2-10}
\swthead{22pt}{YYYYYYYY} & postQ22 & xxxxxxxxxxxxxxxxxxxxxxxx & 0.93 & 4 & 0.56 & 5 & 0.71 & 2 & (NA) \\
\midrule
  & postQ26 & xxxxxxxxxxxxxxxxxxxxx & 0.86 & 4 & 0.61 & 4 & 0.62 & 0 & (NA) \\
\cmidrule(l{\tabcolsep}){2-10} 
  & postQ27 & xxxxxxxxxxxxxxxxxxxxx & 0.89 & 4 & 0.68 & NA & & 1 & (NA) \\
\cmidrule(l{\tabcolsep}){2-10} 
  & postQ28 & xxxxxxxxxxxxxxxxxxxxx & 0.85 & 4 & 0.68  & 4 & 0.79 & 2 & (NA) \\
\cmidrule(l{\tabcolsep}){2-10}
\swthead{20pt}{YYYYYYYY}  & postQ29 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxx & 0.85 & 4 & 0.58  & 4 & 0.64  & 3 & (NA) \\
\midrule
  & postQ32 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx & 0.93 & 4 & 0.91 & NA & NA & 0 & (NA) \\
\cmidrule(l{\tabcolsep}){2-10}
  & postQ33 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx & 0.88 & 3 & 1.13 & NA & NA & 1 & (NA) \\
\cmidrule(l{\tabcolsep}){2-10}
  & postQ34 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx & 0.92 & NA & NA & NA & NA & 2 & (NA) \\
\cmidrule(l{\tabcolsep}){2-10}
\swthead{25pt}{YYYYYYYY} & postQ35 & xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. & 0.89 & 4 & 1.02 & NA & NA    & 3 & (NA) \\
\bottomrule
\end{tabularx}%
\label{tab:addlabel}%
\end{table*}%

\end{landscape}
\end{document}

相关内容