Graphics, Figures & Tables"Floating" longtable, float, and afterpage placement issue

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

"Floating" longtable, float, and afterpage placement issue

Post by cbkschroeder »

Hi,

Thanks for reading my inquiry.

My issue concerns (sideways / landscape) longtable, the afterpage package, and (figure) float placement. In particular, the latter seems to behave in what is, for me at the moment, an undesireable manner.

Having encountered the need to include a large landscape table in my work, and wishing that table to "float", I have explored several alternatives. The rotating package is excellent, for example. Its tables "float" very well; unfortunately - and nobody claims it's supposed to do this - it cannot break tables across pages. The other alternative I have explored is the lscape / pdflscape package with longtable. This combination generates great landscape tables broken across pages, but it does not permit text to "flow" around the table. Enter the afterpage package. I have found several examples of concerns such as mine resolved with this package. Some examples:

http://tex.stackexchange.com/questions/ ... learing-th

http://tex.stackexchange.com/questions/ ... scape-page

http://www.latex-community.org/forum/vi ... age#p53422

http://www.latex-community.org/forum/vi ... cape#p8882

So the above examples seem to work very well when only text surrounds that "floating" longtable. My problem enters when what follows the table are numerous, 1-page each, (floating) figures. To start, I'll adapted an example from the above with bold and italics (I can't yet read latin) to generate the following:

Code: Select all

\documentclass{article}
\usepackage{array,longtable,lipsum,afterpage,pdflscape}
\begin{document}
\textbf{\lipsum[1]}
\afterpage{
\begin{landscape}
\begin{longtable}{|c|>{\raggedright}p{0.7\linewidth}|}
  \hline
  A & \lipsum[1] \tabularnewline \hline
  B & \lipsum[2] \tabularnewline \hline
  C & \lipsum[3] \tabularnewline \hline
  D & \lipsum[4] \tabularnewline \hline
\end{longtable}
\end{landscape}
}
\textit{\lipsum[2-8]}
\end{document}
This generates:
mwe 00.pdf
(49.76 KiB) Downloaded 564 times
This works perfectly in wrapping text around a floating multi-page table though, in digression, I am left curious as to why the table text is italic. Anyway, extending to my situation:

Code: Select all

\documentclass{article}
\usepackage{array,longtable,lipsum,afterpage,pdflscape}
\begin{document}
\textbf{\lipsum[1]}
\afterpage{
\begin{landscape}
\begin{longtable}{|c|c|>{\raggedright}p{0.7\linewidth}|}
  \hline
 Figure \ref{fig:first}  & A & \lipsum[2] \tabularnewline \hline
 Figure \ref{fig:second} & B & \lipsum[3] \tabularnewline \hline
 Figure \ref{fig:third}  & C & \lipsum[4] \tabularnewline \hline
 Figure \ref{fig:fourth} & D & \lipsum[5] \tabularnewline \hline
\end{longtable}
\end{landscape}
}
\begin{figure}
\caption{First}
\label{fig:first}
\vspace{6in} %%%%%%%%%%% make a full-page "dummy figure"
\end{figure}
\begin{figure}
\caption{Second}
\label{fig:second}
\vspace{6in} %%%%%%%%%%% make a full-page "dummy figure"
\end{figure}
\begin{figure}
\caption{Third}
\label{fig:third}
\vspace{6in} %%%%%%%%%%% make a full-page "dummy figure"
\end{figure}
\begin{figure}
\caption{Fourth}
\label{fig:fourth}
\vspace{6in} %%%%%%%%%%% make a full-page "dummy figure"
\end{figure}
\textit{\lipsum[6-10]}
\end{document}
This generates:
mwe 01.pdf
(59.42 KiB) Downloaded 436 times
The issue for me is that the table comes after the figures; I desire the table to come before the figures. It seems as though latex seems to have an odd interpretation of what the end of a page really is. Has anyone any suggestions as to how I might re-arrange my content's order?

Thanks for your time,

Christian

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

"Floating" longtable, float, and afterpage placement issue

Post by cbkschroeder »

I stuggled with this one quite a while! Eventually, I contacted David Carlise; he was very kind to suggest simply including the remaining floats in \afterpage such as:

Code: Select all

\documentclass{article}
\usepackage{array,longtable,lipsum,afterpage,pdflscape}
\begin{document}
\textbf{\lipsum[1]}
\afterpage{
\begin{landscape}
\begin{longtable}{|c|c|>{\raggedright}p{0.7\linewidth}|}
  \hline
 Figure \ref{fig:first}  & A & \lipsum[2] \tabularnewline \hline
 Figure \ref{fig:second} & B & \lipsum[3] \tabularnewline \hline
 Figure \ref{fig:third}  & C & \lipsum[4] \tabularnewline \hline
 Figure \ref{fig:fourth} & D & \lipsum[5] \tabularnewline \hline
\end{longtable}
\end{landscape}
\begin{figure}
\caption{First}
\label{fig:first}
\vspace{6in} %%%%%%%%%%% make a full-page "dummy figure"
\end{figure}
\begin{figure}
\caption{Second}
\label{fig:second}
\vspace{6in} %%%%%%%%%%% make a full-page "dummy figure"
\end{figure}
\begin{figure}
\caption{Third}
\label{fig:third}
\vspace{6in} %%%%%%%%%%% make a full-page "dummy figure"
\end{figure}
\begin{figure}
\caption{Fourth}
\label{fig:fourth}
\vspace{6in} %%%%%%%%%%% make a full-page "dummy figure"
\end{figure}
}
\textit{\lipsum[6-10]}
\end{document}
This went a long way towards solving my problem; it wasn't perfect, however. I numerous cases I had an only very brief body of text following the above, and then several more figure floats. Upon compilation, I would find that those figure floats would be placed *before* all the stuff in the \afterpage argument. The solution to this was to place those floats in their own seperate \afterpage argument, as well.

Instead of generating numerous mwe's for problems nobody's had (yet), I'll add some additional point-form thoughts in case someone really gets stuck here:

- Even after doing the above, sometimes placement isn't quite what you want. Using the placeins package, one can place a \FloatBarrier command just before the termination of the argument of the \afterpage command, ie: \afterpage{ <Your Floats> \FloatBarrier}.

- Judicious placement of float placement modifiers such as [!tp] can really help, as well.

All the above is trial-and-error; it is frustratingly case-by-case, but one can get the placement one wants.

Good luck,

Christian
Post Reply