3

Good morning, i tried to figure out the problem by searching on my own. I indeed found some postings, but unfortunately I was not able to solve my problem. I have a table that has too large width to fit the page. However, I have an economics paper that I work on that has the exact same figure in it that perfectly fits the page.

Here is my code:

\documentclass [a4paper,12 pt]{article}
\usepackage{tabu}
\usepackage{longtable}

\begin{document}

{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{longtabu}to \linewidth {l*{8}{X}}
\caption{Relation between Average Annual Wages in USD and selected Indicators}\\
\hline\hline\endfirsthead\hline\endhead\hline\endfoot\endlastfoot
            &&&\multicolumn{1}{c}{TFP\_OLSFE}&&&\multicolumn{1}{c}{TFP\_OP}\\
            &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}&\multicolumn{1}{c}{(8)}\\
\hline
comp\_herfsubsidy&      0.0382\sym{***}& &  &      0.0309\sym{***}&      0.0430\sym{***}&              &  &      0.0343\sym{***}\\
            &   (0.00911)         &                     &                     &   (0.00726)         &    (0.0103)         &                     &                     &   (0.00827)         \\
[1em]
cor\_subsidy\_lerner&     0.00433         &                     &                     &    0.000921         &     0.00307         &                     &                     &    0.000547         \\
            &   (0.00353)         &                     &                     &   (0.00365)         &   (0.00354)         &                     &                     &   (0.00373)         \\
[1em]
cor\_tariff\_lerner&     -0.0157         &    -0.00164         &    -0.00769         &    -0.00951         &    -0.00643         &     0.00341         &    -0.00351         &     0.00185         \\
            &    (0.0129)         &   (0.00900)         &   (0.00972)         &    (0.0130)         &    (0.0136)         &   (0.00983)         &    (0.0107)         &    (0.0137)         \\
[1em]
lerner      &       13.38\sym{*}  &       10.75\sym{**} &       11.09\sym{**} &       12.69\sym{*}  &       16.66\sym{*}  &       10.79\sym{*}  &       11.36\sym{*}  &       15.58\sym{*}  \\
            &     (5.570)         &     (3.677)         &     (3.692)         &     (5.403)         &     (7.416)         &     (4.242)         &     (4.297)         &     (7.268)         \\
[1em]
lernersquare&      -7.645\sym{*}  &      -6.139\sym{**} &      -6.338\sym{**} &      -7.290\sym{*}  &      -9.061\sym{*}  &      -5.945\sym{*}  &      -6.264\sym{*}  &      -8.494\sym{*}  \\
            &     (3.056)         &     (2.029)         &     (2.040)         &     (2.967)         &     (4.064)         &     (2.379)         &     (2.412)         &     (3.987)         \\
\hline
\(N\)       &     1088635         &     1203999         &     1278474         &     1007014         &     1088635         &     1203999         &     1278474         &     1007014         \\
adj. \(R^{2}\)&       0.214         &       0.218         &       0.214         &       0.220         &       0.183         &       0.189         &       0.185         &       0.189         \\
\hline\hline
\multicolumn{9}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{9}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{longtabu}
}

\end{document}

The longtable looks a bit weird to me - especially the code in the beginning - but this is the case because i use STATA to compute the values and generate the longtable. However, I have changed the line with \begin{longtabu} since i have tried the solution from here: Set longtable to fit the page-width Now the columns just overlap and I dont know what to do.

Thank you for your help!

edit: enter image description here

Maurer
  • 31
  • 2
    This can't fit with this fontsize. Beside this: better don't use tabu, see the readme here https://github.com/tabu-issues-for-future-maintainer/tabu. – Ulrike Fischer Jul 23 '19 at 09:35
  • You are right. It is simply not possible to fix the fontsize and enlarge the width of a table together infinitly. I thought that using tabu would alter the fontsize ones it realizes that the table wont fit the predefined specification (here: textwidth) otherwise. Obviously, it doesnt. Thank youf for the link, I should think of some other solution – Maurer Jul 23 '19 at 18:07

2 Answers2

2

I suggest using the landscape environment, and the xltabular and threeparttablex packages. The former brings the functionalities of longtable to tabularx, the latter is an extension of threeparttable, with a slightly different syntax, which makes table notes available in longtable. I also used `siunitx for an alignment of the numbers on the decimal dot.

\documentclass [a4paper,12 pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xltabular}
\usepackage{threeparttablex}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{lscape}

\begin{document}

\begin{landscape}
\small
\setlength{\tabcolsep}{2pt}
\sisetup{table-format=-1.6,table-number-alignment=center, table-space-text-pre=(, table-space-text-post=\tnote{***}, table-align-text-pre=false, table-align-text-post=false}
\begin{ThreePartTable}
\begin{TableNotes}[para, flushleft]
\smallskip
\footnotesize \item[]Standard errors in parentheses:
\item[*]\(p<0.05\),
\item[**]\(p<0.01\),
\item[***]\(p<0.001\).
\end{TableNotes}
\begin{xltabular}{\linewidth} {X*{8}{S}}
\caption{Relation between Average Annual Wages in USD and selected Indicators}\\
\toprule\endfirsthead\midrule\endhead\midrule\endfoot\endlastfoot
cor\_subsidy\_lerner & 0.00433 & & & 0.000921 & 0.00307 & & & 0.000547 \\
 & {(}0.00353{)} & & & {(}0.00365{)} & {(}0.00354{)} & & & {(}0.00373{)} \\
[1em]
cor\_tariff\_lerner& -0.0157 & -0.00164 & -0.00769 & -0.00951 & -0.00643 & 0.00341 & -0.00351 & 0.00185 \\
 & {(}0.0129{)} & {(}0.00900{)} & {(}0.00972{)} & {(}0.0130{)} & {(}0.0136{)} & {(}0.00983{)} & {(}0.0107{)} & {(}0.0137{)} \\
[1em]
lerner & 13.38\tnote{*} & 10.75\tnote{**} & 11.09\tnote{**} & 12.69\tnote{*} & 16.66\tnote{*} & 10.79\tnote{*} & 11.36\tnote{*} & 15.58\tnote{*} \\
 & {(}5.570{)} & {(}3.677{)} & {(}3.692{)} & {(}5.403{)} & {(}7.416{)} & {(}4.242{)} & {(}4.297{)} & {(}7.268{)} \\
[1em]
lernersquare& -7.645\tnote{*} & -6.139\tnote{**} & -6.338\tnote{**} & -7.290\tnote{*} & -9.061\tnote{*} & -5.945\tnote{*} & -6.264\tnote{*} & -8.494\tnote{*} \\
 & {(}3.056{)} & {(}2.029{)} & {(}2.040{)} & {(}2.967{)} & {(}4.064{)} & {(}2.379{)} & {(}2.412{)} & {(}3.987{)} \\
\midrule
\(N\) & \num{1088635} & \num{1203999} & \num{1278474} & \num{1007014} & \num{1088635} & \num{1203999} & \num{1278474} & \num{1007014} \\
adj. \(R^{2}\)& 0.214 & 0.218 & 0.214 & 0.220 & 0.183 & 0.189 & 0.185 & 0.189 \\
\bottomrule
\insertTableNotes
\end{xltabular}
\end{ThreePartTable}
\end{landscape}

\end{document} 

enter image description here

Edit: a proposition for a portrait layout:

\documentclass [a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[showframe]{geometry} 
\usepackage{xltabular}
\usepackage{threeparttablex}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[svgnames, table]{xcolor}
\usepackage{lscape}

\begin{document}

\vspace*{2\baselineskip}

\begin{ThreePartTable}
\footnotesize
\setlength{\tabcolsep}{2pt}
\sisetup{table-format=-1.6,table-number-alignment=center, table-space-text-pre=(, table-space-text-post=\tnote{***}, table-align-text-pre=false, table-align-text-post=false}
\captionsetup{font={footnotesize, sc}, labelsep=endash, skip=5pt}
\begin{TableNotes}[para, flushleft]
\smallskip
\footnotesize \item[]Standard errors in parentheses:
\item[*]\(p<0.05\),
\item[**]\(p<0.01\),
\item[***]\(p<0.001\).
\end{TableNotes}
\begin{xltabular}{\linewidth} {X*{8}{S}}
\caption{Relation between Average Annual Wages in USD and selected Indicators}\\
\toprule \arrayrulecolor{Gainsboro!75}\specialrule{\aboverulesep}{-\belowrulesep}{-\aboverulesep} \arrayrulecolor{black} \midrule\endfirsthead\midrule\endhead\midrule\endfoot\endlastfoot
 \multicolumn{2}{l}{cor\_subsidy\_lerner}& & & & & & \\
 & 0.00433 & & & 0.000921 & 0.00307 & & & 0.000547 \\
 & {(}0.00353{)} & & & {(}0.00365{)} & {(}0.00354{)} & & & {(}0.00373{)} \\
 [1.5ex]
 \multicolumn{2}{l}{cor\_tariff\_lerner} & & & & & & \\
 & -0.0157 & -0.00164 & -0.00769 & -0.00951 & -0.00643 & 0.00341 & -0.00351 & 0.00185 \\
 & {(}0.0129{)} & {(}0.00900{)} & {(}0.00972{)} & {(}0.0130{)} & {(}0.0136{)} & {(}0.00983{)} & {(}0.0107{)} & {(}0.0137{)} \\[1.5ex]
 \multicolumn{1}{l}{lerner} & 13.38\tnote{*} & 10.75\tnote{**} & 11.09\tnote{**} & 12.69\tnote{*} & 16.66\tnote{*} & 10.79\tnote{*} & 11.36\tnote{*} & 15.58\tnote{*} \\
 & {(}5.570{)} & {(}3.677{)} & {(}3.692{)} & {(}5.403{)} & {(}7.416{)} & {(}4.242{)} & {(}4.297{)} & {(}7.268{)} \\[1.5ex]
 %
 \multicolumn{2}{l}{ lernersquare}\\& -7.645\tnote{*} & -6.139\tnote{**} & -6.338\tnote{**} & -7.290\tnote{*} & -9.061\tnote{*} & -5.945\tnote{*} & -6.264\tnote{*} & -8.494\tnote{*} \\
 & {(}3.056{)} & {(}2.029{)} & {(}2.040{)} & {(}2.967{)} & {(}4.064{)} & {(}2.379{)} & {(}2.412{)} & {(}3.987{)} \\
 \midrule
 \(N\) & {\num{1088635}} & {\num{1203999}} & {\num{1278474}} & {\num{1007014}} & {\num{1088635}} & {\num{1203999}} & {\num{1278474}} & {\num{1007014}} \\
 adj. \(R^{2}\)& 0.214 & 0.218 & 0.214 & 0.220 & 0.183 & 0.189 & 0.185 & 0.189 \\
\bottomrule
\insertTableNotes
\end{xltabular}
\end{ThreePartTable}

\end{document} 

enter image description here

Bernard
  • 271,350
  • First of all, thank you for your fast answer! I have thought of using the landscape environment, too, and put it in the appendix of my work (I think it looks awkward within a scientific paper). However, I would like not to do so. For example, I dont like the numbering being turned to the side, too. However, this seems to be aminor problem that could be fixed. But the first best solution I am looking for is to have the table in "normal" page mode in my paper. Is there a solution to automatically fit the table to the page size (without taking care of the fontsize getting very small)? Thanks! – Maurer Jul 23 '19 at 18:13
  • I have attached a picture to the initial question that shows the table from the paper I am working on. This is what I was referring to as first best solution. – Maurer Jul 23 '19 at 18:21
  • I see. What are you layout dimensions (margins, text width, &c.)? I doubt this paper uses 12pt as the base font size. – Bernard Jul 23 '19 at 18:37
  • I use the article documentclass just like in my example. I have compared my work and the paper and they seem to use the same size. Only the fontsize of the table is obviously smaller. – Maurer Jul 23 '19 at 18:58
  • I already reduced it w.r.t. to the declared 12pt. I can reduce more, but should have the geometry of the page. – Bernard Jul 23 '19 at 19:26
  • I dont set any other options other than the documentclass. I am struggling to find out the default values for a4paper + article configuration. Do you have an idea how to find out? – Maurer Jul 23 '19 at 19:45
  • The default margins are very wide (they account for marginal notes), which real articles in journals do not have). Even reducing the fontsize to \footnotesize, with tabularx, the first column overlaps the 2nd column when not in landscape. – Bernard Jul 23 '19 at 19:49
  • But then I really dont understand how they have made it in the paper. I updated the photo once again where you can see the left and right margins (even if it is hard to see). It seems to work and the size difference to the normal text isnt that large. At least the numbers are clearly readable. Is it smaller as footnotesize? Otherwise I must miss something. However, thanks again for your help! – Maurer Jul 23 '19 at 20:01
  • I'll post a proposition in portrait orientation in a moment. – Bernard Jul 23 '19 at 20:35
  • @Maurer: I've posted a new (portrait) code. Is it closer to what you want? – Bernard Jul 23 '19 at 21:37
  • Indeed, it is. Maybe this is the closest I can get to the original one. I will think of how I finally will integrate the table. Thank you very much for your help. Since it was my first time posting a question, I can only tell good things about it. – Maurer Jul 23 '19 at 22:13
  • Thanks. It's a pleasure to help! – Bernard Jul 23 '19 at 22:22
1
  • If your table content is only what you show in your MWE, than you not need longtable, sufficient is tabular environment.
  • instead X column type I suggest to use the S column type defined in the siunitx package
  • your table is to wide that can be fir in text width. I would consider to the `landcsape oriented table. This cab be obtain with:
    • use pdflscape package (as used in MWE below), or
    • use of sideways table defined in the rotating package

MWE:

\documentclass [a4paper,12 pt]{article}
\usepackage{pdflscape}
\usepackage{booktabs}
\usepackage[referable]{threeparttablex}
\usepackage{siunitx}

\usepackage{lipsum} % for dummy text
\begin{document}

\begin{landscape}
\small
\setlength\tabcolsep{0pt}
\centering
\sisetup{input-symbols = {( )},
         table-space-text-pre={(},
         table-space-text-post={$^{***}$},
         table-align-text-post=false,
         table-format=-1.5
        }
\begin{threeparttable}[ht]
\caption{Relation between Average Annual Wages in USD and selected Indicators}

\begin{tabular*}{\linewidth} {@{\extracolsep{\fill}} l*{8}{S} @{}}
    \toprule
    &   \multicolumn{4}{c}{TFP\_OLSFE}      &    \multicolumn{4}{c}{TFP\_OP}    \\
    \cmidrule(lr){2-5}\cmidrule(lr){6-9}
    & {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} & {(7)} & {(8)}             \\
    \midrule
comp\_herfsubsidy
    & 0.0382\tnote{***} & & & 0.0309\tnote{***} & 0.0430\tnote{***} & & & 0.0343\tnote{***} \\
    & (0.00911)        & & & (0.00726)        & (0.0103)         & & &(0.00827)         \\
    \addlinespace
cor\_subsidy\_lerner
    & 0.00433          & & & 0.000921         & 0.00307          & & & 0.000547         \\
    & (0.00353)        & & & (0.00365)        & (0.00354)        & & & (0.00373)        \\
    \addlinespace
cor\_tariff\_lerner
    & -0.0157 &-0.00164   & -0.00769  & -0.00951 & -0.00643 & 0.00341   & -0.00351 & 0.00185    \\
    & (0.0129)& (0.00900) & (0.00972) & (0.0130) & (0.0136) & (0.00983) & (0.0107) & (0.0137)   \\
    \addlinespace
lerner      
    & 13.38\tnote{*} & 10.75\tnote{**} & 11.09\tnote{**} & 12.69\tnote{*}
    & 16.66\tnote{*} & 10.79\tnote{*}  & 11.36\tnote{*}  & 15.58\tnote{*}   \\
    & (5.570)       & (3.677)        & (3.692)        & (5.403)         
    & (7.416)       & (4.242)        & (4.297)        & (7.268)         \\
    \addlinespace
lernersquare
    & -7.645\tnote{*} & -6.139\tnote{**} & -6.338\tnote{**} & -7.290\tnote{*}
    & -9.061\tnote{*} & -5.945\tnote{*}  & -6.264\tnote{*}  & -8.494\tnote{*}  \\
    & (3.056)         & (2.029)          & (2.040)          & (2.967)        
    & (4.064)         & (2.379)          & (2.412)          & (3.987)         \\
    \midrule
\(N\)       
    & \num{1088635}   & \num{1203999}    & \num{1278474}    & \num{1007014} 
    & \num{1088635}   & \num{1203999}    & \num{1278474}    & \num{1007014}          \\
adj. \(R^{2}\)
    & 0.214           & 0.218            & 0.214            & 0.220         
    & 0.183           & 0.189            & 0.185            & 0.189            \\
    \bottomrule
\end{tabular*}
\begin{tablenotes}[flushleft]\footnotesize
\note \lipsum[1]

\item[*]    Significant at \SI{10}{\%} level
\item[**]   Significant at \SI{5}{\%} level
\item[***]     Significant at \SI{1}{\%} level
\end{tablenotes}
\end{threeparttable}
\end{landscape}

\end{document}

enter image description here

Zarko
  • 296,517
  • With some minor changes, this is exactly what I was looking for. I just changed the \small to \tiny, erased the landscape mode and I have put your adjusted code into my document (which has for some reasons smaller margin gaps) et voilà - it looks exactly the way it should! Thank all of you very much! You have erased one (unfortunately out of the many) of my stress factors in writing my bachelors thesis. – Maurer Jul 24 '19 at 20:53