2

I've been failing to make a proper table where text width changes and have different sizes.

Here is the table when I use tabulary environment. enter image description here

I want to have the columns have the same size and align properly in each row. It seems the hyphen mess up with the alignment. Also the first column name, model 1 is broken into two lines.

Also in the second section, staring from the hline and then cohort size, the columns break into two lines instead of getting wider to fit the text.

I use the following

\begin{center}
\begin{table*}
\centering  
\begin{tabulary}{\textwidth}{LCCCCCC}  
\hline 
\textbf{} &  \textbf{Model 1}  & \textbf{Model 2} & \textbf{Model 3} & \textbf{Model 4} & \textbf{Model 5} & \textbf{Model 6}  \\ 
\textbf{} & \textit{Baseline}  &   \textit{Human Capital}& \textit{Gender} &  \textit{Social Capital} &    \textit{Symbolic Capital} &    \textit{Human Capital (Ext.)}  
\\  
\hline 
start year        &  0.0(0.0) &     0.0(0.0) &     0.0(0.0) &     0.0(0.0) &     0.0(0.0) &     0.0(0.0) \\[8pt] 
productivity      &           &  $-$0.67(0.01) &  $-$0.67(0.01) &  $-$0.69(0.01) &  $-$0.67(0.01) &  $-$0.67(0.01) \\[8pt] 
recognition       &           &    0.02(0.0) &    0.02(0.0) &    0.01(0.0) &    0.02(0.0) &    0.04(0.0) \\[8pt] 
male              &           &              &   0.05(0.01) &   0.04(0.01) &   0.06(0.01) &   0.05(0.01) \\[8pt] 
female            &           &              &  $-$0.05(0.02) &  $-$0.05(0.01) &  $-$0.06(0.01) &  $-$0.06(0.02) \\[8pt] 
none              &           &              &   0.01(0.02) &   0.01(0.01) &   0.01(0.02) &   0.01(0.02) \\[8pt] 
degree            &           &              &              &    0.03(0.0) &    0.04(0.0) &    0.04(0.0) \\[8pt] 
coauthor hindex   &           &              &              &   $-$0.01(0.0) &    $-$0.0(0.0) &    $-$0.0(0.0) \\[8pt] 
top-venue         &           &              &              &              &  $-$0.33(0.03) &   $-$0.3(0.04) \\[8pt] 
quality           &           &              &              &              &              &    $-$0.0(0.0) \\[8pt] \hline
cohort size       &    292,659 &       292,659 &       292,659 &       292,659 &       292,659 &       292,659 \\[8pt]
\% dropouts        &  0.63 &     0.63 &     0.63 &     0.63 &     0.63 &     0.63 \\[8pt]
F1 &     0.77   &     0.81     &    0.81     &   0.81      &    0.81       &   0.81      \\[8pt]
ROC AUC &     0.48   &     0.75     &    0.75     &   0.75      &    0.76       &   0.76     \\[8pt]
Average precision &      0.62 &         0.78 &         0.79 &         0.79 &          0.8 &         0.81 \\[8pt]\hline 
\end{tabulary}
\caption{\label{tab:my label} my caption}
\end{table*}
    \end{center}

and this is the result when I use \begin{tabularx}{\textwidth}{XXXXXXX} instead. It looks abit better! Plus, in the second section, staring from the hline and then cohort size, columns break into two lines instead of getting wider to fit the text.

enter image description here

I also tried to change the column sizes using %\newcolumntype{x}[1]{>{\raggedleft\hspace{0pt}}p{3}} but it didn't work. Any idea is very appreciated!

UPDATE (temp) After trying out @Zarko solution columns and rows alignment looks fine but the table alignment to the page is not right. The table is not in in the centre of the page and the lines no stretching till the end. I get the error overfull \hbox (68.48..) too wide in alignment in line..

here is document class. enter image description here

UPDATE 2 This the result and code when I use the recommended code

\documentclass[pdftex,a4paper]{scrartcl}

\usepackage{abstract}
\usepackage{color}
\usepackage{comment}
\usepackage[pdftex]{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{natbib}
\usepackage{tabularx}
\usepackage{tabulary}
\usepackage{array}%
\usepackage{relsize}
\usepackage{setspace}
\usepackage{booktabs, makecell}
\usepackage{siunitx}
\newcommand\chead[1]{\multicolumn{2}{c}{\bfseries#1}}
\newcommand\mci[1]{\multicolumn{2}{c}{\itshape\makecell[t]{#1}}}
\newcommand\mcc[1]{\multicolumn{2}{c}{#1}}


%\title{Temporal Changes in Inequality and the Predictability of Success in Science: A Study of 30 Computer Science Cohorts}
\title{test}


\begin{document}

\maketitle

    \begin{table*}
    \centering
    \setlength\tabcolsep{0pt}
    \renewcommand\arraystretch{1.1}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l*{6}{S[table-format=+1.2, table-auto-round]@{}l}}
    \toprule
    & \chead{Model 1}   & \chead{Model 2}   & \chead{Model 3}
    & \chead{Model 4}   & \chead{Model 5}   & \chead{Model 6}               \\
    & \mci{Baseline}    & \mci{Human\\ Capital}
                                            & \mci{Gender}
    & \mci{Social\\ Capital}
                        & \mci{Symbolic\\ Capital}
                                            & \mci{Human\\ Capital\\ (Ext.)}\\
    \midrule
start year
    & 0.0   & (0.0) & 0.0   & (0.0) & 0.0   & (0.0) & 0.0 
    & (0.0) & 0.0   & (0.0) & 0.0   & (0.0)         \\
productivity
    &       &       & -0.67 & (0.01) & -0.67 & (0.01)& -0.69 
    & (0.01)& -0.67 & (0.01)&  -0.67 & (0.01)       \\
recognition
    &       &       & 0.02  & (0.0) & 0.02  & (0.0) & 0.01 
    & (0.0) & 0.02  & (0.0) & 0.04  & (0.0)         \\
    \addlinespace
male
    &       &       &       &       & 0.05  & (0.01)&   0.04 
    & (0.01)& 0.06  & (0.01)& 0.05  & (0.01)        \\
female
    &       &       &       &       & -0.05 & (0.02)&  -0.05 
    & (0.01)& -0.06 & (0.01)& -0.06 & (0.02)        \\
none
    &       &       &       &       & 0.01  & (0.02)& 0.01 
    & (0.01)& 0.01  & (0.02)& 0.01  & (0.02)        \\
    \addlinespace
degree
    &       &       &       &       &       &       & 0.03  
    & (0.0) & 0.04  & (0.0) & 0.04  & (0.0)         \\
coauthor hindex
    &       &       &       &       &       &       & -0.01 
    & (0.0) & -0.0  & (0.0) & -0.0  & (0.0)         \\
top-venue
    &       &       &       &       &       &       & 
    &       & -0.33 & (0.03)& -0.3  & (0.04)        \\
quality
    &       &       &       &       &       &       & 
    &       &       &       & -0.0  & (0.0)         \\
    \midrule
cohort size
    & \mcc{292,659} & \mcc{292,659} & \mcc{292,659} & \mcc{292,659}   
    & \mcc{292,659} & \mcc{292,659}                 \\
\% dropouts
    & 0.63  &       & 0.63  &       & 0.63  &       & 0.63 
    &       & 0.63  &       & 0.63  &               \\
F1  & 0.77  &       & 0.81  &       & 0.81  &       & 0.81  
    &       & 0.81  &       & 0.81  &               \\
ROC AUC
    & 0.48  &       & 0.75  &       & 0.75  &       & 0.75 
    &       & 0.76  &       & 0.76  &               \\
Average precision
    & 0.62  &       & 0.78  &       & 0.79  &       & 0.79 
    &       & 0.8   &       & 0.81  &               \\
    \bottomrule
\end{tabular*}
\caption{My caption}
\label{tab:my label}
    \end{table*}
\end{document}

enter image description here

now the horizontal lines are fine but the column spacing is not again.

5
  • the table* environment should not be inside center I would not use tabulary or tabularx for numeric tables, they are for setting line breaking within a column. Just use a normal tabular and a smaller font size such as \small Commented May 23, 2019 at 20:28
  • You have not right to complain about my solution. It works as shown in answer. If you would provide MWE, a small but complete document with your table that we know which documentclass you use and its page layout, I would be able to accommodate solution to it.
    – Zarko
    Commented May 24, 2019 at 6:35
  • @Zarko I didn't complain about the solution I just asked for more info. but I understand your point. I use IEEE document class. I add it to my question.
    – Moj
    Commented May 24, 2019 at 6:50
  • @Moj, I like to help you, however you not allow me. Please edit your question and extend your code fragment to complete small document. ieee has more document classes and options for them. If you will do this what I ask you, I will be able to accommodate my solution to your document. Sorry, but my crystal bal is broken, so I can't see your document in it, :-(.
    – Zarko
    Commented May 24, 2019 at 7:05
  • @Zarko I updated the answer. The problem changes :/
    – Moj
    Commented May 24, 2019 at 8:01

1 Answer 1

2

edit:

with tabular for table environment, booktabs for horizontal rules, siunitx for align numbers at decimal points in even columns and makecell for columns' headers and with use document class of the your document.

That the table is narrower than the width of the text, I reduced the \tabcolsep to 2pt in font size to \small:

\documentclass[a4paper]{scrartcl}
\usepackage{relsize}
\usepackage{setspace}

\usepackage{booktabs, makecell}
\newcommand\chead[1]{\multicolumn{2}{c}{\bfseries#1}}
\newcommand\mci[1]{\multicolumn{2}{c}{\itshape\makecell[t]{#1}}}
\newcommand\mcc[1]{\multicolumn{2}{c}{#1}}
\usepackage{siunitx}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
    \begin{table}
    \centering
    \small
    \setlength\tabcolsep{2pt}
    \renewcommand\arraystretch{1.1}
\begin{tabular}{@{}
                 l*{6}{S[table-format=+1.2,
                         table-auto-round]@{\,} l}
                @{} }
    \toprule
    & \chead{Model 1}   & \chead{Model 2}   & \chead{Model 3}
    & \chead{Model 4}   & \chead{Model 5}   & \chead{Model 6}               \\
    & \mci{Baseline}    & \mci{Human\\ Capital}
                                            & \mci{Gender}
    & \mci{Social\\ Capital}
                        & \mci{Symbolic\\ Capital}
                                            & \mci{Human\\ Capital\\ (Ext.)}\\
    \midrule
start year
    & 0.0   & (0.0) & 0.0   & (0.0) & 0.0   & (0.0) & 0.0 
    & (0.0) & 0.0   & (0.0) & 0.0   & (0.0)         \\
productivity
    &       &       & -0.67 & (0.01) & -0.67 & (0.01)& -0.69 
    & (0.01)& -0.67 & (0.01)&  -0.67 & (0.01)       \\
recognition
    &       &       & 0.02  & (0.0) & 0.02  & (0.0) & 0.01 
    & (0.0) & 0.02  & (0.0) & 0.04  & (0.0)         \\
    \addlinespace
male
    &       &       &       &       & 0.05  & (0.01)&   0.04 
    & (0.01)& 0.06  & (0.01)& 0.05  & (0.01)        \\
female
    &       &       &       &       & -0.05 & (0.02)&  -0.05 
    & (0.01)& -0.06 & (0.01)& -0.06 & (0.02)        \\
none
    &       &       &       &       & 0.01  & (0.02)& 0.01 
    & (0.01)& 0.01  & (0.02)& 0.01  & (0.02)        \\
    \addlinespace
degree
    &       &       &       &       &       &       & 0.03  
    & (0.0) & 0.04  & (0.0) & 0.04  & (0.0)         \\
coauthor hindex
    &       &       &       &       &       &       & -0.01 
    & (0.0) & -0.0  & (0.0) & -0.0  & (0.0)         \\
top-venue
    &       &       &       &       &       &       & 
    &       & -0.33 & (0.03)& -0.3  & (0.04)        \\
quality
    &       &       &       &       &       &       & 
    &       &       &       & -0.0  & (0.0)         \\
    \midrule
cohort size
    & \mcc{292,659} & \mcc{292,659} & \mcc{292,659} & \mcc{292,659}   
    & \mcc{292,659} & \mcc{292,659}                 \\
\% dropouts
    & 0.63  &       & 0.63  &       & 0.63  &       & 0.63 
    &       & 0.63  &       & 0.63  &               \\
F1  & 0.77  &       & 0.81  &       & 0.81  &       & 0.81  
    &       & 0.81  &       & 0.81  &               \\
ROC AUC
    & 0.48  &       & 0.75  &       & 0.75  &       & 0.75 
    &       & 0.76  &       & 0.76  &               \\
Average precision
    & 0.62  &       & 0.78  &       & 0.79  &       & 0.79 
    &       & 0.8   &       & 0.81  &               \\
    \bottomrule
\end{tabular}
\caption{My caption}
\label{tab:my label}
    \end{table}
\end{document}

enter image description here

(red lines indicate text borders)

4
  • Thanks @Zarko Can you please check my update. Can you please explain what {@{\extracolsep{\fill}}l*{6}{S[table-format=+1.2,table-auto-round]@{}l} @{}} does?
    – Moj
    Commented May 24, 2019 at 6:30
  • @Moj, (i) please consider my comment below your question., (ii) this is table column specification: one l and six S. Space between them is determined by \extracolsep macro.
    – Zarko
    Commented May 24, 2019 at 6:39
  • I updated the question with the document class. thanks for your input.
    – Moj
    Commented May 24, 2019 at 6:55
  • @Moj, I edit answer. Now is adopted to your document class.
    – Zarko
    Commented May 24, 2019 at 8:51

You must log in to answer this question.

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