# prevent blank area caused by wrapfigure in multicol environment

I'm using wrapfigure inside a multicol environment to wrap my text around a tikz graph. This however creates an unwanted blank area in the second column (after \columbreak). How can I prevent this?

The following MWE

\documentclass[a4paper]{article}
\usepackage{tikz,multicol,wrapfig,lipsum}
\usetikzlibrary{graphs,graphs.standard}
\begin{document}
\begin{multicols}{2}
\begin{wrapfigure}{l}{0pt}
\tikz \graph [nodes={circle,draw}] {
subgraph C_n [n=3, counterclockwise]
};
\end{wrapfigure}
\lipsum[1-2]

\columnbreak

\lipsum[3-4]
\end{multicols}
\end{document}


generates the following output:

I have to use the multicol environment because there will be text before and after the two columns.

The File List printed by \listfiles:

 *File List*
article.cls    2014/09/29 v1.4h Standard LaTeX document class
size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
tikz.sty    2015/08/07 v3.0.1a (rcs-revision 1.151)
pgf.sty    2015/08/07 v3.0.1a (rcs-revision 1.15)
pgfrcs.sty    2015/08/07 v3.0.1a (rcs-revision 1.31)
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
pgfrcs.code.tex
pgfcore.sty    2010/04/11 v3.0.1a (rcs-revision 1.7)
graphicx.sty    2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
graphics.sty    2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)
trig.sty    2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg    2016/06/04 v1.11 sample graphics configuration
pdftex.def    2018/01/08 v1.0l Graphics/color driver for pdftex
pgfsys.sty    2014/07/09 v3.0.1a (rcs-revision 1.48)
pgfsys.code.tex
pgfsyssoftpath.code.tex    2013/09/09  (rcs-revision 1.9)
pgfsysprotocol.code.tex    2006/10/16  (rcs-revision 1.4)
xcolor.sty    2016/05/11 v2.12 LaTeX color extensions (UK)
color.cfg    2016/01/02 v1.6 sample color configuration
pgfcore.code.tex
pgfcomp-version-0-65.sty    2007/07/03 v3.0.1a (rcs-revision 1.7)
pgfcomp-version-1-18.sty    2007/07/23 v3.0.1a (rcs-revision 1.1)
pgffor.sty    2013/12/13 v3.0.1a (rcs-revision 1.25)
pgfkeys.sty
pgfkeys.code.tex
pgfmath.sty
pgfmath.code.tex
pgffor.code.tex
tikz.code.tex
multicol.sty    2018/04/20 v1.8s multicolumn formatting (FMi)
wrapfig.sty    2003/01/31  v 3.6
lipsum.sty    2018/11/24 v2.1a 150 paragraphs of Lorem Ipsum dummy text
expl3.sty    2018-11-19 L3 programming layer (loader)
expl3-code.tex    2018-11-19 L3 programming layer
l3pdfmode.def    2018-11-19 v L3 Experimental driver: PDF mode
xparse.sty    2018-10-17 L3 Experimental document command parser
supp-pdf.mkii
epstopdf-base.sty    2016/05/15 v2.6 Base part for package epstopdf
infwarerr.sty    2016/05/16 v1.4 Providing info/warning/error messages (HO)
grfext.sty    2016/05/16 v1.2 Manage graphics extensions (HO)
kvdefinekeys.sty    2016/05/16 v1.4 Define keys (HO)
ltxcmds.sty    2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
kvoptions.sty    2016/05/16 v3.12 Key value format for package options (HO)
kvsetkeys.sty    2016/05/16 v1.17 Key value parser (HO)
etexcmds.sty    2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
ifluatex.sty    2016/05/16 v1.4 Provides the ifluatex switch (HO)
pdftexcmds.sty    2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO)
ifpdf.sty    2018/09/07 v3.3 Provides the ifpdf switch
epstopdf-sys.cfg    2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
***********


Diff between TeX Live 2017 on Ubuntu and 2018 on Arch file list:

32c32
< multicol.sty    2017/04/11 v1.8q multicolumn formatting (FMi)
---
> multicol.sty    2018/04/20 v1.8s multicolumn formatting (FMi)
34c34,38
<   lipsum.sty    2014/07/27 v1.3 150 paragraphs of Lorem Ipsum dummy text
---
>   lipsum.sty    2018/11/24 v2.1a 150 paragraphs of Lorem Ipsum dummy text
>    expl3.sty    2018-11-19 L3 programming layer (loader)
> expl3-code.tex    2018-11-19 L3 programming layer
> l3pdfmode.def    2018-11-19 v L3 Experimental driver: PDF mode
>   xparse.sty    2018-10-17 L3 Experimental document command parser
45,46c49,50
< pdftexcmds.sty    2018/01/21 v0.26 Utility functions of pdfTeX for LuaTeX (HO)
<    ifpdf.sty    2017/03/15 v3.2 Provides the ifpdf switch
---
> pdftexcmds.sty    2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO)
>    ifpdf.sty    2018/09/07 v3.3 Provides the ifpdf switch


Possibly a bug in the multicol package?

The following MWE will produce a similar result with updated packages:

\documentclass[a4paper]{article}
\usepackage{tikz,multicol,wrapfig,lipsum}
\usetikzlibrary{graphs,graphs.standard}
\begin{document}
\begin{multicols}{2}
\begin{wrapfigure}{l}{0pt}
\tikz \graph [nodes={circle,draw}] {
subgraph C_n [n=3, counterclockwise]
};
\end{wrapfigure}
Some Text

\columnbreak

\lipsum[3-4]
\end{multicols}
\end{document}


It will also print 3 Underfull \hbox warnings, so I don't know whether it's really an issue or I'm just writing invalid code.

Nevertheless changing \lipsum[3-4] to \lipsum[3] \lipsum[4] makes the warnings disappear and also removes the blank rectangle.

\documentclass[a4paper]{article}
\usepackage{tikz,multicol,wrapfig,lipsum}
\usetikzlibrary{graphs,graphs.standard}
\begin{document}
\begin{multicols}{2}
\begin{wrapfigure}{l}{0pt}
\tikz \graph [nodes={circle,draw}] {
subgraph C_n [n=3, counterclockwise]
};
\end{wrapfigure}
Some Text

\columnbreak

\lipsum[3]
\lipsum[4]
\end{multicols}
\end{document}


• I don't see such an empty rectangle, after compiling your code – user31729 Jan 19 '19 at 11:18
• pdflatex, TexLive 2018 on Linux, updated yesterday... – user31729 Jan 19 '19 at 11:22
• Well, this is strange. Are you sure you posted the minimal version that generates your issue? – user31729 Jan 19 '19 at 11:26
• Other users should test this using Windows or Mac... – user31729 Jan 19 '19 at 11:34
• I also didn't get that rectangle in my compiled pdf through pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian). – Partha D. Jan 19 '19 at 11:46

What wrapfig does is that it sets up a special parshape which should in theory get canceled after the paragraph is set.

Typically this is done by setting something up activating it in \everypar and \everypar then resets itself when called. But if that call happens inside a group then at the end of the group the old \everypar gets restored and you will get the action twice.

Same happens for eample in std LaTeX if a section is directly followed by a list. The section enforces 2 lines of text after it using the above mechanism. But since that text is inside an environment the setup repeats itself once the list ends (and you see clubpenalty 10000 there again.

What can be seen in your MWE is that it suddenly again active on the third paragraph which means it is again active at \lipsum[3-4]. That makes me suspect that \lipsum[1-2] used such a group and thus reinstalled the wrapfig stuff at its end.

lipsum got recently reimplemented and as part of the process it got changed/fixed several times. With the current setup here which has lipsum 2.2 and multicol 1.8v it all works correctly. Looking at your \listfiles output you clearly have older package versions (in several cases) so your system is by no means "current".

Maybe it ie enough to really use the latest lipsum, but in general my suggestion is to update all of your setup and then try again.

and no ... fairly sure it is not a multicol problem.

## Update (concerning the recently added extra MWEs)

What happens there is that you explicitly ask for a column-break directly after the words "Some tex". Now these words are clearly not enough to flow around your picture and that means that in essense you have asked wrapfig to wrap across a column/page break and if you do that the hole or part of the hole may be on the next page/column (while your figure obviously isn't split)

you can get exactly the same result (without multicols) using twocolumn mode and \pagebreak instead of \columnbreak so this isn't really a surprise.

As for the final example not showing the hole in the second column: that has to do with how lipsum is implemented and is, if you like, a deficiency there (add a final extra paragraph and your hole comes back). wrapfig documentation mentions some restrictions concerning its use near list environments and this is a problem of a similar nature.

• Thanks for your detailed explanation! I installed TeX Live using the repository of my distribution, which doesn't include tlmgr. So I removed these packages and did a clean TeX Live install using texlive-installer, installed the necessary packages and voila, the blank area disappeared. I can, however, "restore" the blank area by replacing \lipsum[1-2] with some text or just a single word. And I can then fix it again by replacing \lipsum[3-4] with \lipsum[3] \lipsum[4]. – jkhsjdhjs Jan 20 '19 at 12:54
• @jkhsjdhjs first of all most linux distrubtions contain conld TL versions in their distribution (sometimes years back unfortunately (see for example repology.org/metapackage/texlive/versions), Hoever, even with those you can update them typically using the TL manager without the need to deinstall first. Second, if you get the same or a similar problem with an MWE using the current TL, it would be good if you show that so that the underlying issue (if any) can be analyzed and resolve. The info in your comment is not enough! – Frank Mittelbach Jan 20 '19 at 16:11
• Yes, I see, the TeX Live version contained in the repos of the distribution I'm using however are - compared to other distros - fairly up to date. As I said the packages in my distribution don't contain the tlmgr. There exists similar tool in the user repositoy, but in my opinion a clean install of TeX Live was the best solution as it also uses less space since I don't have to install a whole bunch of packages when I just need one. I'll add two MWE's for the cases I mentioned in my comment to the question. – jkhsjdhjs Jan 20 '19 at 18:12