1

My problem is that I want LaTeX to insert empty lines next to an image until it ends. (Sorry for the terrible wording, I am no native speaker and don't know how to express it...)

Here is how it currently looks: enter image description here

And this is how I'd like it to look (Taken from Word): enter image description here

Is there any way to accomplish what is shown in the second picture dynamically?

Here is a MWS of my code, although it doesn't do much:

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}

\begin{wrapfigure}{r}{5.5cm}
\includegraphics[width=5.5cm]{example}
\end{wrapfigure} 
This is an example text with no particular meaning or purpose. This is an 
example text with no particular meaning or purpose. This is an example text 
with no particular meaning or purpose. This is an example text with no 
particular meaning or purpose. 
\\
This should be below the imagine. This should be below the imagine. This 
should be below the imagine. This should be below the imagine. This should 
be below the imagine. This should be below the imagine. 

\end{document}

Any help would be greatly appreciated!

  • You could try to put the text in a parbox with a width of \textwidth- width of the figure. Then measure the height of this box and insert \vspace (height of the image - height of \parbox), if the height of the image is greater than that of the text. – Andreas Mar 7 '18 at 16:59
  • never use \\ like this! purpose. \\ This – David Carlisle Mar 7 '18 at 17:42
  • 1
    note if you use example-image rather than example in test files then they work as posted (example-image is in the distributions for such test uses) – David Carlisle Mar 7 '18 at 20:26
3

enter image description here

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}
\makeatletter
\def\clearwrapfig{%
\ifnum\c@WF@wrappedlines>\@ne\mbox{}\par\expandafter\clearwrapfig\fi}
\makeatother
\begin{wrapfigure}{r}{5.5cm}
\includegraphics[width=5.5cm]{example-image}
\end{wrapfigure} 
This is an example text with no particular meaning or purpose. This is an 
example text with no particular meaning or purpose. This is an example text 
with no particular meaning or purpose. This is an example text with no 
particular meaning or purpose. 

\clearwrapfig

This should be below the imagine. This should be below the imagine. This 
should be below the imagine. This should be below the imagine. This should 
be below the imagine. This should be below the imagine. 


\end{document}
  • This works exactly as intended and is kept very neat! – Crowley Astray Mar 7 '18 at 20:59
2

Took me a while to get this right -- I hope it is not too similar to the other answers… :-)

\documentclass{article}
\usepackage{graphicx}
\usepackage{wrapfig}

\usepackage{calc}
\usepackage{xifthen}

\usepackage{mwe}    % Provides example images

\newlength{\wrapfheight}    % Height of the image
\newlength{\wraptheight}    % Height of the text beside the image
\newlength{\wraptwidth}        % Width of the text
\newlength{\wrapstrut}        % Amount of space to be inserted below the text

\newsavebox{\wrapf}            % Holds the image
\newsavebox{\wrapt}            % Holds the text

% Wrapper for combining image and one paragraph of text
% #1: image width    #2: image file     #3 text paragraph
\newcommand{\wraptextfigure}[3]{%
    \savebox{\wrapf}{\includegraphics[width=#1]{#2}}%
    \setlength{\wrapfheight}{\totalheightof{\usebox{\wrapf}}}%

    \setlength{\wraptwidth}{\textwidth - #1 -\columnsep}%
    \savebox{\wrapt}{\parbox[t]{\wraptwidth}{#3}}%
    \setlength{\wraptheight}{\totalheightof{\usebox{\wrapt}}}%

    \noindent%
    \begin{minipage}[t]{\textwidth}%
        \begin{wrapfigure}{r}{#1}%
            \vspace*{-\intextsep}\usebox{\wrapf}%
        \end{wrapfigure}%
        #3%
     % If the image is higher than the text insert rule …
        \ifthenelse{\lengthtest{\wraptheight < \wrapfheight}}{%
            \setlength{\wrapstrut}{\wrapfheight - \wraptheight + \intextsep}%
            \rule[-\wrapstrut]{0pt}{\wrapstrut}}%
    % Otherwise add just some vertical space
            {\vspace{1ex}}%
    \end{minipage}%
}



\begin{document}

\noindent\hrulefill\\

\wraptextfigure{5.5cm}{example-image-a}{This is an example text with no particular meaning or purpose. This is an example text with no particular meaning or purpose. This is an example text with no particular meaning or purpose. This is an example text with no particular meaning or purpose.}

This should be below the imagine. This should be below the imagine. This should be below the imagine. This should be below the imagine. This should be below the imagine. This should be below the imagine.

\wraptextfigure{10cm}{example-image-a}{This is an example text with no particular meaning or purpose. This is an example text with no particular meaning or purpose. This is an example text with no particular meaning or purpose. This is an example text with no particular meaning or purpose.}

This should be below the imagine. This should be below the imagine. This should be below the imagine. This should be below the imagine. This should be below the imagine. This should be below the imagine.

\end{document}
  • note that you don't need the mwe package to access the example images, even though they are distributed with that package, – David Carlisle Mar 7 '18 at 21:06
  • it looks really good, but MikTex can't get the xifthen package for some reason – Crowley Astray Mar 7 '18 at 21:32
1

I'd propose not to use warpfig for that.

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}

\begin{document}
\noindent
\begin{minipage}[t]{6.6cm}
This is an example text with no particular meaning or purpose. This is an 
example text with no particular meaning or purpose. This is an example text 
with no particular meaning or purpose. This is an example text with no 
particular meaning or purpose. 
\end{minipage}\hfill
\begin{minipage}[h]{5.5cm}
\includegraphics[width=5.5cm]{example}
\end{minipage}\\
This should be below the imagine. This should be below the imagine. This 
should be below the imagine. This should be below the imagine. This should 
be below the imagine. This should be below the imagine. 

\end{document}

enter image description here

You can play with the alignments of the minipages in order to get your desired output. (Need to run now.)

  • I am afraid that should the text be longer than the picture, it will not automatically take the space back. Any ideas how to solve that? – Crowley Astray Mar 7 '18 at 18:38
1

Here is some modification:

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{pgf}
\usepackage{pgffor}

\newlength{\myfill}
\newlength{\myrfill}
\newsavebox{\mybox}
\newsavebox{\mytbox}
\newsavebox{\myvbox}
\def\myfillcreate{\pgfmathsetmacro\numlines{int(((\lengthtoadd-\lengthtoremove)/(\baselineskip))+2)}\ifnum\numlines>0 \foreach\line in{1,...,\numlines}{\\}\fi}%
\newcommand\includewrapedgraphics[2][]{\savebox\mybox{\vbox{\includegraphics[#1]{#2}}}\setlength{\myfill}{\dimexpr\the\dp\mybox+\the\ht\mybox}\xdef\lengthtoadd{\the\myfill}}%
\def\getmytext#1{\savebox\mytbox{\hbox{#1}}%
\savebox\myvbox{\vbox{#1}}%
\setlength{\myrfill}{\dimexpr\ht\myvbox+\dp\myvbox}%
\ifdim\lengthtoadd>\myrfill%
\xdef\lengthtoremove{\the\myrfill}%
\else%
\xdef\lengthtoremove{0pt}%
\fi%
}%

%#1={first wrapfigure argument (r,l etc)}
%#2={second wrapfigure argument (width)}
%#3={first (optional) includegraphics argument (width, keepaspectratio etc)}
%#4={image name of includegraphics}
%#5={the rest of the text}
\newcommand\mywrapedfigure[5]{%
\includewrapedgraphics[#3]{#4}%
\begin{wrapfigure}{#1}{#2}%
\getmytext{#5}%
\usebox{\mybox}%
\end{wrapfigure}#5%
\myfillcreate
}

\begin{document}

%#1={first wrapfigure argument (r,l etc)}
%#2={second wrapfigure argument (width)}
%#3={first (optional) includegraphics argument (width, keepaspectratio etc)}
%#4={image name of includegraphics}
%#5={the rest of the text}
\mywrapedfigure{tr}{5.5cm}{width=5.5cm}{example-image-a}{% 
This is an example text with no particular meaning or purpose. This is an 
example text with no particular meaning or purpose. This is an example text 
with no particular meaning or purpose. This is an example text with no 
particular meaning or purpose.}

This should be below the imagine. This should be below the imagine. This 
should be below the imagine. This should be below the imagine. This should 
be below the imagine. This should be below the imagine.

\mywrapedfigure{r}{5.5cm}{width=5.5cm}{example-image-a}{% 
This is an example text with no particular meaning or purpose. This is an 
example text with no particular meaning or purpose. This is an example text 
with no particular meaning or purpose. This is an example text with no 
particular meaning or purpose.This is an example text with no particular meaning or purpose. This is an 
example text with no particular meaning or purpose. This is an example text 
with no particular meaning or purpose. This is an example text with no 
particular meaning or purpose.}


This should be below the imagine. This should be below the imagine. This 
should be below the imagine. This should be below the imagine. This should 
be below the imagine. This should be below the imagine.


\mywrapedfigure{r}{5.5cm}{width=5.5cm}{example-image-a}{% 
This is an example text with no particular meaning or purpose. This is an 
example text with no particular meaning or purpose. This is an example text 
with no particular meaning or purpose. This is an example text with no 
particular meaning or purpose.This is an example text with no particular meaning or purpose. This is an 
example text with no particular meaning}

This should be below the imagine. This should be below the imagine. This 
should be below the imagine. This should be below the imagine. This should 
be below the imagine. This should be below the imagine.



\mywrapedfigure{r}{5.5cm}{width=5.5cm}{example-image-a}{% 
This is an example text with no particular meaning or purpose. This is an 
example text with no particular meaning or purpose. This is an example text 
with no particular meaning or purpose. This is an example text with no 
particular meaning or purpose.This is an example text with no particular meaning or purpose. This is an 
example text with no }

This should be below the imagine. This should be below the imagine. This 
should be below the imagine. This should be below the imagine. This should 
be below the imagine. This should be below the imagine.


\mywrapedfigure{r}{5.5cm}{width=5.5cm}{example-image-a}{% 
This is an example text with no particular meaning or purpose. This is an 
example text with no particular meaning or purpose. This is an example text 
with no particular meaning or purpose. This is an example text with no 
particular meaning or purpose. }

This should be below the imagine. This should be below the imagine. This 
should be below the imagine. This should be below the imagine. This should 
be below the imagine. This should be below the imagine.


\end{document}

Usage is explained two times in the example (one on preamble, one on definition)...

Output:

enter image description here

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.