Wrapfig 无法在我的 fcolorbox 迷你页面中工作

Wrapfig 无法在我的 fcolorbox 迷你页面中工作

我正在尝试让文本环绕我的图形。这在我的文本主体中工作正常,但当我将其放入文本中时,\fcolorbox文本会覆盖图像。我已将代码简化为以下示例。作为新手,如果我做错了,我很抱歉,但我没有看到上传文件的链接,所以我希望人们可以使用他们手头的任何图像文件来重现这种情况。

\documentclass{book}
\usepackage{graphicx} % Allows graphics to be imported
\usepackage{wrapfig} % Allows figures to go on the side of the page with text wrapping around them
\usepackage[usenames,dvipsnames]{color} % An easy way to get shaded boxes
\definecolor{light-gray}{gray}{0.8} % Defines the color we're using for shaded boxes

\begin{document}

\fcolorbox{black}{light-gray}{\begin{minipage}{\columnwidth}\parskip=6pt
Some text

\begin{wrapfigure}{r}{.2\textwidth}
\vspace{-15pt}
\begin{center}\includegraphics[width=.18\textwidth]{latexchapters/vectorsfigures/simplepath.png}\end{center}
\vspace{-15pt}
\end{wrapfigure}

{\it Answer:} To find the potential at $(x,y)$ we evaluate a line integral from the origin to $(x,y)$. For simplicity we use the path shown on the right, first going from $(0,0)$ to $(x,0)$ and then from there to $(x,y)$. Along the first segment only $f_x$ contributes, and since $y=0$, $f_x=1$ and the line integral equals $x$. Along the second segment only $f_y$ contributes, and $x$ is constant but $y$ is not, so we get $x\int_0^ye^{\tilde{y}}d\tilde{y} = xe^y-x$. Combining the two segments we find $\int_C\vec{f}=xe^y$. Remember that the gradient theorem just relates line integrals to gradients, but the definition of potential we use includes an additional minus sign, so $V(x,y)=-xe^y$.

\end{minipage}}

\end{document}

答案1

请注意,、\it\bf字体宏已被弃用,因为它们不使用 LaTeX2e 引入的新字体选择方案。请使用{\itshape ..}{\bfseries ..}\textit{..}\textbf{..}请参阅\textit我使用或\it\bfseries等有关系吗\bf两个字母的字体样式命令(\bf,,\it...)会在 LaTeX 中复活吗? 了解更多信息。

使用\textit{...}解决了你的情况的问题(我已经使用example-image-amwe包裹):

在此处输入图片描述

\documentclass{book}
\usepackage{graphicx }% Allows graphics to be imported
\usepackage{wrapfig} % Allows figures to go on the side of the page with text wrapping around them
\usepackage[usenames,dvipsnames]{color} % An easy way to get shaded boxes
\definecolor{light-gray}{gray}{0.8} % Defines the color we're using for shaded boxes

\begin{document}

\noindent
\fcolorbox{black}{light-gray}{\begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule}\parskip=6pt
Some text

\begin{wrapfigure}{r}{.2\textwidth}
\centering
\includegraphics[width=.18\textwidth]{example-image-a}
\end{wrapfigure}

\textit{Answer}: To find the potential at $(x,y)$ we evaluate a line integral from 
the origin to $(x,y)$. For simplicity we use the path shown on the right, first going 
from $(0,0)$ to $(x,0)$ and then from there to $(x,y)$. Along the first segment only 
$f_x$ contributes, and since $y=0$, $f_x=1$ and the line integral equals $x$. Along the 
second segment only $f_y$ contributes, and $x$ is constant but $y$ is not, so we get 
$x\int_0^ye^{\tilde{y}}d\tilde{y} = xe^y-x$. Combining the two segments we find 
$\int_C\vec{f}=xe^y$. Remember that the gradient theorem just relates line integrals to 
gradients, but the definition of potential we use includes an additional minus sign, so 
$V(x,y)=-xe^y$.

\end{minipage}}

\end{document}

我还在您的文档中更改了以下内容:

  • 用来\centering代替center环境。它消除了插入负数 s 的要求\vspace
  • 插入\noindent在 之前\fcolorbox,因为默认每个段落都用 缩进\parindent。这里不需要;
  • 使长度minipage相当于\linewidth-2\fboxsep-2\fboxrule避免过满\hbox警告 -默认情况下在框的两侧\fcolorbox添加\fboxsep和。\fboxrule

相关内容