When I have two floating environments on a page (one figure
and one table
), the longtable
can push the content below it into the bottom margin of the page. Here is a minimal example:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{lipsum}
\usepackage{longtable,booktabs}
\usepackage[demo]{graphicx}
\title{R Markdown v2 Demo}
\author{Li Lei \\ Han Meimei}
\date{2015/01/01}
\begin{document}
\maketitle
\lipsum
\begin{figure}
\includegraphics[width=0.5\linewidth]{foo-1}
\includegraphics[width=0.5\linewidth]{foo-2}
\caption{Two plots placed side by side.}
\end{figure}
\begin{longtable}[c]{lrrrrrrrrrrr}
\caption{A table of the first 10 rows of the mtcars
data.}\tabularnewline
\toprule
& mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear &
carb\tabularnewline
\midrule
Mazda RX4 & 21.0 & 6 & 160 & 110 & 3.90 & 2.620 & 16.46 & 0 & 1 & 4 &
4\tabularnewline
Mazda RX4 Wag & 21.0 & 6 & 160 & 110 & 3.90 & 2.875 & 17.02 & 0 & 1 & 4
& 4\tabularnewline
Datsun 710 & 22.8 & 4 & 108 & 93 & 3.85 & 2.320 & 18.61 & 1 & 1 & 4 &
1\tabularnewline
\bottomrule
\end{longtable}
\begin{table}
\caption{A Tale of Two Tables.}
\centering
\begin{tabular}{rr}
\toprule
Sepal.Length & Sepal.Width\\
\midrule
5.1 & 3.5\\
4.9 & 3.0\\
4.7 & 3.2\\
\bottomrule
\end{tabular}
\begin{tabular}{lrrr}
\toprule
& mpg & cyl & disp\\
\midrule
Mazda RX4 & 21.0 & 6 & 160\\
Mazda RX4 Wag & 21.0 & 6 & 160\\
Datsun 710 & 22.8 & 4 & 108\\
Hornet 4 Drive & 21.4 & 6 & 258\\
Hornet Sportabout & 18.7 & 8 & 360\\
\bottomrule
\end{tabular}
\end{table}
\lipsum
\end{document}
Here is a screenshot of the second page of the PDF created from pdflatex
:
If I remove the longtable
, the text can be correctly broken onto the next page. I wonder what the problem is in this document.
$ pdflatex --version
pdfTeX 3.14159265-2.6-1.40.16 (TeX Live 2015)
kpathsea version 6.2.1
Copyright 2015 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty. Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.6.17; using libpng 1.6.17
Compiled with zlib 1.2.8; using zlib 1.2.8
Compiled with xpdf version 3.04
EDIT (cfr)
Here's a more minimal example demonstrating the same problem. (Could probably be pared down further: I mostly tried to eliminate packages.)
\documentclass{article}
\usepackage{lipsum}
\usepackage{longtable}
\title{R Markdown v2 Demo}
\author{Li Lei}
\date{2015/01/01}
\begin{document}
\maketitle
\lipsum
\begin{figure}
ab
\caption{Two plots placed side by side.}
\end{figure}
\begin{longtable}[c]{lrrrrrrrrrrr}
\caption{A table of the first 10 rows of the mtcars
data.}\tabularnewline
\hline
& mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear &
carb\tabularnewline
\hline
Mazda RX4 & 21.0 & 6 & 160 & 110 & 3.90 & 2.620 & 16.46 & 0 & 1 & 4 &
4\tabularnewline
Mazda RX4 Wag & 21.0 & 6 & 160 & 110 & 3.90 & 2.875 & 17.02 & 0 & 1 & 4
& 4\tabularnewline
Datsun 710 & 22.8 & 4 & 108 & 93 & 3.85 & 2.320 & 18.61 & 1 & 1 & 4 &
1\tabularnewline
\hline
\end{longtable}
\begin{table}
\caption{A Tale of Two Tables.}
\centering
\begin{tabular}{rr}
\hline
Sepal.Length & Sepal.Width\\
\hline
5.1 & 3.5\\
4.9 & 3.0\\
4.7 & 3.2\\
\hline
\end{tabular}
\end{table}
\lipsum
\end{document}
Obviously, the spilling into the right margin is expected here as I've not adapted the table to the standard text width. But the spilling into the bottom presumably is not.
longtable
is rather small. Whylongtable
then?geometry
andgraphicx
.longtable
alone is sufficient to create the issue. (Unlesslipsum
is to blame which seems unlikely.)\@topnum=0
(\z@ is 0) now we can noticed that the problem still if the figure go to the bottom area so\@botnum\z@
. The conclusion (not very sure) if a longtable go in only one page, this page can't have floats in top or bottom. you can see this if you use\begin{figure}[hbp]