将列标题放在一行上

将列标题放在一行上

我有下表:

\documentclass[12pt,notitlepage]{article}
\usepackage{setspace} 
\usepackage{ifthen}
\usepackage{booktabs}
\usepackage{array}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{caption}

\begin{document}
\begin{table}[!h]
    \captionsetup{font=bf, labelsep=period, singlelinecheck=off}
    \caption{DI detection results}
    
    {\footnotesize \onehalfspacing
    \newcolumntype{W}{>{\raggedright\arraybackslash}X}
    \newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
    \newcolumntype{Z}{>{\centering\arraybackslash}X}
    \begin{tabularx}{\textwidth}{clZZZZZ}
    \toprule
    \multirow{2}{*}{Criterion} & \multirow{2}{*}{Statistic} & Total Period & Period 1 & Period 2 & Period 3 & Period 4\\
    & & (2000--2012) & (2000--2002) & (2003--2005) & (2006--2008) & (2009--2012) \\ \otoprule
        Criterion 1 & Threshold  & 360.5 & 601.2 & 601.2 & 601.2 & 601.2 \\
              & Detected (DI) & 32    & 31    & 64    & 31    & 12 \\
              & Simultaneously detected & 18    & 15    & 34    & 6     & 5 \\
              & Prop. (\%)  & 56.3  & 48.4  & 53.1  & 19.4  & 41.7 \\
              &       &       &       &       &       &  \\
        Criterion 2 & Threshold  & 307.4 & 514.0 & 514.0 & 514.0 & 514.0 \\
              & Detected (DI) & 37    & 39    & 68    & 32    & 15 \\
              & Simultaneously detected & 21    & 16    & 35    & 7     & 5 \\
              & Prop. (\%)  & 56.8  & 41.0  & 51.5  & 21.9  & 33.3 \\
              &       &       &       &       &       &  \\
        Criterion 3 & Threshold  & 261.7 & 438.9 & 438.9 & 438.9 & 438.9 \\
              & Detected (DI) & 47    & 46    & 74    & 39    & 20 \\
              & Simultaneously detected & 26    & 20    & 38    & 11    & 5 \\
              & Prop. (\%)  & 55.3  & 43.5  & 51.4  & 28.2  & 25.0 \\
        \bottomrule
        \end{tabularx}}
    \end{table}

\end{document}

输出:

enter image description here

但是我不喜欢“总时期”等列标题及其下方年份的外观。我希望能够将“总时期”全部放在一行中,并将年份(例如 2000-2012)放在一行中,而不是分成两行。我该怎么做?

答案1

在这种情况下,您似乎有几种选择:

  • 要么resizebox使用graphicx包装,这可能会导致您的桌子看起来有点拉伸或挤压;
  • 扩大该特定页面的边距table- 这是我选择的选项。

我已经使用adjustwidthchangepage包生成下表:

screenshot

考虑到你有带小数的数字,我认为也许值得考虑siunitx包来帮助对齐——这是此类实现的输出。

siunitx option

为了您的方便,这里提供了这两个选项的完整代码。

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage{caption}
%\usepackage{showframe}
\usepackage{changepage}
\newcolumntype{W}{>{\raggedright\arraybackslash}X}
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\newcolumntype{Z}{>{\centering\arraybackslash}X}

\begin{document}
\begin{table}[!h]
  \begin{adjustwidth}{-2cm}{-2cm}
    \captionsetup{font=bf, labelsep=period, singlelinecheck=off}
    \caption{DI detection results}

    {\footnotesize
      \begin{tabularx}{\linewidth}{clZZZZZ}
        \toprule
        \multirow{2}{*}{Criterion} & \multirow{2}{*}{Statistic} & \mbox{Total Period} & Period 1     & Period 2     & Period 3     & Period 4     \\
                                   &                            & (2000--2012)        & (2000--2002) & (2003--2005) & (2006--2008) & (2009--2012) \\ \toprule
        Criterion 1                & Threshold                  & 360.5               & 601.2        & 601.2        & 601.2        & 601.2        \\
                                   & Detected (DI)              & 32                  & 31           & 64           & 31           & 12           \\
                                   & Simultaneously detected    & 18                  & 15           & 34           & 6            & 5            \\
                                   & Prop. (\%)                 & 56.3                & 48.4         & 53.1         & 19.4         & 41.7         \\
                                   &                            &                     &              &              &              &              \\
        Criterion 2                & Threshold                  & 307.4               & 514.0        & 514.0        & 514.0        & 514.0        \\
                                   & Detected (DI)              & 37                  & 39           & 68           & 32           & 15           \\
                                   & Simultaneously detected    & 21                  & 16           & 35           & 7            & 5            \\
                                   & Prop. (\%)                 & 56.8                & 41.0         & 51.5         & 21.9         & 33.3         \\
                                   &                            &                     &              &              &              &              \\
        Criterion 3                & Threshold                  & 261.7               & 438.9        & 438.9        & 438.9        & 438.9        \\
                                   & Detected (DI)              & 47                  & 46           & 74           & 39           & 20           \\
                                   & Simultaneously detected    & 26                  & 20           & 38           & 11           & 5            \\
                                   & Prop. (\%)                 & 55.3                & 43.5         & 51.4         & 28.2         & 25.0         \\
        \bottomrule
      \end{tabularx}}
  \end{adjustwidth}
\end{table}

\begin{table}[!h]
  \begin{adjustwidth}{-2cm}{-2cm}
    \captionsetup{font=bf, labelsep=period, singlelinecheck=off}
    \caption{DI detection results}

    {\footnotesize
      \begin{tabularx}{\linewidth}{clS[table-format=3.1]S[table-format=3.1]S[table-format=3.1]S[table-format=3.1]S[table-format=3.1]}
        \toprule
        \multirow{2}{*}{Criterion} & \multirow{2}{*}{Statistic} & {\mbox{Total Period}} & {Period 1}     & {Period 2}     & {Period 3}     & {Period 4}     \\
                                   &                            & {(2000--2012)}        & {(2000--2002)} & {(2003--2005)} & {(2006--2008)} & {(2009--2012)} \\
        \midrule
        Criterion 1                & Threshold                  & 360.5                 & 601.2          & 601.2          & 601.2          & 601.2          \\
                                   & Detected (DI)              & 32                    & 31             & 64             & 31             & 12             \\
                                   & Simultaneously detected    & 18                    & 15             & 34             & 6              & 5              \\
                                   & Prop. (\%)                 & 56.3                  & 48.4           & 53.1           & 19.4           & 41.7           \\
                                   &                            &                       &                &                &                &                \\
        Criterion 2                & Threshold                  & 307.4                 & 514.0          & 514.0          & 514.0          & 514.0          \\
                                   & Detected (DI)              & 37                    & 39             & 68             & 32             & 15             \\
                                   & Simultaneously detected    & 21                    & 16             & 35             & 7              & 5              \\
                                   & Prop. (\%)                 & 56.8                  & 41.0           & 51.5           & 21.9           & 33.3           \\
                                   &                            &                       &                &                &                &                \\
        Criterion 3                & Threshold                  & 261.7                 & 438.9          & 438.9          & 438.9          & 438.9          \\
                                   & Detected (DI)              & 47                    & 46             & 74             & 39             & 20             \\
                                   & Simultaneously detected    & 26                    & 20             & 38             & 11             & 5              \\
                                   & Prop. (\%)                 & 55.3                  & 43.5           & 51.4           & 28.2           & 25.0           \\
        \bottomrule
      \end{tabularx}}
  \end{adjustwidth}
\end{table}

\end{document}

相关内容