0

I am setting a figure in landscape and then two other figures in normal mode. However, the landscape figure goes between the normal figures and the numbering gets messed up, including in the table of contents. How do I avoid the numbers being in the wrong order?

Unfortunately, I was not able to create a minimal example where this happens. Here is the structure of what I am using:

\clearpage
\begin{landscape}
  % figure 2
\end{landscape}
% figure 1
% figure 3

I'll tried with and without \clearpage before and after the landscape environment.

Edit:

Due to the comment by David, I saw that it is actually the following that causes the problem:

\afterpage{
  \clearpage
  \begin{landscape}
    % figure 2
  \end{landscape}
}
% figure 1
% figure 3

Edit 2:

Finally, a minimal example:

\documentclass{article}
\usepackage{blindtext}
\usepackage{afterpage}
\usepackage{pdflscape}
\usepackage{float}
\begin{document}
\listoffigures
\clearpage
\blindtext[4]
\afterpage{
\begin{landscape}
\begin{figure}
... figure contents ...
\caption{Figure 1}
\end{figure}
\end{landscape}
}
\begin{figure}
... figure contents ...
\caption{Figure 2}
\end{figure}
\begin{figure}[H]
... figure contents ...
\caption{Figure 3}
\end{figure}
\blindtext[4]
\end{document}

Note: Removing the [H] option of the third figure produces a whole page for just one small figure which isn't desired.

Edit 3:

Removing the [H] option does not change the order of figures either.

Edit 4:

For reference, here is what seems to be the result I was looking for: https://tex.stackexchange.com/a/472608/36836

  • 1
    the \clearpage won't do anything as landscape does \clearpage itself but no floats should go out of sequence. Please show an example. – David Carlisle Jul 1 '18 at 19:47
  • @DavidCarlisle I totally agree with you that an example would be great. In particular if it is as you say and landscape should not make floats go out of sequence which might indicate that I have messed up my document in some other way. I cannot post my whole document here. But if I have managed to reproduce it in another example, I'll post it here... – Daniel Jul 2 '18 at 8:26
  • @DavidCarlisle Okay great. Due to your hints, I think I found the culprit now. There is actually an \afterpage{...} surrounding the landscape environment (including the \clearpage!) - I guess to not cut off a page suddenly. Moving the \clearpage in front of the \afterpage command does the trick. Is this the way to go? – Daniel Jul 2 '18 at 9:15
  • 1
    well since the whole purpose of \afterpage is to move things out of sequence than yes it will move things out of sequence. Almost certainly not using \afterpage is the way to go but hard to say in general. – David Carlisle Jul 2 '18 at 10:00
  • @DavidCarlisle My purpose of using \afterpage was to get the text before and after a landscape page to "float" nicely so to not get any larger vertical space. Do you know of a better alternative to this? – Daniel Jul 2 '18 at 11:58
1

I'm not exactly sure what do you want to achieve? Do you want the figures not to change their position in text? Or do you want to change the numbering so that fig 1 will be on the first page, fig 3 on the second (landscape page) and then fig 2 on the third page?

In case 1 you can use the float package which adds an option [H] (uppercase H instead of default latex lowercase h). It forces the float to stay exactly where it is put in the text. The code will look like this:

\begin{figure}[H] 
%figure
\end{figure}

Regarding case 2, you can change the numbering of the figures by changing the figure counter like this:

%figure1
\addtocounter{figure}{1}
%figure3
\addtocounter{figure}{-2}
%figure2
\addtocounter{figure}{1}

Then you'll have first figure 1 then figure 3 then figure 2 then figure 4, 5, 6...

  • Thanks. I have tried to correct my vague comment. I actually tried to achieve case 2. However, it would be great of course if I would not have to handle the numbering manually. – Daniel Jul 2 '18 at 8:22
  • 1
    Note that while the form shown in the question should not ever make floats go out of sequence using [H] makes the figure a non-float and so it can then get out of sequence with floats which may float past it unless you use \clearpage to stop them (or correct the numbering by hand) – David Carlisle Jul 2 '18 at 9:01
  • @DavidCarlisle: Figures go out of sequence independently of the [H] option. But I would like them to appear in sequence hence correcting numbering by hand does not solve the problem. – Daniel Jan 23 at 12:40
0

LaTeX will keep floats in order but...

If you use afterpage the latex commands are only interpreted hen the delayed text is inserted so that figure is figure 2, so in that case the numbering and ordering (as seen in the table of contents) is correct it is just the caption text is wrong. But presumably no real caption would be "figure two" in words.

The situation with [H] is different. If you use [H] then you are asserting manual control and that figure will not move, even if other figures float past it, in that case it is your responsibility to force the correct float numbering.

I don't think you need \afterpage or [H] here (I'm somewhat responsible for both those things and I wouldn't use them here) Just allow Latex to number floats as usual.

\documentclass{article}
\usepackage{blindtext}
\usepackage{pdflscape}
\usepackage{float}
\usepackage{rotating}
\begin{document}
\listoffigures
\clearpage
\blindtext[4]
\begin{sidewaysfigure}
... figure contents ...
\caption{Figure 1}
\end{sidewaysfigure}
\begin{figure}
... figure contents ...
\caption{Figure 2}
\end{figure}
\begin{figure}
... figure contents ...
\caption{Figure 3}
\end{figure}
\blindtext[4]
\end{document}
  • Thanks. However, first, the captions going the wrong way around is just a symptom of the problem. The problem is that the order in which figures appear is changed. For example, if I reference the figures in text I would like them to appear in order I reference them first without having to fiddle around with their placement manually. Second, as for your proposed solution of using sidewaysfigure it does not put the pages in landscape which makes it non-ideal for online reading. – Daniel Jan 23 at 13:23
  • @Daniel the order hasn't changed by accident or due to some subtle interaction, it has been explicitly delayed and is not inserted until later as you wrapped it in \afterpage I am not sure what else you would expect it to do? the content of \afterpage isn't evaluated at all, it's just as if you used it in \newcommand\tmp{\begin{figure}......} and then \tmp gets used later in the document (in fact that is essentially exactly what does happen) – David Carlisle Jan 23 at 13:27
  • I was hoping that \afterpage could help me to get the following: 1. figures on pages in landscape, and 2. figures in the order they are inserted. So, if I understand you correctly, \afterpage cannot be used for this since it fails to deliver 2. So, I am still searching for a solution to getting both 1 and 2 done. 1 and 2 together seems like the obvious things one would want when creating landscape figures for online reading. – Daniel Jan 23 at 13:36
  • @Daniel it delivers 2 if you understand "inserted" the way tex understands it, \afterpage stores the argument in a macro and inserts it later it's just as if you have defined \tmpfiga and \tmpfigb in the preamble, The place and order that the macro is defined is not recorded by TeX, what matters is where it is used (which in this case is at the top of the next page, after the other figure has already been set as figure 1) – David Carlisle Jan 23 at 14:50
  • I am not sure I can follow you. My point was: TeX normally shows figures in the order I write them in the document using the figure environment. That makes sense since then one can make sure one references them in the right order. This works also with sidewaysfigure. But I am looking for a way to get the order as expected and the figures on a landscape page. None of the answers suggested achieve this. – Daniel Jan 24 at 13:25

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.