2

I have the following table:

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

which outputs:

enter image description here

However I do not like the appearance of column titles such as 'Total Period' and the year beneath it. I'd like to be able to fit "Total Period" all on one row and same with the years, e.g., (2000--2012) on one row rather than split across two. How can I do this?

1 Answer 1

2

In cases like this, it seems like you have a few choices:

  • either use resizebox from the graphicx package, which may result in your table looking a little stretched or squished;
  • extend the margins of the page for that particular table- this is the option that I have chosen.

I have used the adjustwidth environment from the changepage package to produce the following table:

screenshot

Given that you have numbers with decimals, I think it might also be worth considering the siunitx package to help with alignment- here's the output from such an implementation.

siunitx option

Here's the complete code for both options for your convenience.

% 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}
0

You must log in to answer this question.

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