8

I know of two options to put figures in landscape.

The first is to use the sidewaysfigure environment. This works very well when it comes to keeping the sequence of figures. However, it leaves the page in portrait and turns the figure instead which makes it hard to read online. I also could not figure out how to put several figures (not sub-figures) on one page.

The second is to use a combination of the landscape environment and \afterpage. This works very well when it comes to showing pages in landscape with the figures easily readable. However, this messes up the sequence of floats. (See sidewaysfigure and landscape and, for the numbering problem, How to get landscape float with correct numbering?.)

Is there a proper way to get the best of both worlds, i.e. landscape pages while keeping the order of figures?

Note on the chosen solution

There are a couple of limitations with the chosen answer. On how to fix them see How to avoid additional page getting rotated?.

Daniel
  • 1,787

1 Answers1

8

Putting more than one figure in a sidewaysfigure is easy: the environment doesn't care how many \captions you add. So use minipage or whatever.

Rotating a page in the pdf viewer is rather easy too: one only need to add a bit of code to the page attributes.

The main problem is that sidewaysfigure is a float. So it is not straightforward to identify the page which needs the rotating code, and it is also not straightforward how to remove the code from the page attributes for the pages after the float has been placed. Answers like Rotate single PDF page when viewing ignore this problem by using hard coded \newpage commands.

One possible solution is to use labels to mark up the pages which should be rotated:

\documentclass{article}
\usepackage{rotating}
\usepackage{pdflscape,lipsum}
\usepackage{eso-pic,zref-user}
\newcounter{cntsideways}
\makeatletter
\AddToShipoutPictureBG{%
 \ifnum\zref@extractdefault{rotate\number\value{page}}{page}{0}=0  
  \PLS@RemoveRotate
 \else 
  \PLS@AddRotate{90}%
 \fi}

\newcommand\rotatesidewayslabel{\stepcounter{cntsideways}%
 \zlabel{tmp\thecntsideways}\zlabel{rotate\zref@extractdefault{tmp\thecntsideways}{page}{0}}}

\begin{document}
\lipsum[1]

\begin{sidewaysfigure}
\rotatesidewayslabel
\begin{minipage}{4cm}
a picture
\caption{figure}
\end{minipage}
\begin{minipage}{4cm}
a second picture
\caption{figure 2}
\end{minipage}

\bigskip
\centering
\includegraphics{example-image-duck}
\caption{figure}
\end{sidewaysfigure}

\lipsum[3-9]

\begin{sidewaysfigure}
\rotatesidewayslabel
\begin{minipage}{4cm}
a picture
\caption{figure}
\end{minipage}
\begin{minipage}{4cm}
a second picture
\caption{figure 2}
\end{minipage}

\bigskip
\centering
\includegraphics{example-image-duck}
\caption{figure}
\end{sidewaysfigure}

\lipsum[3-9]
\end{document}
Ulrike Fischer
  • 327,261
  • This rotates the list of figures page as well in my document. I haven't been able to get a MWE, though, if I just add \listoffigures to your code everything seems fine. Any idea? – Claudio Jan 31 '19 at 08:17
  • @Claudio I can imagine a number of things that could go wrong -- starting from that you didn't apply my code correctly, didn't do enough runs, that something is special in the page numbering of your document, and not ending at the possibility that there is flaw in my code. But without MWE I will not speculate. – Ulrike Fischer Jan 31 '19 at 09:02
  • after some investigation, it seems that the issue is not the list of figures. It is caused by using \frontmatter and \mainmatter, maybe because of the switching from roman to arabic numerals. If you switch the class to book and add \frontmatter\lipsum[1]\mainmatter right after \begin{document} in your example, you should get this behaviour. – Claudio Jan 31 '19 at 10:12
  • @Claudio add \if@mainmatter ... \fi to the \AddToShipoutPictureBG code to avoid that it is executed in the frontmatter. – Ulrike Fischer Jan 31 '19 at 15:38
  • 1
    @UlrikeFischer Unfortunately, it does not work correctly when adding the twoside option to the document. Even sideways pages in your example appear upside down. Any idea how to make the solution more robust in that way? – Daniel Feb 11 '19 at 08:55
  • 2
    @Daniel you can use \usepackage[figuresright]{rotating} so that all pictures look to the same side (I would prefer this). If you want that rotating puts the pictures sometimes looking to the right or to the left, you will have to add a test for odd/even pages and then use \PLS@AddRotate{90} or \PLS@AddRotate{-90}. – Ulrike Fischer Feb 11 '19 at 09:13
  • @UlrikeFischer Great. Maybe worth adding this to the solution? Especially since \usepackage[figuresright]{rotating} seems to make no difference when the document is not twoside. – Daniel Feb 12 '19 at 09:21
  • @UlrikeFischer I tried to automatically rotate each sidewaysfigure with \xapptocmd{\sidewaysfigure}{\rotatesidewayslabel}. However, this leads to a rotation of the second page of my table of contents. Do you happen to know what the problem might be? – Daniel Apr 22 '19 at 16:46
  • No, also it is not okay to ask additional, new questions in comments as I'm the only one seeing them. Ask a new question. – Ulrike Fischer Apr 22 '19 at 16:49
  • @UlrikeFischer I am very sorry. I wasn't aware of this. Will not happen again. I was under the impression that this was more a comment on your solution than a question. Thanks for all your help so far. – Daniel Apr 22 '19 at 17:23