2

I have this code:

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[margin=2.5cm]{geometry}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{caption}
\usepackage{booktabs}
\usepackage[labelfont=bf]{caption}
\usepackage{siunitx}

\begin{document}
\def\arraystretch{1.25}
\begin{table}[]
\centering
\captionof{table}{\textbf{Some Fancy Title to My Table}\\\small{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.}}
\resizebox{\columnwidth}{!}{
\begin{tabular}{llrrrlrlrrrlrlrrrlr}
\toprule
&&
\multicolumn{4}{c}{Parameter 1}&&&
\multicolumn{4}{c}{Parameter 2}&&&
\multicolumn{4}{c}{Parameter 3}\\
\cline{3-6}\cline{9-12}\cline{15-18}&&
\multicolumn{1}{c}{Estimate}&
\multicolumn{1}{c}{$t$--Statistic}&
\multicolumn{1}{c}{$p$--value}&
\multicolumn{1}{c}{$\bar{R}^{2}$}&&&
\multicolumn{1}{c}{Estimate}&
\multicolumn{1}{c}{$t$--Statistic}&
\multicolumn{1}{c}{$p$--value}&
\multicolumn{1}{c}{$\bar{R}^{2}$}&&&
\multicolumn{1}{c}{Estimate}&
\multicolumn{1}{c}{$t$--Statistic}&
\multicolumn{1}{c}{$p$--value}&
\multicolumn{1}{c}{$\bar{R}^{2}$}\\
\hline
Model 1             &&&&&\multicolumn{1}{r}{0.47}   &&&&&&\multicolumn{1}{r}{0.47}  &&&&&&\multicolumn{1}{r}{0.47}&\\
\qquad{}Intercept   &&-0.02 &-1.19  &0.23&      &&&0.14     &6.41   &0.00&***   &&&0.05   &2.69   &0.01&**  &\\
\qquad{}Factor 1        &&0.81  &290.96 &0.00&***   &&&0.81     &290.91 &0.00&***   &&&0.81   &290.83 &0.00&*** &\\
\qquad{}Factor 2      &&0.09  &3.07   &0.00&**    &&&-0.05    &-1.80  &0.07&.     &&&0.03   &0.85   &0.39&    &\\
\qquad{}Factor 3      &&0.23  &7.67   &0.00&***   &&&-0.18    &-6.21  &0.00&***   &&&-0.01  &-0.52  &0.61&    &\\
\bottomrule
\end{tabular}
} % end of resizebox
\end{table}
\end{document}

which produces this table:

table

Is it possible to somehow remove the space between the values in the 'p-value' column and the stars (***) from the 'R^2' column? My problem is that I would like to keep the space between the column headers, and the space between the empty column and the numerical 'R^2' value from the 'Model 1' row.

Said differently, I try to set up my table such that the right most column under the 'Parameter 1' header looks something like this:

0.23

0.00***

0.00**

0.00***

The numerical values (to the left) are right justified, while the stars (to the right) are left justified.

I hope that my question makes sense. I have already looked at multiple questions, such as this.

Thanks in advance!

4

Jeepers, that is one ugly way of doing a table!

There's always more than one way to do it. I'd suggest:

  • Use S from siunitx for the figures.
  • Put the asterisks in the p-value column (braced so as not to confuse siunitx).
  • Get rid of the dreaded resizebox (had you actually worked out how tiny the type was?)
  • Buy ourselves a little extra space by reducing tabcolsep (the labels more or less do the spacing: they are a bit tight but can't be helped: in an ideal world I'd reduce the length of the labels by abbreviating, e.g. "est" and "t-stat" and "p", in which case we might need some more tabcolsep back).
  • Get rid of columns whose only function is spacing, instead putting spacing if we need it in the template (we need rather little).
  • Use trimmed \cmidrules to group the parameters (removing the need for space between them): there's no point loading booktabs then using \cline and \hline.
  • Thereby remove all redundant cells from the data which were only there for spacing and have it line up.
  • Remove the \qquads and use a difference in type style instead to show we are dealing with a particular model.

With all that we are able to remove the resizebox and have the whole thing footnotesize which should be just about legible, and still within the text width. We also have code which actually reflects the table, without a lot of ampersands which are just spacers.

Code as follows (with redundant packages removed).

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[margin=2.5cm]{geometry}
\usepackage{booktabs}
\usepackage[labelfont=bf]{caption}
\usepackage{siunitx}

\begin{document}
\def\arraystretch{1.25}
\setlength{\tabcolsep}{1.5pt}
\begin{table}[]
\centering
\captionof{table}{\textbf{Some Fancy Title to My Table}\\\small{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.}}
\footnotesize
\begin{tabular}{lSSS[table-format=1.2]S@{\hskip 4pt}SSS[table-format=1.2]S@{\hskip 4pt}SSS[table-format=1.2]S}
  \toprule
  &
\multicolumn{4}{c}{Parameter 1}&
\multicolumn{4}{c}{Parameter 2}&
\multicolumn{4}{c}{Parameter 3}\\
%  \cmidrule(r){2-5}\cmidrule(lr){6-9}\cmidrule(l){10-13}
&
\multicolumn{1}{c}{Estimate}&
\multicolumn{1}{c}{$t$--Statistic}&
\multicolumn{1}{c}{$p$--value}&
\multicolumn{1}{c}{$\bar{R}^{2}$}&
\multicolumn{1}{c}{Estimate}&
\multicolumn{1}{c}{$t$--Statistic}&
\multicolumn{1}{c}{$p$--value}&
\multicolumn{1}{c}{$\bar{R}^{2}$}&
\multicolumn{1}{c}{Estimate}&
\multicolumn{1}{c}{$t$--Statistic}&
\multicolumn{1}{c}{$p$--value}&
\multicolumn{1}{c}{$\bar{R}^{2}$}\\
\cmidrule(r){2-5}\cmidrule(r){6-9}\cmidrule{10-13}
\textit{Model 1} &       &        &           & 0.47 &       &        &           & 0.47 &       &        &  & 0.47   \\
Intercept        & -0.02 & -1.19  & 0.23      &      & 0.14  & 6.41   & 0.00{***} &      & 0.05  & 2.69   & 0.01{**}  \\
Factor 1         & 0.81  & 290.96 & 0.00{***} &      & 0.81  & 290.91 & 0.00{***} &      & 0.81  & 290.83 & 0.00{***} \\
Factor 2         & 0.09  & 3.07   & 0.00{**}  &      & -0.05 & -1.80  & 0.07      &      & 0.03  & 0.85   & 0.39      \\
Factor 3         & 0.23  & 7.67   & 0.00{***} &      & -0.18 & -6.21  & 0.00{***} &      & -0.01 & -0.52  & 0.61      \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

  • Thank you for your solution, Mr. @PaulStanley. I know that I still have a lot to learn about best practices regarding table set-up. So pointing out the mistakes/corrections is a great way for me to continue to learn. – Andreas Apr 25 '18 at 8:15
4

I would like to suggest that you reorganize the table to get rid of all empty ("filler"?) columns and place the information about R^2 in a separate row below the top-tier header cells. With these changes in place, it's no longer necessary to \resizebox the tabular material -- making the material just that much more legible to your readers. Finally, I think the readability of the numbers in the (now only 9) numeric columns would benefit from arranging all numbers by the decimal markers.

enter image description here

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[margin=2.5cm]{geometry}
\usepackage{setspace,amssymb,mathtools}
\usepackage{booktabs,siunitx,dcolumn}
\usepackage[font=bf,justification=raggedright,
   singlelinecheck=off,skip=0.333\baselineskip]{caption}
\newcolumntype{d}[1]{D..{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}}

\begin{document}
\begin{table}
%\renewcommand\arraystretch{1.25}

\caption{Some fancy title to my Table}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea 
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit 
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat 
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim 
id est laborum.

\medskip
\centering
\begin{tabular}{@{} l *{3}{d{2.2}d{3.2}d{1.4}} @{}}
\toprule
Model 1 &
\multicolumn{3}{c}{Parameter 1}&
\multicolumn{3}{c}{Parameter 2}&
\multicolumn{3}{c@{}}{Parameter 3}\\
&\multicolumn{3}{c}{($\bar{R}^{2}=0.47$)}
&\multicolumn{3}{c}{($\bar{R}^{2}=0.47$)}
&\multicolumn{3}{c}{($\bar{R}^{2}=0.47$)}\\
\cmidrule(lr){2-4}\cmidrule(lr){5-7}\cmidrule(l){8-10}
&\mc{Coeff.}&\mc{$t$-Stat.}&\mc{$p$-value}
&\mc{Coeff.}&\mc{$t$-Stat.}&\mc{$p$-value}
&\mc{Coeff.}&\mc{$t$-Stat.}&\multicolumn{1}{c@{}}{$p$-value}\\
\midrule
Intercept &-0.02 &-1.19  & 0.23 
          & 0.14 &6.41   & 0.00^{***} 
          & 0.05 &2.69   & 0.01^{**}  \\
Factor 1  & 0.81 &290.96 & 0.00^{***} 
          & 0.81 &290.91 & 0.00^{***}   
          & 0.81 &290.83 & 0.00^{***} \\
Factor 2  & 0.09 &  3.07 & 0.00^{**} 
          &-0.05 & -1.80 & 0.07 
          & 0.03 &  0.85 & 0.39       \\
Factor 3  & 0.23 &  7.67 & 0.00^{***} 
          &-0.18 & -6.21 & 0.00^{***} 
          &-0.01 & -0.52 & 0.61       \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
  • 1
    +1 Many of the same changes I made -- but you were bolder with redesigning the actual structure (which I dare not touch because I'm only a lawyer!) – Paul Stanley Apr 24 '18 at 22:46
  • Thank you, Mr. @Mico. I really like the redesign of the table, which is much more efficient than my own. I will consider changing the layout. – Andreas Apr 25 '18 at 8:21
4

Never use \resizebox with a tabular! It leads to inconsistent font size. Better play with fontsizes and the value of \tabcolsep.

I propose to use tabularx to fit \linewidth, and systematically use the rules from booktabs:

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[margin=2.5cm, showframe]{geometry}
\usepackage{setspace}
\usepackage{amssymb}
\usepackage{mathtools}%% loads amsmath
\usepackage{booktabs, tabularx}
\usepackage[labelfont=bf]{caption}
\usepackage{siunitx}

\begin{document}

\def\arraystretch{1.25}
\begin{table}[!htb]
\centering\footnotesize\setlength{\tabcolsep}{3pt}%
\sisetup{table-number-alignment=center}
\captionof{table}{\textbf{Some Fancy Title to My Table}\\\footnotesize{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.}}

\begin{tabularx}{\linewidth}{X *{3}{S[table-format=1.2]S[table-format=3.2]S[table-format=1.2, table-space-text-post=***]@{\,}c}@{}}
\toprule
& \multicolumn{4}{c}{Parameter 1}& \multicolumn{4}{c}{Parameter 2}& \multicolumn{4}{c}{Parameter 3}\\
\cmidrule(l{2pt}r){2-5}\cmidrule(l{2pt}r){6-9}\cmidrule(l{2pt}r{2pt}){10-13}
 & {Estimate}& {$t$--Statistic}& {$p$--value}& $\bar{R}^{2}$
 & {Estimate}& {$t$--Statistic}& {$p$--value}&{$\bar{R}^{2}$}
 & {Estimate}& {$t$--Statistic}& {$p$--value}& {$\bar{R}^{2}$}\\
\midrule
\multicolumn{1}{@{}l}{Model 1} &{}&&& 0.47 &&&& 0.47 &&&& 0.47 \\[0.5ex]
Intercept & - 0.02 &- 1.19 &0.23& & 0.14 &6.41 &0.00*** &&0.05 &2.69 &0.01** &\\
Factor 1 &0.81 &290.96 &0.00 *** & &0.81 &290.91 & 0.00 *** & &0.81 &290.83 &0.00 *** &\\
Factor 2 &0.09 &3.07 &0.00 ** & &-0.05 &-1.80 &0.07{. }& &0.03 &0.85 &0.39& \\
Factor 3 & 0.23 &7.67 &0.00 *** & &-0.18 &-6.21 &0.00 *** & &-0.01 &-0.52 &0.61& \\
\bottomrule
\end{tabularx}
\end{table}

\end{document} 

enter image description here

  • Thank you again, Mr. @Bernard! I will try to implement the best of all the inputs, I have received on this question. Have a great day. – Andreas Apr 25 '18 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.