wrapfig2 和类似定理的环境

wrapfig2 和类似定理的环境

当我使用 wrapfig2 包时,我偶然发现,如果类似定理的环境不是 wrapfigure 环境之后的第一个段落,则该定理会正确缩进:

\documentclass{article}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}

\usepackage{wrapfig2}

\begin{document}
\begin{wrapfigure}{l}*
\rule{4cm}{4cm}
\end{wrapfigure}
Texts before theorem. Texts before theorem. Texts before theorem.
Texts before theorem. Texts before theorem. Texts before theorem.
\begin{thm}
  Texts in the theorem. Texts in the theorem. Texts in the theorem.
  Texts in the theorem. Texts in the theorem. Texts in the theorem.
  Texts in the theorem. Texts in the theorem. Texts in the theorem.
\end{thm}
Texts after the theorem. Texts after the theorem. Texts after the theorem.
Texts after the theorem. Texts after the theorem. Texts after the theorem.
\end{document} 

输出:

在此处输入图片描述

我的问题是,如果我们可以编写一些像隐形段落一样的黑客代码,以便图形可以包裹在类似单一定理的环境中:

\documentclass{article}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}

\usepackage{wrapfig2}

\begin{document}
\begin{wrapfigure}{l}*
\rule{4cm}{4cm}
\end{wrapfigure}
%do something here so that the wrapfigure "works" for theorem-like environments
\begin{thm}
  Texts in the theorem. Texts in the theorem. Texts in the theorem.
  Texts in the theorem. Texts in the theorem. Texts in the theorem.
  Texts in the theorem. Texts in the theorem. Texts in the theorem.
\end{thm}
Texts after the theorem. Texts after the theorem. Texts after the theorem.
Texts after the theorem. Texts after the theorem. Texts after the theorem.
\end{document} 

答案1

\leavevmode开始一个段落(例如\everypar)。 \hrule将结束一个段落而不添加任何空格。但是,这条不可见的线仍然有效,因此您需要调整行数(可选参数)。

\documentclass{article}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}

\usepackage{wrapfig2}

\begin{document}

Text before wrapfig.

\begin{wrapfigure}[1]{l}*
\rule{4cm}{4cm}
\end{wrapfigure}

\leavevmode\vspace{\dimexpr -\parskip-\baselineskip}\hrule height0pt

\begin{thm}
  Texts in the theorem. Texts in the theorem. Texts in the theorem.
  Texts in the theorem. Texts in the theorem. Texts in the theorem.
  Texts in the theorem. Texts in the theorem. Texts in the theorem.
\end{thm}
Texts after the theorem. Texts after the theorem. Texts after the theorem.
Texts after the theorem. Texts after the theorem. Texts after the theorem.
Texts after the theorem. Texts after the theorem. Texts after the theorem.
Texts after the theorem. Texts after the theorem. Texts after the theorem.
Texts after the theorem. Texts after the theorem. Texts after the theorem.
\end{document} 

相关内容