7

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}

enter image description here

mankoff
  • 2,756
  • I have. Not sure how to do two columns that are not 50/50, but I'm also interested in this specific answer because sometimes the image is only 1/2 or 2/3 of the page height, and this problem still exists, but two full columns would leave a lot of whitespace in that situation. – mankoff Oct 11 '13 at 15:58
  • 1
    Please make a complete small document that shows the problem (you can use \rule{2cm}{10cm} or whatever you need instead of \includegraphics to make a portable test. – David Carlisle Oct 11 '13 at 18:34

1 Answers1

6

enter image description here

Interesting,

You can patch the section handling so that things work:

Add

\makeatletter
\def\patchsect#1\let\@svsec\@empty{#1\def\@svsec{\leavevmode\kern1sp\relax}}
\let\old@sect\@sect
\def\@sect{\expandafter\patchsect\old@sect}
\makeatother

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

David Carlisle
  • 757,742
  • 1
    Thanks. I would never manually number sections. That was just a bad example. Is this a bug? Where would I report it? – mankoff Oct 12 '13 at 02:53