1

I am currently experiencing some formatting issues with my table. I have conducted two separate regression analyses and now I would like to include them in one table since all the regression coefficients are the same. One table looks like this:

\documentclass[paper=a4, pagesize, fontsize=11pt]{scrartcl} 
\usepackage{pdfpages}
  \usepackage[utf8]{inputenc}  
  \usepackage[T1]{fontenc}       
  \usepackage[ngerman]{babel}   
\usepackage{rotating,threeparttable,siunitx,tabularx,ragged2e,booktabs}
\newcolumntype{L}{>{\RaggedRight}X} 

\begin{document}


    \begin{sidewaystable}
        \small %\footnotesize
        \begin{threeparttable}[H]
            \caption{Regressionstabelle -- Modell 1} 
            \label{tab:reg1} 
            %%\setlength{\tabcolsep}{5.5pt} % default: 6pt
            \sisetup{table-format=-1.2} % set default format
            \begin{tabularx}{\textheight}{@{} 
                    L 
                    S
                    S[table-format=1.2]
                    %>{\lbr}S[table-space-text-pre=\lbr]
                    %@{,\,} % comma rather than whitespace as column separator
                    S%[table-format=<.4, add-integer-zero=false]
                    S[table-format=<.4, add-integer-zero=false]
                    S[table-format=1.2]
                    S[table-format=<.4, add-integer-zero=false]
                    S[table-format=<.4, add-integer-zero=false] @{}} 

                \toprule
                & \multicolumn{5}{c}{}  \\
                %   \cmidrule(lr){2-6} \cmidrule(lr){7-7} %\cmidrule(l){8-9}
                Latente Konstrukte & {$B$} & {SE} & {$z$}& {$p$}&$\gamma$  \\ 
                \midrule
                \emph{ Vitalität}&&&&&\\
                Extraversion      & 0.32  & 0.22  & 1.48 & 0.14   & 0.16\\
                Verträglichkeit   & 0.36  &0.23   &1.54  &0.12    &0.18\\
                Gewissenhaftigkeit&0.18   &0.23   &0.78  &0.44    &0.10\\
                Neurotizismus     &1.32   &0.24   &5.53  & < .001 &0.99\\
                Offenheit         &-1.33  &1.42  &-0.94  &0.35    &-0.13\\  
                \addlinespace
                \emph{ Psychisches Wohlbefinden}&&&&&\\
                Extraversion  &0.19   & 0.17   & 1.09    & 0.28     & 0.13\\
                Verträglichkeit   &0.34   &0.19   &1.77    &0.08     &0.24\\
                Gewissenhaftigkeit&0.57   &0.20  &2.80   &0.01   &0.47\\
                Neurotizismus     &1.26   &0.23  &5.45   &< .001 &1.36\\
                Offenheit         &-1.19  &1.21  &-0.98  &0.33   &-0.17\\ 
                \addlinespace
                \emph{Allgemeine Gesundheitswahrnehmung}&&&&&\\ 
                Extraversion      & 0.28 & 0.17 & 1.64 & 0.10 & 0.19\\
                Verträglichkeit   & 0.40 &0.19 &2.11     &0.04  &0.27\\
                Gewissenhaftigkeit&0.13   &0.18  &0.71   &0.48  &0.10\\
                Neurotizismus     &0.91   &0.20  &4.45   &<.001 &0.93\\
                Offenheit         &-0.63  &0.90  &-0.71  &0.48  &-0.08\\ 
                \bottomrule 
            \end{tabularx} 

            \smallskip\scriptsize
            \begin{tablenotes}
                \item[\phantom{*}$*$] Modell 1: Schiefwinkeliges Modell unter Einschluss der Subskalen \emph{Schmerz} und \emph{Soziale Funktionsfähigkeit}  
                \item[$**$] Modell 2: Orthogonales Modell unter Ausschluss der Subskalen \emph{Schmerz} und \emph{Soziale Funktionsfähigkeit} 
            \end{tablenotes}

        \end{threeparttable}
    \end{sidewaystable}  

\end{document}

Regression table

Is there a way how I can move the columns where it says (B, SE, p, z etc. ) more to the left, so that I have enough space left to add those columns one more time for the results of the second regression analysis. Also, I would need to make one horizontal line above the first B, SE etc. columns and a second one for the next few columns so that I can write Regression 1 above the first horizontal line and regression 2 above the second one. Do you know what I mean? :=)

I hope that someone of you will be able to help me. Thanks already very much in advance.

All the best, Helena

Mico
  • 506,678
Milkovena
  • 121
  • please fix your example so that people can try it and test answers. ! LaTeX Error: Environment sidewaystable undefined. – David Carlisle May 24 '20 at 19:00
  • And how is the L column type defined? – Bernard May 24 '20 at 19:10
  • A bunch of packages are missing in order to make this example code compilable. You will need at least booktabs, tbaularx, siunitx, rotating and threeparttablex. From the screenshot I would also guess that the L type column is defined as follows: \newcolumntype{L}{>{\raggedright\arraybackslash}X} is that correct? – leandriis May 24 '20 at 19:27
  • If I am correct and your L type column is a variant of the X type columns, you can simply add more columns and the first column's width will adapt automatically. (That's the whole purpose of the X type column and tabularx). For the two horizontal lines, you can use \cmidrule. Probable \cmidrule(r){2-6} \cmidrule(l){7-11} does what you want. Please also take a look at the table-format option of the S type columns and match them to the contents of the corresponding columns. (Currently your code results in a bunch of overfull box warnings that can be eliminated that way.) – leandriis May 24 '20 at 19:47
  • 1
    Lastly, and entirely depending on the amount of columns you want to add as well as on the width of their contents, you might even be able to fit the whole table onto a portrait oriented page. – leandriis May 24 '20 at 19:48
  • @leandriis - Your intuition about the table fitting fine in portrait mode is spot-on! – Mico May 24 '20 at 19:59

2 Answers2

2

As long as you permit a line break in the first column (see below for a specific implementation), ordinary table and tabular environments will do just fine -- no need for sidewaystable and tabularx -- for the code you've shown so far.

enter image description here

\documentclass[paper=a4, pagesize, fontsize=11pt]{scrartcl} 
%% new instructions:
\usepackage{threeparttable,siunitx,ragged2e,booktabs}
\newcolumntype{P}[1]{>{\RaggedRight\hangafter1\hangindent1em}p{#1}} % automatic hanging indentation
\renewcommand\TPTtagStyle{\textit} % italic for table footnote markers
\newlength\mylen  

  \usepackage[utf8]{inputenc}  
  \usepackage[T1]{fontenc}       
  \usepackage[ngerman]{babel}  

\begin{document}
\begin{table}[htbp]
    \centering
    \settowidth\mylen{\emph{Psychisches Wohlbefinden}} % determine width of first column
    \begin{threeparttable}
    \caption{Regressionstabelle -- Modell 1\tnote{$*$}} 
    \label{tab:reg1} 

    \sisetup{table-format=-1.2} % set default format
    \begin{tabular}{@{} 
            P{\mylen} 
            S
            S[table-format=1.2]
            S
            S[table-format=1.2]
            S
            @{}} 
         \toprule
         Latente Konstrukte & {$B$} & {SE} & {$z$} & {$p$} & {$\gamma$}  \\ 
         \midrule
         \emph{Vitalität}\\
         Extraversion      & 0.32  &0.22  & 1.48  &0.14    & 0.16\\
         Verträglichkeit   & 0.36  &0.23  & 1.54  &0.12    & 0.18\\
         Gewissenhaftigkeit& 0.18  &0.23  & 0.78  &0.44    & 0.10\\
         Neurotizismus     & 1.32  &0.24  & 5.53  &{--\tnote{a}}  & 0.99\\
         Offenheit         &-1.33  &1.42  &-0.94  &0.35    &-0.13\\  
         \addlinespace
         \emph{Psychisches Wohlbefinden}\\
         Extraversion      & 0.19   & 0.17  & 1.09   & 0.28  & 0.13\\
         Verträglichkeit   & 0.34   & 0.19  & 1.77   & 0.08  & 0.24\\
         Gewissenhaftigkeit& 0.57   & 0.20  & 2.80   & 0.01  & 0.47\\
         Neurotizismus     & 1.26   & 0.23  & 5.45   &{--\tnote{a}} & 1.36\\
         Offenheit         &-1.19   & 1.21  &-0.98   & 0.33  &-0.17\\ 
         \addlinespace
         \emph{Allgemeine Gesundheits\-wahrnehmung}\\ 
         Extraversion      & 0.28 & 0.17 & 1.64 & 0.10 & 0.19\\
         Verträglichkeit   & 0.40 &0.19 &2.11     &0.04  &0.27\\
         Gewissenhaftigkeit&0.13   &0.18  &0.71   &0.48  &0.10\\
         Neurotizismus     &0.91   &0.20  &4.45   &{--\tnote{a}} &0.93\\
         Offenheit         &-0.63  &0.90  &-0.71  &0.48  &-0.08\\ 
         \bottomrule 
    \end{tabular} 

    \smallskip\footnotesize\RaggedRight
    \begin{tablenotes}[flushleft]
    \item[$*$] Modell 1: Schiefwinkliges Modell unter Einschluss 
          der Subskalen \emph{Schmerz} und \emph{Soziale Funktionsfähigkeit}  
    \item[$**$] Modell 2: Orthogonales Modell unter Ausschluss der Subskalen 
          \emph{Schmerz} und \emph{Soziale Funktionsfähigkeit} 
    \item[a] $p<0.001$
    \end{tablenotes}
    \end{threeparttable}
\end{table}  

\end{document}

Addendum: Assuming the second model would also contribute 5 columns, it's still possible to typeset the entire table in portrait mode unless the document's margins are unusually wide. The following suggested setup employs a tabular* environment to assure that all 11 columns will fit.

enter image description here

\documentclass[paper=a4, pagesize, fontsize=11pt]{scrartcl} 
\usepackage{threeparttable,siunitx,ragged2e,booktabs}
\newcolumntype{P}[1]{>{\RaggedRight\hangafter1\hangindent1em}p{#1}}
\renewcommand\TPTtagStyle{\textit}
\newlength\mylen  

  \usepackage[utf8]{inputenc}  
  \usepackage[T1]{fontenc}       
  \usepackage[ngerman]{babel}  

\usepackage[margin=2.5cm]{geometry} % set page parameters suitably
\begin{document}
\begin{table}
    %\small
    \setlength\tabcolsep{0pt}
    \settowidth\mylen{\emph{Psychisches Wohlbefinden}} % determine width of first column
    \begin{threeparttable}
    \caption{Regressionstabelle -- Modelle 1 und 2} 
    \label{tab:reg1} 

    \sisetup{table-format=-1.2} % set default format
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} 
            P{\mylen} 
            S S[table-format=1.2] S S[table-format=1.2] S
            S S[table-format=1.2] S S[table-format=1.2] S
            } 
         \toprule
         Latente Konstrukte 
         & \multicolumn{5}{c}{Modell 1\tnote{$*$}} 
         & \multicolumn{5}{c}{Modell 2\tnote{$**$}} \\
         \cmidrule(lr){2-6} \cmidrule(l){7-11}
         & {$B$} & {SE} & {$z$} & {$p$} & {$\gamma$} 
         & {$B$} & {SE} & {$z$} & {$p$} & {$\gamma$}  \\ 
         \midrule
         \emph{Vitalität}\\
         Extraversion      
           & 0.32  &0.22  & 1.48  &0.14    & 0.16
           & 0.32  &0.22  & 1.48  &0.14    & 0.16 \\
         Verträglichkeit   
           & 0.36  &0.23  & 1.54  &0.12    & 0.18\\
         Gewissenhaftigkeit
           & 0.18  &0.23  & 0.78  &0.44    & 0.10\\
         Neurotizismus     
           & 1.32  &0.24  & 5.53  &{--\tnote{a}}  & 0.99\\
         Offenheit         
           &-1.33  &1.42  &-0.94  &0.35    &-0.13\\  
         \addlinespace
         \emph{Psychisches Wohlbefinden}\\
         Extraversion      
           & 0.19   & 0.17  & 1.09   & 0.28  & 0.13\\
         Verträglichkeit   
           & 0.34   & 0.19  & 1.77   & 0.08  & 0.24\\
         Gewissenhaftigkeit
           & 0.57   & 0.20  & 2.80   & 0.01  & 0.47\\
         Neurotizismus     
           & 1.26   & 0.23  & 5.45   &{--\tnote{a}} & 1.36\\
         Offenheit         
           &-1.19   & 1.21  &-0.98   & 0.33  &-0.17\\ 
         \addlinespace
         \emph{Allgemeine Gesundheitswahrnehmung}\\ 
         Extraversion      
           & 0.28 & 0.17 & 1.64 & 0.10 & 0.19\\
         Verträglichkeit   
           & 0.40 &0.19 &2.11     &0.04  &0.27\\
         Gewissenhaftigkeit
           &0.13   &0.18  &0.71   &0.48  &0.10\\
         Neurotizismus     
           &0.91   &0.20  &4.45   &{--\tnote{a}} &0.93\\
         Offenheit         
           &-0.63  &0.90  &-0.71  &0.48  &-0.08\\ 
         \bottomrule 
    \end{tabular*} 

    \smallskip\footnotesize\RaggedRight
    \begin{tablenotes}[flushleft]
    \item[$*$] Modell 1: Schiefwinkliges Modell unter Einschluss 
          der Subskalen \emph{Schmerz} und \emph{Soziale Funktionsfähigkeit}  
    \item[$**$] Modell 2: Orthogonales Modell unter Ausschluss der Subskalen 
          \emph{Schmerz} und \emph{Soziale Funktionsfähigkeit} 
    \item[a] $p<0.001$
    \end{tablenotes}
    \end{threeparttable}
\end{table}  

\end{document}
Mico
  • 506,678
1

Based on some assumptions about your table, I would suggest the following MWE:

enter image description here

\documentclass[paper=a4, pagesize, fontsize=11pt]{scrartcl} 
  \usepackage[T1]{fontenc}       
  \usepackage[ngerman]{babel}   
  \usepackage{rotating} 
  \usepackage{threeparttable}
\usepackage{siunitx}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ragged2e}
\newcolumntype{L}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}
\begin{document}

        \small 
        \begin{threeparttable}[H]
            \caption{Regressionstabelle -- Modell 1} 
            \label{tab:reg1} 
            \setlength{\tabcolsep}{0pt}
            \sisetup{table-format=-1.2} % set default format
            \begin{tabular*}{\linewidth}{@{} 
                    l @{\extracolsep{\fill}}
                    *{2}{
                        S
                        S[table-format=1.2]
                        S
                        S[table-format=<.3, add-integer-zero=false]
                        S
                        }
                     @{}} 

                \toprule
                & \multicolumn{5}{c}{Regression 1} & \multicolumn{5}{c}{Regression 2}  \\
                \cmidrule(r){2-6} \cmidrule(l){7-11}
                Latente  Konstrukte & {$B$} & {SE} & {$z$}& {$p$}&$\gamma$ & {$B$} & {SE} & {$z$}& {$p$}&$\gamma$  \\ 
                \midrule
                \multicolumn{5}{@{}l}{\emph{Vitalität}}\\ \midrule
                Extraversion      & 0.32  & 0.22  & 1.48 & 0.14   & 0.16  & 0.32  & 0.22  & 1.48 & 0.14   & 0.16\\
                Verträglichkeit   & 0.36  &0.23   &1.54  &0.12    &0.18\\
                Gewissenhaftigkeit&0.18   &0.23   &0.78  &0.44    &0.10\\
                Neurotizismus     &1.32   &0.24   &5.53  & < .001 &0.99\\
                Offenheit         &-1.33  &1.42  &-0.94  &0.35    &-0.13\\  
                \midrule
                \multicolumn{5}{@{}l}{\emph{Psychisches Wohlbefinden}}\\ \midrule
                Extraversion  &0.19   & 0.17   & 1.09    & 0.28     & 0.13\\
                Verträglichkeit   &0.34   &0.19   &1.77    &0.08     &0.24\\
                Gewissenhaftigkeit&0.57   &0.20  &2.80   &0.01   &0.47\\
                Neurotizismus     &1.26   &0.23  &5.45   &< .001 &1.36\\
                Offenheit         &-1.19  &1.21  &-0.98  &0.33   &-0.17\\ 
                \midrule
                \multicolumn{5}{@{}l}{\emph{Allgemeine Gesundheitswahrnehmung}}\\ \midrule
                Extraversion      & 0.28 & 0.17 & 1.64 & 0.10 & 0.19\\
                Verträglichkeit   & 0.40 &0.19 &2.11     &0.04  &0.27\\
                Gewissenhaftigkeit&0.13   &0.18  &0.71   &0.48  &0.10\\
                Neurotizismus     &0.91   &0.20  &4.45   &<.001 &0.93\\
                Offenheit         &-0.63  &0.90  &-0.71  &0.48  &-0.08\\ 
                \bottomrule 
            \end{tabular*} 

            \begin{tablenotes}
                \item[\phantom{*}$*$] Modell 1: Schiefwinkeliges Modell unter Einschluss der Subskalen \emph{Schmerz} und \emph{Soziale Funktionsfähigkeit}  
                \item[$**$] Modell 2: Orthogonales Modell unter Ausschluss der Subskalen \emph{Schmerz} und \emph{Soziale Funktionsfähigkeit} 
            \end{tablenotes}

        \end{threeparttable}  

\end{document}
leandriis
  • 62,593