在环境附近使用 WrapFigure。(环境内的某些文本未被 wrapfig 包裹)

在环境附近使用 WrapFigure。(环境内的某些文本未被 wrapfig 包裹)

为了计算文档中的单词数,我使用自定义环境,如建议的那样这里在 tex.stackexchange 上。如下所示,当此环境与 wrapfigure 一起使用时,wrapfigure 无法正确换行文本。

在此处输入图片描述

以下是此 MWE 中使用的 PNG 文件。在我的原始文档中,我使用的是 TikZ 创建的 PDF 文件,但这更容易托管,并且具有相同的效果,只是光栅化质量较差。 在 TikZ 中创建的 PDF 的 PNG 栅格

MWE 如下。

\documentclass[a4paper]{article}
\usepackage{mathtools}
\usepackage{wrapfig}
\usepackage{xesearch}
\usepackage{enumitem}

\newcounter{words}
\newenvironment{counted}{%
  \setcounter{words}{0}
  \SearchList!{wordcount}{\stepcounter{words}}
    {a?,b?,c?,d?,e?,f?,g?,h?,i?,j?,k?,l?,m?,
    n?,o?,p?,q?,r?,s?,t?,u?,v?,w?,x?,y?,z?}
  \UndoBoundary{'}
  \SearchOrder{p;}}{%
  \StopSearching}

\begin{document}
\begin{wrapfigure}{r}{0.5\textwidth}
\centering
\includegraphics{fig1.png}
\caption{Caption}
\label{fig:1a}
\end{wrapfigure}

\begin{counted}
We assume that point $\mathrm{P}$ is far enough from the dipole such that the $\mathbf{B}$ field obeys the equation for a dipole aligned along the $z$-axis:
As can be seen by inspection, the magnetic field lines encircle the $z$-axis and therefore a circular wire loop centred at any point along the axis would have a net zero flux passing through the centre -- no signal would be detected.\
The wire loop must be aligned in a plane normal to the magnetic flux. If the loop were aligned parallel to the flux, then no flux would pass \emph{through} the loop. In accordance with Faraday's Law, this would mean that no electric field would be found integrating along the path of the loop -- i.e. no current would be induced and therefore no signal detected. It is important to note that the direction of the flux is key and flux from opposite directions cancels out, as demonstrated in figure~\ref{fig:1a}.
\end{counted}
\end{document}

目前,我必须在正确换行的文本和字数统计之间做出选择。我宁愿不必在这两者之间做出选择!

答案1

只要您不在wrapfigure环境和文本之间留空行并\par在之前添加命令,问题就会消失end{counted}

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage{wrapfig}
\usepackage{xesearch}
\usepackage{enumitem}

\newcounter{words}
\newenvironment{counted}{%
  \setcounter{words}{0}
  \SearchList!{wordcount}{\stepcounter{words}}
    {a?,b?,c?,d?,e?,f?,g?,h?,i?,j?,k?,l?,m?,
    n?,o?,p?,q?,r?,s?,t?,u?,v?,w?,x?,y?,z?}
  \UndoBoundary{'}
  \SearchOrder{p;}}{%
  \StopSearching}

\begin{document}
\begin{wrapfigure}{r}{0.5\textwidth}
\centering
\includegraphics{fig1.png}
\caption{Caption}
\label{fig:1a}
\end{wrapfigure}
\begin{counted}
We assume that point $\mathrm{P}$ is far enough from the dipole such that the $\mathbf{B}$ field obeys the equation for a dipole aligned along the $z$-axis:
As can be seen by inspection, the magnetic field lines encircle the $z$-axis and therefore a circular wire loop centred at any point along the axis would have a net zero flux passing through the centre -- no signal would be detected.

The wire loop must be aligned in a plane normal to the magnetic flux. If the loop were aligned parallel to the flux, then no flux would pass \emph{through} the loop. In accordance with Faraday's Law, this would mean that no electric field would be found integrating along the path of the loop -- i.e. no current would be induced and therefore no signal detected. It is important to note that the direction of the flux is key and flux from opposite directions cancels out, as demonstrated in figure~\ref{fig:1a}.\par
\end{counted}

\end{document}

在此处输入图片描述

顺便一提,绝不使用\\后跟一个空行来增加段落之间的间隔(这会产生一个水平盒子未满的警告);在这个站点搜索替代方案。

相关内容