3

I am struggling with line breaks and horizontal and vertical centering in my tables. I am trying to get an automatic line break for "Synthetic Control Group Sample A" in Table 1 and for "Logarithm consumer price index" in Table 2 (please see MWE below). I also want to center my rows vertically in case that there is a line break. Do you have any suggestions how I can get automatic line breaks for long expressions so that it looks better? And do you have any ideas how I can center single rows vertically? Please find my code below. Thank you very much in advance for your time and your help!

enter image description here

\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabulary}
\usepackage{multirow}
\usepackage{dcolumn}
\usepackage{tabularht}
\begin{document}
\begin{table}[h]
  \centering{
  \caption{Composition of Synthetic Control Groups}
  }
\begin{tabular}{rrlr}
  \toprule
  \multicolumn{2}{p{14.925em}}{\textbf{Synthetic Control Group Sample A}} & \multicolumn{2}{p{14.925em}}{\textbf{Synthetic Control Group Sample B}} \\
  \midrule
  \midrule
  \multicolumn{1}{l}{\textbf{State}} & \multicolumn{1}{l}{\textbf{Percent}} & \textbf{State} & \multicolumn{1}{l}{\textbf{Percent}} \\
  \midrule
  \multicolumn{1}{l}{A} & 53.0\% & A & 9.5\% \\
  \multicolumn{1}{l}{B} & 12.2\% & B & 19.7\% \\
  \multicolumn{1}{l}{C} & 34.8\% & C & 5.8\% \\
        &       & D & 58.7\% \\
        &       & E & 6.2\% \\
  \bottomrule
  \end{tabular}%
\end{table}

\begin{table}[h]
  \centering{
      \caption{Descriptive Statistics}
  }
\begin{tabular}{lrrrrrr}
  \toprule
  \textbf{Variables} & \multicolumn{1}{c}{\textbf{N}} & \multicolumn{1}{c}{\textbf{Mean}} & \multicolumn{1}{c}{\textbf{Median}} & \multicolumn{1}{c}{\textbf{Std. Dev.}} & \multicolumn{1}{c}{\textbf{Min}} & \multicolumn{1}{c}{\textbf{Max}} \\
  \midrule
  \midrule
  Logarithm debt pc & 90    & 8.584028 & 8.779948 & 0.6039792 & 6.947824 & 9.336767 \\
  Logarithm GDP pc & 90    & 10.03278 & 10.15797 & 0.6830409 & 7.906916 & 10.77783 \\
  Unemployment rate & 90    & 0.0883556 & 0.077 & 0.0484822 & 0.029 & 0.204 \\
  Logarithm consumer price index & 90    & 4.549728 & 4.555454 & 0.0623881 & 4.430817 & 4.646312 \\
  \bottomrule
  \end{tabular}%
\end{table}
\end{document}

1
  • @Zarko I have adjusted my tables according to your advice. I am now struggling a bit with the column widths since I have some variables which are way bigger and range to nearly 400,000. For variables with high values the value itself is overwritten since column width is not wide enough. Do you have an idea how I can solve this? Thank you very much in advance for your help!
    – Ferdi
    May 30, 2022 at 17:14

2 Answers 2

4

Welcome to TeX.SE!

With tabularray package is simple:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\usepackage[skip=0.33\baselineskip]{caption}

\begin{document}
\begin{table}[ht]
    \centering
    \caption{Composition of Synthetic Control Groups}
\sisetup{table-format=2.1{\%}}
\begin{tblr}{width=0.7\linewidth, 
             colspec = {X[c] X[c, si] X[c] X[c, si]},
            row{1,2} = {font=\bfseries},
            hspan = minimal
              }
    \toprule
\SetCell[c=2]{c}    Synthetic Control Group Sample A
    &           &   \SetCell[c=2]{c}    Synthetic Control Group Sample B
                            &           \\
  \midrule
State   & {{{Percent}}}   
                & State & {{{Percent}}} \\
  \midrule
A   & 53.0\,\%  & A     &  9.5\,\%  \\
B   & 12.2\,\%  & B     & 19.7\,\%  \\
C   & 34.8\,\%  & C     &  5.8\,\%  \\
    &           & D     & 58.7\,\%  \\
    &           & E     &  6.2\,\%  \\
  \bottomrule
  \end{tblr}%
\end{table}

\begin{table}[ht]
    \centering 
    \caption{Descriptive Statistics}
\sisetup{round-mode=places,
         round-precision=4,
         table-format=2.4}
\begin{tblr}{colsep=4pt,
             colspec = {@{} X[2,l,m] c *{5}{X[0.8, c, si]} @{}},
              row{1} = {font=\bfseries, m},
              }
    \toprule
Variables   & N     & {{{Mean}}}    & {{{Median}}} & {{{Std. Dev.}}} 
                    & {{{Min}}}     & {{{Max}}}     \\
    \midrule
Logarithm debt pc 
            & 90    & 8.584028      & 8.779948      & 0.6039792 
                    & 6.947824      & 9.336767      \\
Logarithm GDP pc 
            & 90    & 10.03278      & 10.15797      & 0.6830409 
                    & 7.906916      & 10.77783      \\
Unemployment rate 
            & 90    & 0.0883556     & 0.077         & 0.0484822 
                    & 0.029         & 0.204         \\
Logarithm consumer price index 
            & 90    & 4.549728      & 4.555454      & 0.0623881 
                    & 4.430817      & 4.646312      \\
    \bottomrule
    \end{tblr} 
\end{table}
\end{document}

enter image description here

Since the second table is quite wide, and to have different number of decimal, the numbers are rounded to 5 decimals. Doing this table is nicely fit on the page.

3
  • Thanks you guys very much for your time and your help!! :)
    – Ferdi
    May 29, 2022 at 16:46
  • @Ferdi, you are welcome. BTW, policy of this site is, that you express your thankfulness by voting of equations and on the end this accept the one , which on the best way solve your problem (by clicking on the check markt at top of the left side of answer) :-). As I see, so far you not accept none from received answers (for accepting you will be rewarded with two pints of reputation).
    – Zarko
    May 29, 2022 at 16:53
  • I have adjusted my tables according to your advice. I am now struggling a bit with the column widths since I have some variables which are way bigger and range to nearly 400,000. Do you have an idea how I can solve this? Thank you very much in advance for your help! ![enter image description here](i.stack.imgur.com/VD3oP.png)
    – Ferdi
    May 30, 2022 at 7:44
3

I would take different approaches to fixing the layouts of the tables.

  • For table 1, I'd fix the header by removing redundant material, so that the first header line just says "Sample A" and "Sample B". I would also enclose the \caption directive and tabular environment in a threeparttable environment, so that the width of the caption doesn't exceed the width of the table itself.

  • For table 2, the main challenge is to make the table fit inside the textblock. I can see no useful purpose being served by showing 6 or 7 decimal digits. By employing the machinery of the siunitx package and its S column type, the numbers can be rounded automatically to 3 decimal digits. I would also make the first column less wide by replacing "consumer price index" with "CPI".

  • For both tables, I would not embolden the material in the header rows.

enter image description here

2
  • 1
    +1! I wonder why people from Economic Sciences (to be honets, many from other doing the same) in descriptive statistic use different number of decimals. Anyway, I allowed to myself to round OP numbers to 5 decimals and than have problems with fitting table on page :-(
    – Zarko
    May 29, 2022 at 8:44
  • @Zarko - Thanks! There's definitely nothing necessarily "optimal" about showing exactly 3 decimal digits. Actually, in my experience, nothing useful is achieved in general by showing more than 3 decimal digits...
    – Mico
    May 29, 2022 at 8:50

You must log in to answer this question.

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