I'm using package wrapfig
in a document with many subsections. At least one per page. I have a tall figure, almost the height of an entire page, so I assume wrapfig
is the correct way to place this – one column of text (~60% of page width) and one column of figure (~40% of page width).
However, wrapfig
appears to have issues when it extends over a section or subsection. There have been two (1, 2) questions on this site have brought this up already, but the answer to both of those is "put the new section on the next page". Since I have many sections, that does not work in this document.
Perhaps the solution is to embed the wrapfig
in another environment, but I am not sure which one.
Edit
I found what was causing the issue:
\setcounter{secnumdepth}{-1}
Here is an MWE. It should generate the screenshot below. Comment out the above line, and wrapfig
appears to work correctly.
\RequirePackage[l2tabu, orthodox]{nag}
\documentclass[12pt]{article}
\usepackage{lipsum}
\usepackage{wrapfig}
\setcounter{secnumdepth}{-1} % disables section and subsection numbering
\begin{document}
\section{Section 1}
\begin{wrapfigure}{r}{0.30\linewidth}
\rule{5cm}{9cm}
\caption{Caption}
\label{fig:fig}
\end{wrapfigure}
\subsection{Subsection 1}
\lipsum[1]
\subsection{Subsection 2}
\lipsum[2-4]
\end{document}
Best Answer
Interesting,
You can patch the section handling so that things work:
Add
However if your real document is using numbered sections like this, setting
secnumdepth
to -1 and using numbers in the section titles is just the wrong thing to do, it disables all LaTeX's mechanisms for cross referencing. See This question