我正在尝试让文本环绕我的图形。这在我的文本主体中工作正常,但当我将其放入文本中时,\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-a
了mwe
包裹):
\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