环绕图旁边有空行

环绕图旁边有空行

我的问题是我想让 LaTeX 在图像旁边插入空行,直到图像结束。(抱歉措辞不当,我不是母语人士,不知道如何表达......)

目前的样子如下: 在此处输入图片描述

这就是我希望它看起来的样子(摘自 Word): 在此处输入图片描述

有没有什么办法可以动态地实现第二张图所示的效果?

这是我的代码的 MWS,尽管它没有做太多事情:

\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}

任何帮助将不胜感激!

答案1

在此处输入图片描述

\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}

答案2

我花了一段时间才把这个问题搞清楚——我希望它与其他答案不太相似……:-)

\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}

答案3

我建议不要为此使用 warpfig。

\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}

在此处输入图片描述

您可以调整小页面的对齐方式以获得所需的输出。(需要立即运行。)

答案4

以下是一些修改:

\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}

示例中解释了两次用法(一次在序言中,一次在定义中)...

输出:

在此处输入图片描述

相关内容