如何减少 wrapfigure 的顶部边距

如何减少 wrapfigure 的顶部边距

我正在写一份文档,wrapfigure它的各个部分如下所示:

~~~~~~~~~~~~~~~~~~~~~~
~~~~~~   
  ~~~~~~~~   ________
~~~~~~~~~~  |        |
~~~~~~~~~~  | Figure |
~~~~~~~~~~  |________| 
~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~

我怎样才能减少图形顶部的边距,\baselineskip使其看起来像这样:

~~~~~~~~~~~~~~~~~~~~~~
~~~~~~       ________
  ~~~~~~~~  |        | 
~~~~~~~~~~  | Figure |
~~~~~~~~~~  |________|
~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~

以下是带有简化图的 MWE:

\documentclass{article}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{tikz}
\begin{document}
\lipsum[1]

\begin{wrapfigure}{r}{0pt}
  \begin{tikzpicture}[inner sep=0pt, outer sep=0pt]
    \node (A) {A};
    \node[above right] (B) at (A.north east) {B};
    \draw (A.south west)--(B.north east);
  \end{tikzpicture}
\end{wrapfigure}
\lipsum[2]
\end{document}

答案1

另一个简单的解决方案是让 LaTeX 相信图形高度比实际要小,这要归功于命令的可选参数\raisebox。代码如下:

        \documentclass[11pt, a4paper]{article}
        \usepackage[utf8]{inputenc}
        \usepackage[T1]{fontenc}
        \usepackage{lmodern}

        \usepackage{kantlipsum, wrapfig,graphicx}

        \begin{document}

        Here is some text to fill up the first line and give some typing practice to me.

        \begin{wrapfigure}{r}{0pt}
        \raisebox{0pt}[\dimexpr\height-0.6\baselineskip\relax]{\includegraphics{airepara}}%
        \end{wrapfigure}
        \kant[1]

        \begin{wrapfigure}{r}{0pt}%
        \raisebox{0pt}[\dimexpr\height-0.6\baselineskip\relax]{\includegraphics[width=3cm]{airepara}}%
        \end{wrapfigure}
        \kant[2]

        \end{document}

在此处输入图片描述

相关内容