使表格适合页面

使表格适合页面

我是 Latex 的新手,在将回归表放到一页(纵向)上时遇到了一些困难。目前我正在使用它,\resizebox但无法完全正常工作。我找到了一个依赖于该adjustbox包的类似线程,但由于某种原因,我的 PC 无法安装它... (缩小表格以适合页面,或保持原样

有人对我如何缩小表格以适合一页有什么建议吗?

这是我的设置:

\documentclass[12pt]{article}
\usepackage{amsmath,graphicx,amsthm,lscape,setspace}
\usepackage{graphicx}
\usepackage{endnotes}
\usepackage{lscape}
\usepackage{verbatim}
\setlength{\oddsidemargin}{0in}
\setlength{\textwidth}{6.85in}
\setlength{\topmargin}{0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textheight}{9in}
\renewcommand{\baselinestretch}{1.46}
\renewcommand{\arraystretch}{1}
\setlength{\evensidemargin}{0in}
\flushbottom

\begin{document}

\renewcommand{\arraystretch}{1.25} \renewcommand{\baselinestretch}{1}
\pagestyle{empty}
\begin{center}
\resizebox{\columnwidth}{!}{%
\begin{tabular}{lcccccccc}
\multicolumn{6}{l}{Table 5.1.  \\
\multicolumn{6}{l}{\scriptsize{Notes text......}} \\
\cline{1-6}
\multicolumn{6}{c}{Panel A}\\
\cline{1-6}
{} & \multicolumn{2}{c}{Purchase Turnover} & & \multicolumn{2}{c}{Sale Turnover}\\
\cline{2-3}  \cline{5-6}
{} & {$(1)$} & {$(2)$} & & {$(1)$} & {$(2)$} \\ 
\cline{1-6}
Experience & -0.148 & -0.0114 &       & -0.0025 & 0.0058 \\
  & (-39.87) & (-4.10) &       & (-1.37) & (2.41) \\
Initial Dependent &       & 0.0857 &       &       & 0.110 \\
  &       & (15.02) &       &       & (7.02)  \\
Lag Dependent &       & 0.126 &       &       & 0.125 \\
  &       & (12.11) &       &       & (9.74)  \\
Lag Return &       & 0.0483 &       &       & 0.0295$ \\
  &       & (7.14) &       &       & (5.01) \\
Intercept & 0.350 & 0.245 &       & 0.0634 & -0.121 \\
  & (50.57) & (2.88) &       & (19.78) & (-1.64) \\
\cline{1-6}
Controls & No & Yes & & No & Yes \\
Year FE & Yes & Yes & & Yes & Yes \\
County FE & Yes & Yes & & Yes & Yes \\
\cline{1-6}
No. Obs. & 129,861 & 84,747 &       & 129,861 & 84,747 \\
Adj. R-sq & 0.128 & 0.075 &       & 0.017 & 0.050 \\
\cline{1-6}
% Panel B
\multicolumn{6}{c}{Panel B - All Households}\\
\cline{1-6}
{} & \multicolumn{2}{c}{Purchase Turnover} & & \multicolumn{2}{c}{Sale Turnover}  \\
\cline{2-3}  \cline{5-6}
{} & {$(1)$} & {$(2)$} & & {$(1)$} & {$(2)$} \\ 
\cline{1-6}
Experience & -0.121 & -0.0004 &       & -0.078 & 0.041 \\
  & (-48.57) & (-2.50) &       & (-1.77) & (2.03) \\
Initial Dependent &       & 0.0997 &       &       & 0.250 \\
  &       & (19.92) &       &       & (7.96)  \\
Lag Dependent &       & 0.116 &       &       & 0.144 \\
  &       & (11.00) &       &       & (7.28)  \\
Lag Return &       & 0.323 &       &       & 0.0258 \\
  &       & (4.58) &       &       & (2.31) \\
Intercept & 0.589 & 0.225 &       & 0.0436 & -0.122 \\
  & (51.57) & (2.11) &       & (15.72) & (-1.51) \\
\cline{1-6}
Controls & No & Yes & & No & Yes  \\
Year FE & Yes & Yes & & Yes & Yes  \\
County FE & Yes & Yes & & Yes & Yes \\
\cline{1-6}
No. Obs. & 1,256,615 & 874,015 &       & 1,256,615 & 874,015 \\
Adj. R-sq & 0.017 & 0.045 &       & 0.007 & 0.026 \\
\cline{1-6}
\end{tabular}%
}
\end{center}

抱歉代码太长了!谢谢您的帮助!!

答案1

我建议对您的代码进行以下更改:

  • 如果我理解正确的话,您希望表格的宽度与文本宽度相同。这可以通过使用 轻松实现tabularx。为此,请不要使用adjustbox,因为表格会变得非常难看。
  • 表格标题除了longtable应该在tabular环境之外,所以我引入了浮动环境table并添加了caption
  • booktabs为了使表格看起来美观,使用包及其规则是合适的: toprulemidrule......正如您在下面的代码中看到的那样
  • 您的表格实际上有五列,而不是六列,因此我减少了列数
  • 图中showframeI 表示表格的宽度为文本宽度。实际使用时请删除此包。
  • 似乎您希望在正文和表格文本中使用不同的行间空间。为此,我使用包setspace并将完整的表格内容放在\begin{spacing}{1.0} ...之间\end{spacing}。您可以根据自己的意愿和品味更改此延伸。

经过所有这些改变后,我得到了以下结果:

在此处输入图片描述

我没有重新输入整个表格,缺失的行很容易添加。

\documentclass[12pt]{article}
    \usepackage{amsmath,amsthm}
    \usepackage{setspace}
    \usepackage{graphicx}
    \usepackage{endnotes}
    \usepackage{lscape}
    \usepackage{verbatim}

\setlength{\oddsidemargin}{0in}
\setlength{\textwidth}{6.85in}
\setlength{\topmargin}{0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textheight}{9in}
\renewcommand{\baselinestretch}{1.46}
\renewcommand{\arraystretch}{1}
\setlength{\evensidemargin}{0in}
\flushbottom

    \usepackage{showframe}% just to show page layout
    \usepackage{caption}
    \usepackage{booktabs, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
    \pagestyle{empty}

\begin{table}
    \begin{spacing}{1.0}
\caption[Table 5.1]
        {Table 5.1.\medskip\newline
        Notes text......}
\label{tab:mytable}
    \begin{tabularx}{\hsize}{l*{4}{C}}
    \toprule
\multicolumn{5}{c}{Panel A}\\
    \midrule
    &   \multicolumn{2}{c}{Purchase Turnover} 
        & \multicolumn{2}{c}{Sale Turnover}\\
    \cmidrule(r){2-3}  \cmidrule(l){4-5}
    & $(1)$     &  $(2)$    & $(1)$     & $(2)$     \\
    \midrule
Experience 
    & -0.148    & -0.0114   & -0.0025   &   0.0058  \\
    & (-39.87)  & (-4.10)   & (-1.37)   &   (2.41)  \\
Initial Dependent 
    &           & 0.0857    &           &   0.110   \\
    &           & (15.02)   &           &   (7.02)  \\
Lag Dependent 
    &           & 0.126     &           &   0.125   \\
    &           & (12.11)   &           &   (9.74)  \\
Lag Return 
    &           & 0.0483    &           &   0.0295  \\
    &           &           &           &   (5.01)  \\
Intercept 
    &   0.350   & 0.245     &   0.0634  &    -0.121 \\
    &   (50.57) & (2.88)    &   (19.78) &   (-1.64) \\
    \midrule
Controls 
    & No        &   Yes     &   No      &   Yes     \\
Year FE 
    &   Yes     &   Yes     &   Yes     &   Yes     \\
County FE   
    & Yes       &   Yes     &   Yes     &   Yes     \\
    \midrule
No. Obs. 
    & 129,861   & 84,747    &   129,861 & 84,747    \\
Adj. R-sq 
    & 0.128     & 0.075     &   0.017   & 0.050     \\
    \bottomrule
    \addlinespace[1em]
% Panel B
    \multicolumn{5}{c}{Panel B - All Households}    \\
    \midrule
    &   \multicolumn{2}{c}{Purchase Turnover} 
        &   \multicolumn{2}{c}{Sale Turnover}       \\
    \cmidrule(r){2-3}  \cmidrule(l){4-5}
    & $(1)$     &  $(2)$    & $(1)$     & $(2)$     \\
    \midrule
Experience 
    & -0.121    & -0.0004   &   -0.078  &   0.041   \\
    & (-48.57)  & (-2.50)   &   (-1.77) &   (2.03)  \\
Initial Dependent 
    &           & 0.0997    &           &   0.250   \\
    \bottomrule
\end{tabularx}
    \end{spacing}
    \end{table}
\end{document}

答案2

你是指像下面的代码那样的东西吗?

(您的代码无法编译:缺少花括号,$ 而不是 \$。)

\documentclass[12pt]{article}
\usepackage{amsmath,graphicx,amsthm,lscape,setspace}
\usepackage{graphicx}
\usepackage{endnotes}
\usepackage{lscape}
\usepackage{verbatim}
\setlength{\oddsidemargin}{0in}
\setlength{\textwidth}{6.85in}
\setlength{\topmargin}{0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textheight}{9in}
\renewcommand{\baselinestretch}{1.46}
\renewcommand{\arraystretch}{1}
\setlength{\evensidemargin}{0in}
\flushbottom

\begin{document}

\renewcommand{\arraystretch}{0.8} \renewcommand{\baselinestretch}{1}
\pagestyle{empty}
\begin{center}
\resizebox{4.5in}{!}{%
\begin{tabular}{lcccccccc}
\multicolumn{6}{l}{Table 5.1.}  \\
\multicolumn{6}{l}{\scriptsize{Notes text......}} \\
\cline{1-6}
\multicolumn{6}{c}{Panel A}\\
\cline{1-6}
{} & \multicolumn{2}{c}{Purchase Turnover} & & \multicolumn{2}{c}{Sale Turnover}\\
\cline{2-3}  \cline{5-6}
{} & {$(1)$} & {$(2)$} & & {$(1)$} & {$(2)$} \\ 
\cline{1-6}
Experience & -0.148 & -0.0114 &       & -0.0025 & 0.0058 \\
  & (-39.87) & (-4.10) &       & (-1.37) & (2.41) \\
Initial Dependent &       & 0.0857 &       &       & 0.110 \\
  &       & (15.02) &       &       & (7.02)  \\
Lag Dependent &       & 0.126 &       &       & 0.125 \\
  &       & (12.11) &       &       & (9.74)  \\
Lag Return &       & 0.0483 &       &       & 0.0295 \\
  &       & (7.14) &       &       & (5.01) \\
Intercept & 0.350 & 0.245 &       & 0.0634 & -0.121 \\
  & (50.57) & (2.88) &       & (19.78) & (-1.64) \\
\cline{1-6}
Controls & No & Yes & & No & Yes \\
Year FE & Yes & Yes & & Yes & Yes \\
County FE & Yes & Yes & & Yes & Yes \\
\cline{1-6}
No. Obs. & 129,861 & 84,747 &       & 129,861 & 84,747 \\
Adj. R-sq & 0.128 & 0.075 &       & 0.017 & 0.050 \\
\cline{1-6}
% Panel B
\multicolumn{6}{c}{Panel B - All Households}\\
\cline{1-6}
{} & \multicolumn{2}{c}{Purchase Turnover} & & \multicolumn{2}{c}{Sale Turnover}  \\
\cline{2-3}  \cline{5-6}
{} & {$(1)$} & {$(2)$} & & {$(1)$} & {$(2)$} \\ 
\cline{1-6}
Experience & -0.121 & -0.0004 &       & -0.078 & 0.041 \\
  & (-48.57) & (-2.50) &       & (-1.77) & (2.03) \\
Initial Dependent &       & 0.0997 &       &       & 0.250 \\
  &       & (19.92) &       &       & (7.96)  \\
Lag Dependent &       & 0.116 &       &       & 0.144 \\
  &       & (11.00) &       &       & (7.28)  \\
Lag Return &       & 0.323 &       &       & 0.0258 \\
  &       & (4.58) &       &       & (2.31) \\
Intercept & 0.589 & 0.225 &       & 0.0436 & -0.122 \\
  & (51.57) & (2.11) &       & (15.72) & (-1.51) \\
\cline{1-6}
Controls & No & Yes & & No & Yes  \\
Year FE & Yes & Yes & & Yes & Yes  \\
County FE & Yes & Yes & & Yes & Yes \\
\cline{1-6}
No. Obs. & 1,256,615 & 874,015 &       & 1,256,615 & 874,015 \\
Adj. R-sq & 0.017 & 0.045 &       & 0.007 & 0.026 \\
\cline{1-6}
\end{tabular}%
}
\end{center}

\end{document}


[![enter image description here][1]][1]

相关内容