表格宽度对于页面来说太大。如何解决?

表格宽度对于页面来说太大。如何解决?

我在 Overleaf (Latex) 中制作了一个表格。但问题是表格超出了纸张范围。如下所示:

在此处输入图片描述

我认为问题出在 Notes 上,因为当我删除 Notes 时,问题就解决了(但我想保留 Notes,因此问题仍然存在)。有人有什么建议吗?我的代码是:

\documentclass[12pt]{article}
\begin{document}
\begin{table}[!htbp] \centering 
  \caption{The effect of time on negative campaigning and trait attacks and the effect of opposition party, (supporting, governing party), electoral loss, and ideology on negative campaigning.} 
\begin{tabular}{@{\extracolsep{5pt}}lcccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{6}{c}{\textit{Dependent variables}} \\ 
\cline{2-7} 
\\[-1.8ex] & \multicolumn{6}{c}{ } \\ 
 & N-C & T-A & N-C & N-C & N-C & N-C \\ 
\\[-1.8ex] & (1) & (2) & (3) & (4) & (5) & (6)\\ 
\hline \\[-1.8ex] 
 Time (1970-2022) & $-$0.550$^{***}$ & $-$1.640$^{***}$ &  &  &  &  \\ 
  & (0.000) & (0.000) &  &  &  \\  
  & & & & & & \\  
 Supporting Party (= ref.) &  &  & &  &  & \\ 
  &  &  &  &  &  &  \\ 
  & & & & & & \\ 
 Governing Party &  &  & $-$3.512 &  &  & $-$1.830 \\ 
  &  &  & (2.793) &  &  & (3.289) \\ 
  & & & & & & \\ 
 Opposition Party &  &  & $-$4.202$^{*}$ &  &  & $-$4.000$^{**}$ \\ 
  &  &  & (1.753) &  &  & (1.299) \\ 
  & & & & & & \\ 
 Electoral Loss &  &  &  & 0.005 &  & 0.008 \\ 
  &  &  &  & (0.012) &  & (0.011) \\ 
  & & & & & & \\ 
 Ideology &  &  &  &  & 1.781$^{*}$ & 1.764$^{*}$ \\ 
  &  &  &  &  & (0.851) & (0.722) \\ 
  & & & & & & \\ 
 Ideology dummy (= SD) &  &  &  &  & $-$3.041 & $-$2.912$^{*}$ \\ 
  &  &  &  &  & (1.620) & (1.224) \\ 
  & & & & & & \\ 
 Constant & 15.300 & 27.540 & 11.031$^{***}$ & 7.626$^{***}$ & 3.869$^{*}$ & 6.395$^{**}$ \\ 
  &  (0.000)& (0.000) & (2.173) & (1.488) & (1.922) & (2.371) \\ 
  & & & & & & \\ 
\hline \\[-1.8ex]
\textit{Observations} & 103 & 103 & 103 & 103 & 103 & 103 \\ 
\textit{Adjusted R$^{2}$ }& 1.000 & 1.000 & 0.008 & $-$0.011 & 0.035 & 0.037 \\ 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
\multicolumn{6}{@{}p{\textwidth}@{}}{\small \textbf{Notes:} N-C stands for negative campaigning and T-A stands for trait attacks. Ref. stands for reference category. Coefficients are the estimates of the ordinary least squares regression with the robust standard errors clustered on parties in parentheses. All models include the election year dummies as fixed effects (not shown due to too little space in the table). * represents a significance level of $p$ $<$ 0.05 (5\%), ** represents a significance level of $p$ $<$ 0.01 (1\%), and *** represents a significance level of $p$ $<$ 0.001 (0.1\%).}
\end{tabular} 
\end{table}
\end{document}

答案1

我将按照以下方式书写您的表格:

\documentclass[12pt]{article}
%\usepackage{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\usepackage{tabularray}     %   NEW
\UseTblrLibrary{booktabs,   %   NEW, load package booktabs
                siunitx,    %   NEW, load siunitx package
                }
\sisetup{
    table-align-text-before=false, % <---
    input-open-uncertainty=,
    input-close-uncertainty=,
         }

\begin{document}
\begin{table}[!ht]
    \centering
    \small
\SetTblrStyle{remark}{font=\footnotesize}
\begin{talltblr}[
caption = {The effect of time on negative campaigning and trait attacks and the effect of opposition party, (supporting, governing party), electoral loss, and ideology on negative campaigning.},
  label = {tab:?},
remark{Notes} = {N-C stands for negative campaigning and T-A stands for trait attacks. Ref. stands for reference category. Coefficients are the estimates of the ordinary least squares regression with the robust standard errors clustered on parties in parentheses. All models include the election year dummies as fixed effects (not shown due to too little space in the table). * represents a significance level of $p<0.05$ (\qty{5}{\%}), ** represents a significance level of $p<0.01$ (\qty{1}{\%}), and *** represents a significance level of $p<0.001$ (\qty{0.1}{\%}).}
                ]{colsep=1.3pt,
                  colspec = {@{} X[2,l] *{6}{X[c, si= {table-format=2.3{$^{***}$}}]} @{}},
                  row{1} = {guard, font=\itshape},
                  row{2,3} = {guard},
                  row{4}   = {belowsep=-1pt},
                  row{5-Z} = {rowsep=-1pt},
                  row{odd[4-Z]} = {belowsep=1ex},
                  }
%%%% table body
    \toprule
\SetCell[r=3]{c}
    &   \SetCell[c=6]{c}  Dependent variables 
                &           &           &           &           &           \\
    \midrule
    &   N-C     &     T-A   &     N-C   &   N-C     & N-C       & N-C       \\
    &   (1)     &     (2)   &     (3)   &   (4)     & (5)       & (6)       \\
    \midrule
Time (1970-2022) 
    & -0.550\TblrNote{***}
                & -1.640\TblrNote{***}
                            &           &           &           &           \\
    & (0.000)   & (0.000)   &           &           &           &           \\
\SetCell[r=2]{l} {Supporting Party\\ (= ref.)}
    &           &           &           &           &           &           \\
    &           &           &           &           &           &           \\
Governing Party 
    &           &           & -3.512    &           &           & -1.830    \\
    &           &           & (2.793)   &           &           & (3.289)   \\

Opposition Party 
    &           &           & -4.202\TblrNote{*}
                                        &           &           & -4.000\TblrNote{**}    \\
    &           &           & (1.753)   &           &           & (1.299)   \\
Electoral Loss 
    &           &           &           & 0.005     &           & 0.008     \\
    &           &           &           & (0.012)   &           & (0.011)   \\
Ideology 
    &           &           &           &           & 1.781\TblrNote{*} 
                                                                & 1.764\TblrNote{*}     \\
    &           &           &           &           & (0.851)   & (0.722)   \\
\SetCell[r=2]{l} {Ideology dummy\\ (= SD)} 
    &           &           &           &           & -3.041    & -2.912\TblrNote{*}    \\
    &           &           &           &           & (1.620)   & (1.224)   \\
Constant 
    & 15.300    & 27.540    & 11.031\TblrNote{***} 
                                        & 7.626\TblrNote{***} 
                                                    & 3.869\TblrNote{*} 
                                                                & 6.395\TblrNote{**}    \\
    &  (0.000)  & (0.000)   & (2.173)   & (1.488)   & (1.922)   & (2.371)       \\
    \midrule
\SetRow{guard, mode=text}
\textit{Observations} 
    & {103}     & {103}     & {103}     & {103}     & {103}     & {103}         \\
\textit{Adjusted $R^{2}$}
    & 1.000     & 1.000     & 0.008     & -0.011    & 0.035     & 0.037         \\
    \bottomrule
\end{talltblr}
\end{table}
\end{document}
  • 使用的是talltblr表,tabularray相当于threeparttable
  • 数字按小数点对齐(通过使用siunitx包)
  • 删除所有空行并用奇数行的额外垂直空格替换。
  • 如果您可以放大,则可以设置更大的字体大小和列之间的距离\textwidth,例如通过使用geometry
  • 有关tabularray语法的详细信息,请阅读软件包文档

在此处输入图片描述

(红线显示页面布局)

附录:
如果您喜欢不同风格的标题,例如您问题中的图片所示,那么实现此目的的更简单方法是将标题移出包talltblr并由包定义样式caption。在这种情况下,文档和表格序言如下:

\documentclass[12pt]{article}
%\usepackage{geometry}

\usepackage[font=small, labelfont=bf, 
            skip=0.33\baselineskip]{caption}
\usepackage{tabularray}     %   NEW
\UseTblrLibrary{booktabs,   %   NEW, load package booktabs
                siunitx,    %   NEW, load siunitx package
                }
\sisetup{
    table-align-text-before=false, % <---
    input-open-uncertainty=,
    input-close-uncertainty=,
         }

\begin{document}
\begin{table}[!ht] 
    \centering
    \small
\caption{The effect of time on negative campaigning and trait attacks and the effect of opposition party, (supporting, governing party), electoral loss, and ideology on negative campaigning.}
\label{tab:?}

\SetTblrStyle{remark}{font=\footnotesize}
\begin{talltblr}[
    label=none,
    entry=none,
remark{Notes} = {N-C stands for negative campaigning and T-A stands for trait attacks. Ref. stands for reference category. Coefficients are the estimates of the ordinary least squares regression with the robust standard errors clustered on parties in parentheses. All models include the election year dummies as fixed effects (not shown due to too little space in the table). * represents a significance level of $p<0.05$ (\qty{5}{\%}), ** represents a significance level of $p<0.01$ (\qty{1}{\%}), and *** represents a significance level of $p<0.001$ (\qty{0.1}{\%}).}
                ]{colsep=3pt,
                  colspec = {@{} X[2,l] *{6}{X[c, si= {table-format=2.3{$^{***}$}}]} @{}},
                  row{1} = {guard, font=\itshape},
                  row{2,3} = {guard},
                  row{4}   = {belowsep=-1pt},
                  row{5-Z} = {rowsep=-1pt},
                  row{odd[4-Z]} = {belowsep=1ex},
                  }
%%%% table body

文档的前几行表格是:

在此处输入图片描述

答案2

这样的表格不太可能适合 12pt 大小的标准文本宽度,因此至少\small需要减小到。

我还会删除“幻像行”,选择更好的命令booktabs。第一列中较长的描述可以方便地拆分到多行中。

\tabcolsep参数设置为零,因此\extracolsep可以完成其工作。检查最终结果,如果结果太局促,请切换到\footnotesize而不是\small

\documentclass[12pt]{article}
\usepackage{caption}
\usepackage{booktabs}

\begin{document}

\begin{table}[tp] % no chance to get it h even with !

\caption{The effect of time on negative campaigning and trait attacks and 
  the effect of opposition party, (supporting, governing party), electoral
  loss, and ideology on negative campaigning.} 

\small

\setlength{\tabcolsep}{0pt}

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lcccccc@{}}
\toprule
& \multicolumn{6}{c}{\textit{Dependent variables}} \\ 
\cmidrule{2-7}
& N-C & T-A & N-C & N-C & N-C & N-C \\ 
& (1) & (2) & (3) & (4) & (5) & (6)\\ 
\midrule
 Time (1970-2022) & $-$0.550$^{***}$ & $-$1.640$^{***}$ &  &  &  &  \\ 
  & (0.000) & (0.000) &  &  &  \\
\addlinespace
 Supporting Party &  &  & &  &  & \\ 
(= ref.) &  &  &  &  &  &  \\ 
\addlinespace
 Governing Party &  &  & $-$3.512 &  &  & $-$1.830 \\ 
  &  &  & (2.793) &  &  & (3.289) \\ 
\addlinespace
 Opposition Party &  &  & $-$4.202$^{*}$ &  &  & $-$4.000$^{**}$ \\ 
  &  &  & (1.753) &  &  & (1.299) \\ 
\addlinespace
 Electoral Loss &  &  &  & 0.005 &  & 0.008 \\ 
  &  &  &  & (0.012) &  & (0.011) \\ 
\addlinespace
 Ideology &  &  &  &  & 1.781$^{*}$ & 1.764$^{*}$ \\ 
  &  &  &  &  & (0.851) & (0.722) \\ 
\addlinespace
 Ideology dummy &  &  &  &  & $-$3.041 & $-$2.912$^{*}$ \\ 
(= SD)  &  &  &  &  & (1.620) & (1.224) \\ 
\addlinespace
 Constant & 15.300 & 27.540 & 11.031$^{***}$ & 7.626$^{***}$ & 3.869$^{*}$ & 6.395$^{**}$ \\ 
  &  (0.000)& (0.000) & (2.173) & (1.488) & (1.922) & (2.371) \\ 
\midrule
\textit{Observations} & 103 & 103 & 103 & 103 & 103 & 103 \\ 
\textit{Adjusted $R^{2}$ }& 1.000 & 1.000 & 0.008 & $-$0.011 & 0.035 & 0.037 \\ 
\bottomrule
\end{tabular*}

\medskip

\textbf{Notes:} N-C stands for negative campaigning and T-A stands for trait attacks. 
Ref. stands for reference category. Coefficients are the estimates of the ordinary 
least squares regression with the robust standard errors clustered on parties in 
parentheses. All models include the election year dummies as fixed effects (not shown 
due to too little space in the table). * represents a significance level of $p<0.05$~(5\%), 
** represents a significance level of $p<0.01$~(1\%), and *** represents a significance 
level of $p<0.001$~(0.1\%).

\end{table}
\end{document}

在此处输入图片描述

加载的目的caption只是将标题与表格分离。如果你不想加载包,至少将其放置\medskip在标题和表格之间。

相关内容