格式化表格以适合页面

格式化表格以适合页面

我正在尝试制作这样的表格,但效果不太好,因为行重叠如下:在此处输入图片描述 以下是代码:

\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}

有人能帮我解决这个问题吗?

答案1

对列宽进行一些更改,并使用环境table而不是minipage,页面上将可以容纳七列。

可选项\arraystretch允许单元的垂直扩展。

A

(使用\bfseries\textbf{...}代替旧的\bf粗体字)

% !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}

另一种方式是,仅使用包nicematrix来构建表并添加siunitx对齐小数点(第一次编译两次),代码会更干净。

该命令\Block{}允许使用\\内部。

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

以下两种重新设计中的一种怎么样?

在此处输入图片描述

\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}

相关内容