1

I have often used this form of the wrapfigure, but I notice that sometimes I have this problem.

 \documentclass[pdftex,10pt,a4paper]{book}
\setlength{\oddsidemargin}{0 mm}
\setlength{\topmargin}{0 mm}
%\setlength{\headheight}{7 mm} %latezza capotesta
%\setlength{\headsep}{9 mm} 
\setlength{\evensidemargin}{0 mm}
\setlength{\marginparwidth}{0 mm} %% per le note a bordo?
\setlength{\textheight}{230mm} %Altezza Testo
\setlength{\textwidth}{150mm}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}
\usepackage{mwe}
\usepackage{caption}
\usepackage{lipsum}


\begin{document}
\lipsum[1-1]
    \begin{wrapfigure}[11]{l}[\dimexpr \marginparwidth]{5.5cm}
        \centering\raisebox{\dimexpr \topskip-\height}{%
            \includegraphics[width=5.0cm]{example-image-a}}
        \captionof{figure}{Titolo dell'immagine casuale}
    \end{wrapfigure}\hfil

\lipsum[2-3]

\begin{wrapfigure}[11]{r}[\dimexpr \marginparwidth]{5.5cm}
    \centering\raisebox{\dimexpr \topskip-\height}{%
        \includegraphics[width=5.0cm]{example-image-a}}
    \captionof{figure}{Titolo dell'immagine casuale}
\end{wrapfigure}\hfil


\lipsum[4-5]
    
\end{document}

enter image description here

any suggestions on this?

3

An alternative:


\documentclass[pdftex,10pt,a4paper]{book}
\usepackage[textheight=230mm,
            textwidth=150mm,
            marginparwidth=0mm]{geometry} % for defining page layout
\usepackage{graphicx}
\usepackage{wrapfig}
\setlength{\intextsep}{0pt} % <--- push image to top of paragraph
\usepackage{caption}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{blindtext}    % wrapfigure doesn't work well with lipsum

\begin{document}

    \begin{wrapfigure}[12]{l}{0.4\linewidth}% explicit reserved space for wrapfigure
    \includegraphics[width=\linewidth]{example-image-duck}
    \caption{Titolo dell'immagine casuale}
    \end{wrapfigure}
\blindtext[1]

\begin{wrapfigure}{r}{5.5cm}% implicit reserved space for wrapfigure
    \centering
    \includegraphics[width=5.0cm]{example-image-a}
    \caption{Titolo dell'immagine casuale}
\end{wrapfigure}
\blindtext[2]
\end{document}

enter image description here

2

It looks like your main concern is over-printing at the bottom, yet you manually specified the number of lines to wrap. So either omit the [11] argument entirely, or change it to [12].

There are other issues that you did not circle in red.

You have an empty one-line paragraph near the start of each wrapfig, which appears as a blank line in the output. If that is not on purpose, get rid of the \hfil which causes it.

The \raisebox is not doing what it seems you want (something about positioning at the top of a page). I'm guessing that you want to reduce the vertical gap around the wrapfig. So instead use \setlength{\intextsep}{4pt} or some other length.

Using \captionof is unnecessary, but doesn't hurt. (I suspected it would break the automatic-width feature for 0pt width, but it seems to work.)

I don't know why you specify a margin overhang, with the margin width set to zero. Just leave out that optional argument.

In summary, I think you are trying too hard. You could use

\lipsum[1-1]

\setlength\intextsep{4pt}
\begin{wrapfigure}{l}{5.5cm}
    \centering
    \includegraphics[width=5.0cm]{example-image-a}
    \caption{Titolo dell'immagine casuale}
\end{wrapfigure}

\lipsum[2-3]
1

This seems to work better:

\documentclass[pdftex,10pt,a4paper]{book}
\setlength{\oddsidemargin}{0 mm}
\setlength{\topmargin}{0 mm}
%\setlength{\headheight}{7 mm} %latezza capotesta
%\setlength{\headsep}{9 mm} 
\setlength{\evensidemargin}{0 mm}
\setlength{\marginparwidth}{0 mm} %% per le note a bordo?
\setlength{\textheight}{230mm} %Altezza Testo
\setlength{\textwidth}{150mm}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}
\usepackage{mwe}
\usepackage{caption}
\usepackage{lipsum}


\begin{document}
\lipsum[1-1]
    \begin{wrapfigure}{l}[\dimexpr \marginparwidth]{5.5cm}
        \centering\raisebox{\dimexpr \topskip-\height}{%
            \includegraphics[width=5.0cm]{example-image-a}}
        \caption{Titolo dell'immagine casuale}
    \end{wrapfigure}\hfil

\lipsum[2-3]

\begin{wrapfigure}{r}[\dimexpr \marginparwidth]{5.5cm}
    \centering\raisebox{\dimexpr \topskip-\height}{%
        \includegraphics[width=5.0cm]{example-image-a}}
    \caption{Titolo dell'immagine casuale}
\end{wrapfigure}\hfil


\lipsum[4-5]
    
\end{document}

enter image description here

Avoid \captionof{}{} and just use \caption{} (wrapfigure environment handles caption itself but possibly doesn't recognize \captionof) ... Also by giving the optional argument of 11 lines ... you "force" that behavior ...

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.