1

I am trying to put some text in the middle of a horizontal line that only spans a part of the table. Below is my table so far

\documentclass{article}
\usepackage{amssymb, amsmath, bm}
\usepackage[flushleft]{threeparttable}

\begin{document}

\begin{table}[H]
\caption{\textbf{Filtered errors}}
\label{table:summary_statistics}
\begin{threeparttable}
\footnotesize
\renewcommand{\TPTminimum}{\linewidth}
\makebox[\linewidth]{%
\begin{tabular}{lccccccccc}
\toprule
\hline 
& DNS &  &  & MS-DNS &  &  & MS-DRA \\ \cline{2-3} \cline{5-6} \cline{8-9}
\thead{Maturity \\} & \thead[l]{Mean \\ }   & \thead{Std. dev. \\ } &  & 
\thead[l]{Mean \\ }   & \thead{Std. dev. \\ } &  &  \thead[l]{Mean \\ }   & 
\thead{Std. dev. \\ } \\
\midrule
3      & 3.285 & 2.573 & & 0.000 & 9.230 & & 0.993 & 0.845 \\
6      & 3.432 & 2.613 & & 0.030 & 9.540 & & 0.993 & 0.850 \\
12     & 3.617 & 2.635 & & 0.099 & 9.658 & & 0.993 & 0.863 \\
24     & 3.874 & 2.611 & & 0.188 & 9.566 & & 0.991 & 0.877 \\
36     & 4.108 & 2.543 & & 0.306 & 9.459 & & 0.990 & 0.885 \\
60     & 4.511 & 2.398 & & 0.627 & 9.317 & & 0.988 & 0.891 \\
84     & 4.837 & 2.285 & & 1.007 & 9.406 & & 0.987 & 0.892 \\
120    & 5.195 & 2.174 & & 1.498 & 9.642 & & 0.986 & 0.890 \\
Median & 1.910 & 1.205 & & -0.616& 4.376 & & 0.966 & 0.442 \\
Mean   & -0.731& 0.900 & & -2.691& 1.634 & & 0.949 & 0.596 \\      
#Lower \\ 
\bottomrule
\end{tabular}
}
\begin{tablenotes}\footnotesize
 \item Note: This table reports \par 
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

I also put a screenshot of the table below.

enter image description here

How do I get the text, e.g. DNS/MS-DNS/MS-DRA in the middle of the line instead of at the left side?

Thank you in advance.

1
  • Off-topic: The \caption and \label directives should occur after \begin{threepartable}.
    – Mico
    May 26, 2019 at 15:22

3 Answers 3

4

The \thead machinery seems like overkill for the table at hand. In its place, I suggest use \multicolumn{2}{c}{...} directives for the centered header cells, along with \cmidrule instead of \cline.

I would also recommend aligning the numbers on their respective decimal markers and typesetting them in math mode, so that typographically appropriate math-minus symbols rather than text-mode dashes get employed for the negative numbers.

However, please don't employ \footnotesize for the main table unless you want to deliberately annoy your readers.

enter image description here

\documentclass{article}
\usepackage{siunitx, booktabs, lipsum}
\usepackage[flushleft]{threeparttable}

\begin{document}

\begin{table}
\centering
\begin{threeparttable}
\caption{\textbf{Filtered errors}}
\label{table:summary_statistics}
%\footnotesize
%%\renewcommand{\TPTminimum}{\linewidth}

\begin{tabular}{@{} l *{6}{S[table-format=1.3]} @{}}
\toprule
& \multicolumn{2}{c}{DNS} 
& \multicolumn{2}{c}{MS-DNS} 
& \multicolumn{2}{c@{}}{MS-DRA} \\ 
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-7}
Maturity & {Mean} & {Std.\ dev.} 
         & {Mean} & {Std.\ dev.}
         & {Mean} & {Std.\ dev.} \\
\midrule
3      & 3.285 & 2.573 & 0.000 & 9.230 & 0.993 & 0.845 \\
6      & 3.432 & 2.613 & 0.030 & 9.540 & 0.993 & 0.850 \\
12     & 3.617 & 2.635 & 0.099 & 9.658 & 0.993 & 0.863 \\
24     & 3.874 & 2.611 & 0.188 & 9.566 & 0.991 & 0.877 \\
36     & 4.108 & 2.543 & 0.306 & 9.459 & 0.990 & 0.885 \\
60     & 4.511 & 2.398 & 0.627 & 9.317 & 0.988 & 0.891 \\
84     & 4.837 & 2.285 & 1.007 & 9.406 & 0.987 & 0.892 \\
120    & 5.195 & 2.174 & 1.498 & 9.642 & 0.986 & 0.890 \\
\addlinespace
Median & 1.910 & 1.205 & -0.616& 4.376 & 0.966 & 0.442 \\
Mean   & -0.731& 0.900 & -2.691& 1.634 & 0.949 & 0.596 \\
Lower \\
\bottomrule
\end{tabular}

\smallskip
\begin{tablenotes}
\footnotesize
 \item[]Note: \lipsum*[2]
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}
2

Here it is. I improved the layout with siunitx, booktabs, tabularx and caption. As @Mico suggested in his comments, \footnotesize is not necessary for the table to fit between margins, and \caption should be coded form within the threeparttable environment.

\documentclass{article}
\usepackage{amssymb, amsmath, bm}
\usepackage[flushleft]{threeparttable}
\usepackage{float, booktabs, makecell, caption, tabularx}
\usepackage{siunitx}

\begin{document}

\begin{table}%[H]
\begin{threeparttable}
\caption{\textbf{Filtered errors}}
\label{table:summary_statistics}
\sisetup{table-format=-1.3, table-number-alignment=center}
\renewcommand{\theadalign}{lc}
\renewcommand{\TPTminimum}{\linewidth}
\begin{tabularx}{\linewidth}{X*{2}{SSc}SS}
\toprule
\midrule[0.3pt]
& \multicolumn{2}{c}{DNS} & & \multicolumn{2}{c}{MS-DNS} & & \multicolumn{2}{c}{MS-DRA} \\
\cmidrule(lr){2-3} \cmidrule{5-6} \cmidrule{8-9}
\thead{Maturity \\} & {\thead[l]{Mean \\ }} & {\thead{Std. dev. \\ }} & &
{\thead[l]{Mean \\ }} & {\thead{Std. dev. \\ }} & & {\thead[l]{Mean \\ }} &
{\thead{Std. dev. \\ }} \\
\midrule
3 & 3.285 & 2.573 & & 0.000 & 9.230 & & 0.993 & 0.845 \\
6 & 3.432 & 2.613 & & 0.030 & 9.540 & & 0.993 & 0.850 \\
12 & 3.617 & 2.635 & & 0.099 & 9.658 & & 0.993 & 0.863 \\
24 & 3.874 & 2.611 & & 0.188 & 9.566 & & 0.991 & 0.877 \\
36 & 4.108 & 2.543 & & 0.306 & 9.459 & & 0.990 & 0.885 \\
60 & 4.511 & 2.398 & & 0.627 & 9.317 & & 0.988 & 0.891 \\
84 & 4.837 & 2.285 & & 1.007 & 9.406 & & 0.987 & 0.892 \\
120 & 5.195 & 2.174 & & 1.498 & 9.642 & & 0.986 & 0.890 \\
Median & 1.910 & 1.205 & & -0.616& 4.376 & & 0.966 & 0.442 \\
Mean & -0.731& 0.900 & & -2.691& 1.634 & & 0.949 & 0.596 \\
\#Lower \\
\bottomrule
\end{tabularx}
\begin{tablenotes}\footnotesize
 \item Note: This table reports \par
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document} 

enter image description here

2
  • @Mico: actually, I don't think so. It was in the O.P.'s code and I left it. I mainly wanted to avoid his makebox[\linewidth] for the tabular environment.
    – Bernard
    May 26, 2019 at 15:58
  • @Mico: You're right. I hadn't even noticed this problem, as I focused on the others. I've updated accordingly. Thanks for your most useful comments.
    – Bernard
    May 26, 2019 at 17:40
0
\documentclass{article}
\usepackage{booktabs}
\usepackage[flushleft]{threeparttable}

\begin{document}

\newcommand{\MC}[1]{\multicolumn{2}{@{}c@{}}{#1}}

\begin{table}[htb]
\begin{threeparttable}
\caption{\textbf{Filtered errors}}
\label{table:summary_statistics}
\footnotesize
\renewcommand{\TPTminimum}{\linewidth}
\begin{tabular}{@{}l*8{c}@{}}
\toprule
       & \MC{DNS} &  & \MC{MS-DNS} & & \MC{MS-DRA} \\ \cmidrule{2-3} \cmidrule{5-6} \cmidrule{8-9}
Maturity & Mean & Std. dev. &  & Mean & Std. dev. &  & Mean & Std. dev. \\
\midrule
3      & 3.285 & 2.573 & & 0.000 & 9.230 & & 0.993 & 0.845 \\
6      & 3.432 & 2.613 & & 0.030 & 9.540 & & 0.993 & 0.850 \\
12     & 3.617 & 2.635 & & 0.099 & 9.658 & & 0.993 & 0.863 \\
24     & 3.874 & 2.611 & & 0.188 & 9.566 & & 0.991 & 0.877 \\
36     & 4.108 & 2.543 & & 0.306 & 9.459 & & 0.990 & 0.885 \\
60     & 4.511 & 2.398 & & 0.627 & 9.317 & & 0.988 & 0.891 \\
84     & 4.837 & 2.285 & & 1.007 & 9.406 & & 0.987 & 0.892 \\
120    & 5.195 & 2.174 & & 1.498 & 9.642 & & 0.986 & 0.890 \\
Median & 1.910 & 1.205 & & -0.616& 4.376 & & 0.966 & 0.442 \\
Mean   & -0.731& 0.900 & & -2.691& 1.634 & & 0.949 & 0.596 \\      
Lower  &       &       & &       &       & &       &       \\ 
\bottomrule
\end{tabular}
\begin{tablenotes}\footnotesize
 \item Note: This table reports \par 
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

enter image description here

You must log in to answer this question.

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