0

I have a table which is wider than my usual margins. This results in the table violating the right margin. (putting table in landscape wont work because of the length) I want to have a caption of the same size as the table. I can adjust the left, but not the right margin. Is there a way to make it violate the right margin as well ? Or alternatively, a way to have my table violate the left margin instead of the right.

 \documentclass[a4paper,10pt]{article}
 \usepackage[margin=3cm]{geometry}
 \usepackage{amssymb,amsmath, array, float, subfig}
 \usepackage{ragged2e, setspace}
 \usepackage{longtable}
 \usepackage{pdflscape}
 \usepackage{graphicx, natbib, cite}
 \usepackage[utf8]{inputenc}
 \usepackage{caption} 
 \usepackage{tabularx}
 \usepackage{afterpage}

\begin{document}
\begin{table}
\captionsetup{width=1.5\textwidth, margin=0em}
\setlength{\leftskip}{\captionmargin}%
\caption{Title\\ \small Columns 1 and 2 show the effect of blablablalab}
    \begin{tabular}[]{p{2,15cm}p{1.45cm} p{1.45cm} p{1.45cm} p{1.45cm} p{1.45cm} p{1.45cm} p{1.45cm} p{1.45cm}} \hline

                     & (1)      & (2)                & (3)      & (4)      & (5)      & (6)      & (7)                & (8)                \\
     Dep.Var.Name                & Dep.Var.Name & \(\Delta\)Dep.Var.Name & Dep.Var.Name & Dep.Var.Name & Dep.Var.Name & Dep.Var.Name & \(\Delta\)Dep.Var.Name & \(\Delta\)Dep.Var.Name \\ \hline
                     &          &                    &          &          & \\          
     LONG NAME FE            & Yes      & No                 & Yes      & Yes      & Yes      & Yes      & No                 & No                 \\ \hline
     \multicolumn{9}{c}{ Robust standard errors in parentheses} \\
     \multicolumn{9}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
     \end{tabular}
\end{table} 
\end{document}
2
  • Welcome to TeX.SX! Not related to your problem, but I believe you are missing a \\ before LONG NAME FE
    – Runar
    Jul 7 '16 at 14:31
  • your right, corrected it
    – Peter
    Jul 7 '16 at 14:39
1

The simple way to put it is that \caption likes to be inside a minipage. BTW, I modified "Dep.Var.Name." to fit the p{} field.

I take it all those packages are there to test compatibility?

\documentclass[a4paper,10pt]{article}
 \usepackage[margin=3cm]{geometry}
 \usepackage{amssymb,amsmath, array, float, subfig}
 \usepackage{ragged2e, setspace}
 \usepackage{longtable}
 \usepackage{pdflscape}
 \usepackage{graphicx, natbib, cite}
 \usepackage[utf8]{inputenc}
 \usepackage{caption} 
 \usepackage{tabularx}
 \usepackage{afterpage}


\begin{document}
\begin{table}
\hspace*{\dimexpr -\oddsidemargin-1in}\rlap{\begin{minipage}{\paperwidth}
\caption{Title\\ \small Columns 1 and 2 show the effect of blablablalab}
\centering
    \begin{tabular}[]{p{2,15cm}p{1.45cm} p{1.45cm} p{1.45cm} p{1.45cm} p{1.45cm} p{1.45cm} p{1.45cm} p{1.45cm}} \hline
                     & (1)      & (2)                & (3)      & (4)      & (5)      & (6)      & (7)                & (8)                \\
     Dep. Var. Name                & Dep. Var. Name & $(\Delta)$Dep. Var. Name & Dep. Var. Name & Dep. Var. Name & Dep. Var. Name & Dep. Var. Name & $(\Delta)$Dep. Var. Name & $(\Delta)$Dep. Var. Name \\ \hline
                     &          &                    &          &          & \\          
     LONG NAME FE            & Yes      & No                 & Yes      & Yes      & Yes      & Yes      & No                 & No                 \\ \hline
     \multicolumn{9}{c}{ Robust standard errors in parentheses} \\
     \multicolumn{9}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
     \end{tabular}
\end{minipage}}
\end{table} 
\end{document}

full width of page

1

This isn't exactly a solution to your problem, but a suggestion on how you could improve the look of it, and make it fit into the text. I realise this may not be something that you can use, but I don't think you should violate the margins.

  • Remove the repeating header title Variable, as it is already in the leftmost header. I don't see a reason for repeating it in every row.
  • Instead of specifying the width of every row, just use c or l here. Also, for many rows of the same type, the syntax *{num}{type} makes it a lot clearer.
  • Use \cemtering inside the table environment. Of course, if you really want the table to span outside margins, there is no point in this suggestion.
  • Are you really using all these different and very related packages? Consider sticking to a certain style. Be consistent everywhere. Remove unused packages.
  • Consider using booktabs-style. You are already creating better-looking tables than most, as you are not using vertical lines. Many think that some horizontal lines of different weight improve the look and readability. booktabs can help in keeping consistent line weights for all tables, by using \toprule,\midrule and \bottomrule.

Output

enter image description here

Code

\documentclass[a4paper,10pt]{article}
\usepackage[margin=3cm]{geometry}
%\usepackage{amssymb,amsmath, float, subfig}
%\usepackage{ragged2e, setspace}
%\usepackage{longtable}
%\usepackage{pdflscape}
%\usepackage{graphicx, natbib, cite}
\usepackage[utf8]{inputenc}
\usepackage{caption} 
%\usepackage{tabularx}
%\usepackage{afterpage}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering

\caption{Local leverage\\ \small Columns 1 and 2 show the effect of blablablalab}
    \begin{tabular}{l *{8}{c}} 
    \toprule

     Variables      & (1)       & (2)\(\Delta\) & (3)       & (4)       & (5)      & (6)      & (7)\(\Delta\)       & (8)\(\Delta\)      \\   
     Long Name Fe   & Yes       & No            & Yes       & Yes       & Yes      & Yes      & No                  & No                 \\ 
     \bottomrule
     \addlinespace
     \multicolumn{9}{c}{ Robust standard errors in parentheses} \\
     \multicolumn{9}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
     \end{tabular}
\end{table} 
\end{document}
1
  • Sorry, still learning LaTeX. Everytime I run into a problem someone suggests some new package. Thanks for the suggestions.
    – Peter
    Jul 7 '16 at 15:05
1

Just changing the horizontal margin to 2.5cm, it can fit text width using tabularx and threeparttable:

\documentclass[a4paper, 10pt]{article}
 \usepackage[hmargin=2.5cm, vmargin=3cm, showframe]{geometry}
 \usepackage{amssymb,amsmath, array, float, subfig}
 \usepackage{ragged2e, setspace}
 \usepackage{pdflscape}
 \usepackage{graphicx, natbib, cite}
 \usepackage[utf8]{inputenc}
 \usepackage{caption}
 \usepackage{tabularx, booktabs}
 \usepackage[flushleft]{threeparttable} \usepackage{afterpage}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{threeparttable}[flushleft]
\setlength\tabcolsep{3pt}\renewcommand\arraystretch{1.3}
\caption{Title\\ \small Columns 1 and 2 show the effect of blablablalab}
    \begin{tabularx}{\linewidth}{>{\hsize=1.8\hsize\raggedright}X *{8}{>{\hsize=0.9\hsize}X}}%
     \toprule
    & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\
    Dep.Var.Name & Dep.Var.\newline Name & $ \Delta $Dep.\newline Var.Name & Dep.Var.\newline Name & Dep.Var.\newline Name & Dep.Var.\newline Name & Dep.Var.\newline Name & \(\Delta\)Dep.\newline Var.Name & \(\Delta\)Dep.\newline Var.Name \\
    \midrule
 LONG NAME FE & Yes & No & Yes & Yes & Yes & Yes & No & No \\
\bottomrule
\addlinespace
     \end{tabularx}
\begin{tablenotes}
\small
  \item[]Robust standard errors in parentheses
\item[]*** p${}<0.01$, ** p$ {}<0.05$, * p${}<0.1$
\end{tablenotes}
\end{threeparttable}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.