1

When using wrapped floats, it always bugged me that they would begin one line below the start of the paragraph to which they belong. Now I have found a trick how to lift them up here, but using it has unexpected consequences for other, full-width floats elsewhere in the document.

The trick is to add this line to the preamble:

 \setlength{\intextsep}{0cm plus1cm minus1cm}

It works like a charm on wrapped floats, but the text above and below some of the other floats will now run into the figure - there is seemingly no rule how much space there is now above and below floats. Some look like before, others will have text running into them regardless of how big a vertical space I add above and below the float.

I hate to manually adjust the space around every single float, and I dread going back to the times with poorly aligned wrapped floats. What is going on here, and what should I do to get properly aligned wrapped floats and enough, consistent space for regular floats?

EDIT: Here is the result of the same LyX file, on the left without that one line and on the right with it. I also took the liberty to reduce the number of lines to wrap by one for the version on the right. It should be obvious that the vertical position of the right wrapped float looks better but that of the right float has become worse.

Sample rendering

Here is the source for the right side (with the "special" line):

#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass scrbook
\begin_preamble
\setlength{\intextsep}{0cm plus1cm minus1cm}
\end_preamble
\options twopage
\use_default_options false
\begin_modules
fixltx2e
fix-cm
\end_modules
\maintain_unincluded_children false
\language english
\language_package none
\inputencoding auto
\fontencoding default
\font_roman "cmr" "default"
\font_sans "lmss" "default"
\font_typewriter "lmtt" "default"
\font_math "auto" "auto"
\font_default_family sfdefault
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize 12
\spacing single
\use_hyperref false
\papersize a4paper
\use_geometry false
\use_package amsmath 1
\use_package amssymb 0
\use_package cancel 0
\use_package esint 1
\use_package mathdots 0
\use_package mathtools 0
\use_package mhchem 0
\use_package stackrel 0
\use_package stmaryrd 0
\use_package undertilde 0
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip smallskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Chapter
Headline
\end_layout

\begin_layout Standard
\begin_inset Wrap figure
lines 9
placement O
overhang 0in
width "50col%"
status open

\begin_layout Plain Layout
\noindent
\align center
\begin_inset Graphics
    filename /Users/Peter/Desktop/pic.PNG
    lyxscale 20
    width 48text%

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset Caption Standard

\begin_layout Plain Layout
Sample wrapped float
\end_layout

\end_inset


\end_layout

\end_inset

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
 tempor incididunt ut labore et dolore magna aliqua.
 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
 ut aliquip ex ea commodo consequat.
 Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
 eu fugiat nulla pariatur.
 Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
 deserunt mollit anim id est laborum.
 Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
 doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
 veritatis et quasi architecto beatae vitae dicta sunt explicabo.
 Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
 sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
\end_layout

\begin_layout Standard
\begin_inset Float figure
placement !h
wide false
sideways false
status open

\begin_layout Plain Layout
\noindent
\align center
\begin_inset Graphics
    filename pic.PNG
    lyxscale 20
    width 70text%

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset Caption Standard

\begin_layout Plain Layout
Sample float
\end_layout

\end_inset


\end_layout

\end_inset


\end_layout

\begin_layout Standard
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
 adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore
 et dolore magnam aliquam quaerat voluptatem.
 Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit
 laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum
 iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae
 consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
\end_layout

\end_body
\end_document

And here is the output when I export the file to pdflatex:

%% LyX 2.2.2 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\RequirePackage{fix-cm}
\RequirePackage{fixltx2e}
\documentclass[12pt,a4paper,oneside,twopage]{scrbook}
\renewcommand{\rmdefault}{cmr}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\usepackage{wrapfig}
\usepackage{graphicx}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\setlength{\intextsep}{0cm plus1cm minus1cm}

\makeatother

\begin{document}

\chapter{Headline}

\begin{wrapfigure}[9]{O}{0.5\columnwidth}%
\begin{centering}
\includegraphics[width=0.48\textwidth,height=7\baselineskip]{example-image}
\par\end{centering}
\caption{Sample wrapped float}
\end{wrapfigure}%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus
error sit voluptatem accusantium doloremque laudantium, totam rem
aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto
beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia
voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur
magni dolores eos qui ratione voluptatem sequi nesciunt.

\begin{figure}[!h]
\begin{centering}
\includegraphics[width=0.7\textwidth]{example-image}
\par\end{centering}
\caption{Sample float}
\end{figure}

Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit, sed quia non numquam eius modi tempora incidunt ut
labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima
veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam,
nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure
reprehenderit qui in ea voluptate velit esse quam nihil molestiae
consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
\end{document}
  • You also can use the insbox plain TeX macro package. It has InsertBoxL and \InsertBoxR commands, which normally align the figure top on the baseline. Another solution would be loading wrapfig and putting the graphic file in a \raisebox{some height}{\includegraphics{...}}. – Bernard Jul 16 '17 at 18:52
  • @Bernard: Sorry, no, all that will do is to drive the caption down and away from the picture. The picture will stay as poorly aligned as before. – Peter Kämpf Jul 16 '17 at 19:42
  • @DavidCarlisle: I added a sample. You need the source, too? – Peter Kämpf Jul 16 '17 at 19:51
  • Which solution drives the caption down? With wrapfig and \raisebox? Could you post a minimal code? – Bernard Jul 16 '17 at 19:53
  • @Bernard: I replaced the figure in the float by "\raisebox{1cm}{\includegraphics[width=8cm]{/Users/Peter/Desktop/pic.PNG}}" as ERT. The full LyX file of the sample above runs to 180 lines. – Peter Kämpf Jul 16 '17 at 19:56
2

The length \intextsep is used by floats that are positioned (due to an [h] argument) within a text page rather than floating to the top or bottom of a page or added to a float page.

0cm plus1cm minus1cm

is a length with natural (preferred width) of 0cm but if the page content needs to stretch it can stretch to 1cm and if the page is over full and white space needs to shrink, it can shrink to -1cm.

So this setting declares that if a float is set mid-page, it may be surrounded by negative space of 1cm above and below, so overprinting the text by that amount, or it may be surrounded by white space of up to 1cm above and below the float.

Basically there is no document where this setting can be useful. It will not necessarily produce bad typesetting. It might accidentally stretch to a reasonable space, such as 10pt or so, but that would just be by luck.

For comparison, the standard classes (at 10pt option) use a setting of

\setlength\intextsep   {12pt plus 2pt minus 2pt}

so a space between 10pt and 14pt, with natural size 12pt.

wrapfig adds this space into the wrapped figure, so if you wanted to set it globally it would be enough to use

\setlength\intextsep   {0pt}

without the allowing the 1cm over-printing, however better to leave h floats and just patch wrapfig to remove the \intextspace at the top

enter image description here

%% LyX 2.2.2 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\RequirePackage{fix-cm}
\RequirePackage{fixltx2e}
\documentclass[12pt,a4paper,oneside,twopage]{scrbook}
\renewcommand{\rmdefault}{cmr}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\usepackage{wrapfig}
\usepackage{graphicx}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
%\setlength{\intextsep}{0cm}% plus1cm minus1cm}
\usepackage{etoolbox}
\patchcmd\WF@rapt{\vtop\bgroup}{\vtop\bgroup\vspace{-\intextsep}}{}{}
\makeatother

\begin{document}

\chapter{Headline}

\begin{wrapfigure}[9]{O}{0.5\columnwidth}%
\begin{centering}
\includegraphics[width=0.48\textwidth,height=7\baselineskip]{example-image}
\par\end{centering}
\caption{Sample wrapped float}
\end{wrapfigure}%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus
error sit voluptatem accusantium doloremque laudantium, totam rem
aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto
beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia
voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur
magni dolores eos qui ratione voluptatem sequi nesciunt.

\begin{figure}[!h]
\begin{centering}
\includegraphics[width=0.7\textwidth]{example-image}
\par\end{centering}
\caption{Sample float}
\end{figure}

Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit, sed quia non numquam eius modi tempora incidunt ut
labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima
veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam,
nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure
reprehenderit qui in ea voluptate velit esse quam nihil molestiae
consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
\end{document}
  • This explains the odd spacing of regular floats. All I can say is that this strange line works well and consistently for wrapped floats, so it does something useful. And please remember, I am using it in LyX. – Peter Kämpf Jul 16 '17 at 19:55
  • @PeterKämpf No it can not ever do anything useful, it might do the same as setting it to 0pt for example, but setting it to allow over-printing by 1cm can never do anything good. Without an example it is impossible to guess what effect it is having, picins does not use \intextsep (I downloaded it from ctan to look) – David Carlisle Jul 16 '17 at 20:07
  • @PeterKämpf as I guessed, setting it to 0pt has the effect you want on wrapfig, but I'll add something to my answer – David Carlisle Jul 16 '17 at 20:22
  • Cool, that does work indeed! – Peter Kämpf Jul 16 '17 at 20:49
  • Well, it works on the small sample but barfs at a longer file. The error message is: \@ ifundefined{showcaptionsetup}{}{% Sorry, but I'm not programmed to handle this case; I'll just pretend that you didn't ask for it. If you're in the wrong mode, you might be able to return to the right one by typing I}' or I$' or `I\par'. – Peter Kämpf Jul 16 '17 at 20:53
0

What works best (after lots of trial and error) was to add a negative vertical space of -4mm at the top of the picture inside the float. Only when the float is placed with the first line on a new page must this negative vertical space be omitted.

Now the LyX source of sample text from the question (without the "special" line) looks like this (Note the section \begin_inset VSpace -4mm \end_inset - this makes all the difference!):

#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass scrbook
\begin_preamble

\end_preamble
\options twopage
\use_default_options false
\begin_modules
fixltx2e
fix-cm
\end_modules
\maintain_unincluded_children false
\language english
\language_package none
\inputencoding auto
\fontencoding default
\font_roman "cmr" "default"
\font_sans "lmss" "default"
\font_typewriter "lmtt" "default"
\font_math "auto" "auto"
\font_default_family sfdefault
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize 12
\spacing single
\use_hyperref false
\papersize a4paper
\use_geometry false
\use_package amsmath 1
\use_package amssymb 0
\use_package cancel 0
\use_package esint 1
\use_package mathdots 0
\use_package mathtools 0
\use_package mhchem 0
\use_package stackrel 0
\use_package stmaryrd 0
\use_package undertilde 0
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip smallskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Chapter
Headline
\end_layout

\begin_layout Standard
\begin_inset Wrap figure
lines 11
placement O
overhang 0in
width "50col%"
status open

\begin_layout Plain Layout
\noindent
\align center
\begin_inset VSpace -4mm
\end_inset

\begin_inset Graphics
    filename pic.PNG
    lyxscale 20
    width 50text%

\end_inset

\end_layout

\begin_layout Plain Layout
\begin_inset Caption Standard

\begin_layout Plain Layout
Sample wrapped float
\end_layout

\end_inset

\end_layout

\end_inset

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
 tempor incididunt ut labore et dolore magna aliqua.
 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
 ut aliquip ex ea commodo consequat.
 Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
 eu fugiat nulla pariatur.
 Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
 deserunt mollit anim id est laborum.
 Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
 doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
 veritatis et quasi architecto beatae vitae dicta sunt explicabo.
 Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
 sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
\end_layout

\begin_layout Standard
\begin_inset Float figure
placement !h
wide false
sideways false
status open

\begin_layout Plain Layout
\noindent
\align center
\begin_inset Graphics
    filename pic.PNG
    lyxscale 20
    width 70text%

\end_inset

\end_layout

\begin_layout Plain Layout
\begin_inset Caption Standard

\begin_layout Plain Layout
Sample float
\end_layout

\end_inset

\end_layout

\end_inset

\end_layout

\begin_layout Standard
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
 adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore
 et dolore magnam aliquam quaerat voluptatem.
 Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit
 laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum
 iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae
 consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
\end_layout

\end_body
\end_document

Sample text rendering

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.