1

I have made a table in Overleaf (Latex). The problem, however, is that the table goes outside the paper. Like this:

enter image description here

I think the problem is with Notes, because when I remove Notes, the problem is solved (but I want to keep Notes therefore the problem). Does anyone have tips? My code is:

\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}
Zarko
  • 296,517
  • Welcome to TeX,SE. Regarding table width your question is duplicte to https://tex.stackexchange.com/questions/332902/my-table-doesnt-fit-what-are-my-options. Beside this your table has other issues which for profesional looking table also should be addressed. For example use of threeparttable or taltblr of tabularray package, use of S column type for aligning of numbers at decimal points etc. – Zarko Nov 25 '22 at 00:05
  • As an example of similar table see https://tex.stackexchange.com/questions/625535/. I should be easy accomodate to your specific (used documentclass and table contents) – Zarko Nov 25 '22 at 00:08
  • First, get rid of the \extracolsep. It either does nothing or adds space. You could make \tabcolsep smaller. – John Kormylo Nov 25 '22 at 00:20
  • In the last row, \multicolumn{6}... should be changed to \multicolumn{7}... as you define 7 columns. This is one of the reasons of table begin larger than expected. – Celdor Nov 25 '22 at 10:40
  • Thanks all! Appreciate it! –  Nov 26 '22 at 01:52

2 Answers2

3

Your table I would write on the following way:

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

  • used is talltblr table, a tabularray equivalent for threeparttable
  • numbers are aligned at decimal points (by use of siunitx package)
  • removed are all empty rows and replaced by additional vertical spaces at odd rows.
  • bigger font size and distances between column can be set if you can make \textwidth larger, for example by use of geometry package
  • for details about tabularray syntax read package documentation

enter image description here

(red lines show page layout)

Addendum:
In a casem when you like different style of caption, for example as can be seen on image in your question, than is simpler way to achieve this move caption outside of talltblr and style define by caption package. In this case the document and table preambles are:

\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

and document first few table rows is:

enter image description here

Zarko
  • 296,517
1

It's very unlikely that such a table can fit a standard text width at 12pt size, so reduction at least to \small is needed.

I'd also remove the “phantom rows”, opting for the better commands of booktabs. The longer descriptions in the first column can conveniently be split across lines.

The \tabcolsep parameter is set to zero, so \extracolsep can do its job. Check the final result and if it comes out too cramped, switch to \footnotesize instead of \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}

enter image description here

The purpose of loading caption is just to detach the caption from the table. If you don't want to load the package, at least place \medskip between caption and table.

egreg
  • 1,121,712