1

I am trying to make a table like this but it doesn't come out good as the rows overlap like this: enter image description here Here is the code:

\documentclass[a4paper]{article} 
\input{head}
\usepackage[utf8]{inputenc}
\usepackage{bbm}
\usepackage{bbold}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{empheq}
\usepackage{mathtools}
\usepackage{tabularx,ragged2e,booktabs,caption}
\newcolumntype{C}[1]{>{\Centering}m{#1}}
\renewcommand\tabularxcolumn[1]{C{#1}}
\begin{document}

\begin{minipage}{\linewidth}
\centering
\captionof{table}{Results of the regression model} 
\label{tab:title} 
\begin{tabular}{ C{1.25in} C{.85in} *4{C{.75in}}}\toprule[1.5pt]
\bf Parameters & \bf IV C & \bf Standard error (SE)& \bf 2SLS & \bf Standard error (SE) & \bf 2SLS & \bf Standard error (SE) &\bf GMM & \bf Standard error (SE)\\\bottomrule[1.25pt]
Cons & $2.266$ & $1.000$ & $4.087$ & $0.158$ & $4.094$ & $0.223$\\
\midrule
Educ & $0.223$ & $0.058$ & $0.118$ & $0.009$ & $0.117$ & $0.013$\\
\midrule
Exper & $0.151$ & $0.027$ & $0.105$ & $0.007$ & $0.105$ & $0.010$\\
\midrule
$\text{Exper}^2$ & $-0.003$ & $0.001$ & $-0.003$ & $0.000$ & $-0.003$ & $0.000$\\
\midrule
$South$ & $-0.086$ & $0.029$ & $-0.123$ & $0.013$ & $-0.123$ & $0.018$\\
\midrule
$Black$ & $-0.036$ & $0.056$ & $-0.127$ & $0.019$ & $-0.129$ & $0.026$\\
\bottomrule[1.25pt]
\end {tabular}\par
\bigskip
\end{minipage}

\end{document}

Can anyone help me fix this problem, please?

5
  • Your data has 7 columns but you declared 6 columns: C{1.25in} C{.85in} *4{C{.75in}}. Commented Apr 27, 2021 at 13:18
  • Ah I see. Fixed it :). Thank you! Commented Apr 27, 2021 at 13:27
  • Could you post a compilable code, not just a snippet? We don"t even know your document class.
    – Bernard
    Commented Apr 27, 2021 at 13:59
  • @Bernard just edited it. Hope it helps Commented Apr 27, 2021 at 14:15
  • 3
    You declare 6 columns, but use 9 column heads
    – Bernard
    Commented Apr 27, 2021 at 14:56

2 Answers 2

3

With some changes to the columns widths, and using the table environment instead of minipage, seven columns will fit on the page.

The optional \arraystretch allows for a vertical expansion of the cells.

a

(use \bfseries or \textbf{...} instead of the older \bf for bold face)

% !TeX TS-program = pdflatex

\documentclass[a4paper]{article} 
%\input{head}
\usepackage[utf8]{inputenc}
\usepackage{bbm}
\usepackage{bbold}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{empheq}
\usepackage{mathtools}
\usepackage{tabularx,ragged2e,booktabs,caption}

\newcolumntype{C}[1]{>{\Centering}m{#1}}
\renewcommand\tabularxcolumn[1]{C{#1}}

\usepackage{array} %<<<< added
\renewcommand{\arraystretch}{1.5}
    
\begin{document}    
    
\begin{table}[ht!]
    \centering
    \caption{Results of the regression model} 
    \label{tab:title} 
    \begin{tabular}{ C{.75in} C{.55in} *5{C{.55in}}} % changed <<<<<
        \toprule%[1.5pt]
    \bfseries Parameters & \bfseries IV C & \bfseries Standard error (SE)& \bfseries 2SLS & \bfseries Standard error (SE) &\bfseries GMM & \bfseries Standard error (SE) \\
        \bottomrule
        Cons & $2.266$ & $1.000$ & $4.087$ & $0.158$ & $4.094$ & $0.223$\\
        \midrule
        Educ & $0.223$ & $0.058$ & $0.118$ & $0.009$ & $0.117$ & $0.013$\\
        \midrule
        Exper & $0.151$ & $0.027$ & $0.105$ & $0.007$ & $0.105$ & $0.010$\\
        \midrule
        $\text{Exper}^2$ & $-0.003$ & $0.001$ & $-0.003$ & $0.000$ & $-0.003$ & $0.000$\\
        \midrule
        $South$ & $-0.086$ & $0.029$ & $-0.123$ & $0.013$ & $-0.123$ & $0.018$\\
        \midrule
        $Black$ & $-0.036$ & $0.056$ & $-0.127$ & $0.019$ & $-0.129$ & $0.026$\\
        \bottomrule
    \end{tabular}
\end{table}
        
\end{document}

With another flavor, using only the package nicematrix to build the table and adding siunitx to align the decimal points, (compile twice the first time) the code is much cleaner.

The command \Block{} allows the use of \\ inside.

b

% !TeX TS-program = pdflatex

\documentclass[a4paper]{article} 

\usepackage{nicematrix}
\usepackage{siunitx} % align the decimal points 

\begin{document}    

\begin{table}[ht!]
\centering
\caption{Results of the regression model} \medskip
\label{tab:title} 
    \begin{NiceTabular}[c]{l *6{S[table-format = 1.3]} }[hlines, cell-space-limits=6pt] % horizontal lines and cell expands 
        \bfseries Parameters & \bfseries IV C & \Block{}<\bfseries>{Standard \\error \\(SE)}& \bfseries 2SLS &  \Block{}<\bfseries>{Standard \\error \\(SE)} &\bfseries GMM &  \Block{}<\bfseries>{Standard \\error \\(SE)} \\
        Cons                        & 2.266 & 1.000 & 4.087 & 0.158 & 4.094  &  0.223\\
        Educ                        & 0.223 & 0.058 & 0.118 & 0.009 & 0.117  & 0.013\\
        Exper                       & 0.151 & 0.027 & 0.105 & 0.007 & 0.105  & 0.010\\
        Exper\textsuperscript{2}    & -0.003& 0.001 & -0.003& 0.000 & -0.003 & 0.000\\
        South                       & -0.086& 0.029 & -0.123& 0.013 & -0.123 & 0.018\\
        Black                       & -0.036& 0.056 & -0.127& 0.019 & -0.129 & 0.026\\  
    \end{NiceTabular}
\end{table}
            
\end{document}
2

What about one of the following two redesigns?

enter image description here

\documentclass[a4paper]{article} 

\usepackage{booktabs,caption}
\usepackage{makecell}
\usepackage{siunitx}

\begin{document}

\begin{table}
\centering
\setlength{\tabcolsep}{0pt}
\caption{Results of the regression model} 
\label{tab:title} 
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l *{4}{S[table-format=-1.3]S[table-format=1.3]}}
\toprule
\thead{Parameters} 
  & {\thead{IV C}} & {\thead{Standard\\ error\\ (SE)}}
  & {\thead{2SLS}} & {\thead{Standard\\ error\\ (SE)}} 
  & {\thead{2SLS}} & {\thead{Standard\\ error\\(SE)}} 
  & {\thead{GMM}} & {\thead{Standard\\ error\\ (SE)}}\\
\midrule
Cons & 2.266 & 1.000 & 4.087 & 0.158 & 4.094 & 0.223\\
Educ & 0.223 & 0.058 & 0.118 & 0.009 & 0.117 & 0.013\\
Exper & 0.151 & 0.027 & 0.105 & 0.007 & 0.105 & 0.010\\
Exper\textsuperscript{2} & -0.003 & 0.001 & -0.003 & 0.000 & -0.003 & 0.000\\
South & -0.086 & 0.029 & -0.123 & 0.013 & -0.123 & 0.018\\
Black & -0.036 & 0.056 & -0.127 & 0.019 & -0.129 & 0.026\\
\bottomrule
\end{tabular*}
\end{table}


\begin{table}
\setlength{\tabcolsep}{0pt}
\renewcommand{\theadfont}{\normalsize}
\sisetup{separate-uncertainty=true}
\caption{Results of the regression model} 
\label{tab:title} 
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l *{4}{S[table-format=-1.3(4)]}}
\toprule
\thead{Parameters}  & {\thead{IV C}}  & {\thead{2SLS}}  & {\thead{2SLS}}  & {\thead{GMM}} \\
\midrule
Cons                     & 2.266(1000) & 4.087(158) & 4.094(223) & 0.000(0)  \\
Educ                     & 0.223(58)   & 0.118(9)   & 0.117(13)   \\
Exper                    & 0.151(27)   & 0.105(7)   & 0.105(10)   \\
Exper\textsuperscript{2} & -0.003(1)   & -0.003(0)  & -0.003(0)   \\
South                    & -0.086(29)  & -0.123(13) & -0.123(18)  \\
Black                    & -0.036(56)  & -0.127(19) & -0.129(26)  \\
\bottomrule
\end{tabular*}
\end{table}

\end{document}

You must log in to answer this question.

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