2

I've created some tabular output through Python (pandas database). However, it leaves a too wide space between columns 2,3 (for which I cannot detect the reason), and actually overflowing the page width.

Sample code is below

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = pdflatexmk
\documentclass[11pt]{article}
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   % ... or a4paper or a5paper or ... 

\usepackage{booktabs}

\usepackage{longtable}

\begin{document}

\begin{longtable}{lrrrrrrrrrrrrrr}
\toprule
{} &     $\underline Y$ &   $\bar Y $ &  $\epsilon$ &   $\bar p$ &    $\underline s$ &  $\bar s$ &   $\theta$ &  $\underline\theta$ &  $\bar\theta$ &      u &     $\underline v$ &   $\bar v$ &     $\underline w$ &   $\bar w$ \\
\midrule
\endhead
\midrule
\multicolumn{3}{r}{{Continued on next page}} \\
\midrule
\endfoot

\bottomrule
\endlastfoot
0 &  0.532 &  0.394 &      1.0 &  1.349 &  0.20 &  0.40 &  32.223 &  12.978 &    19.245 &  0.074 &  0.960 &  1.424 &  0.423 &  0.458 \\
1 &  0.603 &  0.317 &      1.0 &  1.901 &  0.15 &  0.65 &  38.459 &  11.728 &    26.731 &  0.079 &  0.928 &  2.115 &  0.485 &  0.576 \\
2 &  0.566 &  0.361 &      0.5 &  1.253 &  0.20 &  0.40 &  30.642 &  13.475 &    17.167 &  0.073 &  0.986 &  1.256 &  0.407 &  0.433 \\
3 &  0.504 &  0.422 &      2.0 &  1.428 &  0.20 &  0.40 &  33.573 &  12.558 &    21.015 &  0.075 &  0.937 &  1.568 &  0.437 &  0.479 \\
\end{longtable}


\end{document}

table screenshot

5

Since your table has fifteen [15!] columns, reducing the value of \tabcolsep -- the parameter that governs the amount of intercolumn whitespace -- is helpful.

In the following example, the thin line above the table is inserted just to illustrate the width of the text block.

enter image description here

\documentclass[11pt]{article}
\usepackage{geometry} 
\geometry{letterpaper,margin=1in} 
\usepackage{booktabs,longtable}
\begin{document}

{\setlength\tabcolsep{3.5pt} % default value: 6pt
\begin{longtable}{@{} l *{14}{r} @{}}
\toprule
& $\underline Y$ & $\bar Y $ & $\epsilon$ & $\bar p$ & $\underline s$ & $\bar s$ & $\theta$ & $\underline\theta$ & $\bar\theta$ & u & $\underline v$ & $\bar v$ & $\underline w$ & $\bar w$ \\
\midrule
\endhead
\midrule
\multicolumn{15}{r}{Continued on next page} \\
\endfoot
\bottomrule
\endlastfoot
0 & 0.532 & 0.394 & 1.0 & 1.349 & 0.20 & 0.40 & 32.223 & 12.978 & 19.245 & 0.074 & 0.960 & 1.424 & 0.423 & 0.458 \\
1 & 0.603 & 0.317 & 1.0 & 1.901 & 0.15 & 0.65 & 38.459 & 11.728 & 26.731 & 0.079 & 0.928 & 2.115 & 0.485 & 0.576 \\
2 & 0.566 & 0.361 & 0.5 & 1.253 & 0.20 & 0.40 & 30.642 & 13.475 & 17.167 & 0.073 & 0.986 & 1.256 & 0.407 & 0.433 \\
3 & 0.504 & 0.422 & 2.0 & 1.428 & 0.20 & 0.40 & 33.573 & 12.558 & 21.015 & 0.075 & 0.937 & 1.568 & 0.437 & 0.479 \\
\end{longtable}
} % end of scope of "\setlength\tabcolsep{3.5pt} "
\end{document}
3

First of all to suppress the white, since the Continued on next page text is right-aligned, you must use \multicolumn{total number of columns}.

This being settled you can either use the landscape environment and keep defaul spacing parameters, or reduce tabcolsep and/or font size. Here is a code that shows both results.

I also replaced the \bar accent (too small for capital letters) with \widebar, borrowed from the mathabx fonts (package not loaded, as it interferes with default maths fonts).

\documentclass[11pt]{article}

\usepackage{geometry} % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper, showframe, nomarginpar} % ... or a4paper or a5paper or ...%
\usepackage{lscape}
\usepackage{array, booktabs}
\usepackage{longtable}

\DeclareFontFamily{U}{mathx}{\hyphenchar\font45}
\DeclareFontShape{U}{mathx}{m}{n}{
<-6> mathx5 <6-7> mathx6 <7-8> mathx7
<8-9> mathx8 <9-10> mathx9
<10-12> mathx10 <12-> mathx12
}{}
\DeclareSymbolFont{mathx}{U}{mathx}{m}{n}
\DeclareFontSubstitution{U}{mathx}{m}{n}
\DeclareMathAccent{\widebar}{0}{mathx}{"73}

\begin{document}

{\setlength\tabcolsep{3.7pt}\small
\begin{longtable}{l*{14}{r}}
\toprule
{} & $ \underline {Y\!}$ & $ \widebar Y $ & $\epsilon$ & $\widebar p$ & $\underline s$ & $\widebar s$ & $ θ $ & $\underline θ $ & $\widebar\theta$ & u & $\underline v$ & $\widebar v$ & $\underline w$ & $\widebar w$ \\
\midrule
\endhead
\midrule
\multicolumn{15}{r}{{Continued on next page}} \\
\midrule
\endfoot
\bottomrule
\endlastfoot
0 & 0.532 & 0.394 & 1.0 & 1.349 & 0.20 & 0.40 & 32.223 & 12.978 & 19.245 & 0.074 & 0.960 & 1.424 & 0.423 & 0.458 \\
1 & 0.603 & 0.317 & 1.0 & 1.901 & 0.15 & 0.65 & 38.459 & 11.728 & 26.731 & 0.079 & 0.928 & 2.115 & 0.485 & 0.576 \\
2 & 0.566 & 0.361 & 0.5 & 1.253 & 0.20 & 0.40 & 30.642 & 13.475 & 17.167 & 0.073 & 0.986 & 1.256 & 0.407 & 0.433 \\
3 & 0.504 & 0.422 & 2.0 & 1.428 & 0.20 & 0.40 & 33.573 & 12.558 & 21.015 & 0.075 & 0.937 & 1.568 & 0.437 & 0.479 \\
\end{longtable}
}
\clearpage
\newgeometry{showframe = false}
\begin{landscape}
\begin{longtable}{l*{14}{r}}
\toprule
{} & $ \underline {Y\!}$ & $ \widebar Y $ & $\epsilon$ & $\widebar p$ & $\underline s$ & $\widebar s$ & $ θ $ & $\underline θ $ & $\widebar\theta$ & u & $\underline v$ & $\widebar v$ & $\underline w$ & $\widebar w$ \\
\midrule
\endhead
\midrule
\multicolumn{15}{r}{{Continued on next page}} \\
\midrule
\endfoot
\bottomrule
\endlastfoot
0 & 0.532 & 0.394 & 1.0 & 1.349 & 0.20 & 0.40 & 32.223 & 12.978 & 19.245 & 0.074 & 0.960 & 1.424 & 0.423 & 0.458 \\
1 & 0.603 & 0.317 & 1.0 & 1.901 & 0.15 & 0.65 & 38.459 & 11.728 & 26.731 & 0.079 & 0.928 & 2.115 & 0.485 & 0.576 \\
2 & 0.566 & 0.361 & 0.5 & 1.253 & 0.20 & 0.40 & 30.642 & 13.475 & 17.167 & 0.073 & 0.986 & 1.256 & 0.407 & 0.433 \\
3 & 0.504 & 0.422 & 2.0 & 1.428 & 0.20 & 0.40 & 33.573 & 12.558 & 21.015 & 0.075 & 0.937 & 1.568 & 0.437 & 0.479 \\
\end{longtable}
\end{landscape}

\end{document} 

enter image description here

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.