带框/框架的等式周围的文本

带框/框架的等式周围的文本

我想让文本更靠近方程式,但方程式却跳到了下一行。方程式框还坚持居中,而不是紧贴边距。

有没有办法自动适应wrapfigure/ tcolorboxempheq将框一直对齐到边缘,并使文本更靠近?

\documentclass[a4paper,12pt]{report}
\usepackage[many]{tcolorbox}
\usepackage{empheq}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage{wrapfig}
\usepackage{blindtext}

\tcbset{enhanced,boxrule=0.8pt,bottomrule=1.6pt,arc=0pt,auto outer arc,lifted shadow={1mm}{-1mm}{2mm}{0.1mm}{gray!60}}
\newtcbox{\eqbox}[2]{nobeforeafter,math upper,colback=#1,colframe=#2}
\setlength\intextsep{0pt}



\begin{document}

\section{Electric Power}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

\begin{wrapfigure}[4]{r}{10.2em}
\begin{empheq}[box=\eqbox{green!70!blue}{green!50!black},box align=right]{equation*}
    P = \frac{\mathrm{d}w}{\mathrm{d}t}
\end{empheq}
\end{wrapfigure}

\blindtext

\begin{wrapfigure}[4]{r}{10em}
\begin{empheq}[box=\eqbox{red!20}{red!40},box align=right]{equation*}
    P = \frac{\mathrm{d}w}{\mathrm{d}t}
\end{empheq}
\end{wrapfigure}

\blindtext

\begin{wrapfigure}[4]{l}{10em}
\begin{empheq}[box=\eqbox{red!20}{red!40},box align=right]{equation*}
    P = \frac{\mathrm{d}w}{\mathrm{d}t}
\end{empheq}
\end{wrapfigure}

\blindtext

\end{document}

答案1

\InsertBoxR使用纯 TeX 宏包中的命令进行调整要容易得多insbox。此命令接受两个强制参数:插入框之前下一段中未缩短的行数,以及插入的框,以及一个可选参数,即补充的较短行数,以防 TeX 错误地计算较短行数。equation*这里不需要使用 - 我用一个简单的替换了它$\displaystyle ... $。最后,我加载了esdiff更简单的输入 od(偏导数或非偏导数):

\documentclass[a4paper,12pt]{report}
\usepackage[many]{tcolorbox}
\usepackage{esdiff}
\usepackage{siunitx}
\usepackage{blindtext}

\tcbset{enhanced,boxrule=0.8pt,bottomrule=1.6pt,arc=0pt,auto outer arc,lifted shadow={1mm}{-1mm}{2mm}{0.1mm}{gray!60}}
\newtcbox{\eqbox}[2]{nobeforeafter,math upper,colback=#1,colframe=#2}
\setlength\intextsep{0pt}

\input{insbox}

\begin{document}

\section{Electric Power}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

\InsertBoxR{0}{\eqbox{green!70!blue}{green!50!black}{\displaystyle P = \diff{w}{t}}}
\blindtext

\InsertBoxR{3}{\eqbox{red!20}{red!40}{\displaystyle P = \diff{w}{t}}}
\blindtext

\InsertBoxR{0}{\eqbox{red!20}{red!40}{\displaystyle P = \diff{w}{t}}}
\blindtext

\end{document} 

在此处输入图片描述

答案2

您的方法的问题在于您使用了empheq,它非常适合向 AMS 方程环境添加奇特的东西。然而,对于wrapfigures 来说,它就没那么好了,因为方程有缩进、居中等等。所以我建议换个方式,把内联方程装箱。这可以使用tcolorbox您定义的 来完成。下面为您提供了一个可以做到这一点的环境。它测量方程的宽度和高度,并wrapfigure相应地构建 ,同时考虑到分别存储在/eqrwapbox/xsep和中的一些宽限距离/eqrwapbox/ysep,以便您在需要时更方便地更改它们。结果环境称为InlayEq,其用法的一个示例是

\begin{InlayEq}{red!20}{red!40}
P = \frac{\mathrm{d}w}{\mathrm{d}t}
\end{InlayEq}

这是相应的 MWE:

\documentclass[a4paper,12pt]{report}
\usepackage[many]{tcolorbox}
\usepackage{empheq}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage{wrapfig}
\usepackage{blindtext}

\tcbset{enhanced,boxrule=0.8pt,bottomrule=1.6pt,arc=0pt,auto outer arc,lifted
shadow={1mm}{-1mm}{2mm}{0.1mm}{gray!60},}
\newtcbox{\eqbox}[2]{nobeforeafter,math upper,colback=#1,colframe=#2}
\setlength\intextsep{0pt}

\usepackage{environ}
\newbox\EqSaveBox
\pgfkeys{/eqrwapbox/.cd,xsep/.initial=0.4em,ysep/.initial=1ex}
\NewEnviron{InlayEq}[3][r]{\begin{lrbox}{\EqSaveBox}
\eqbox{#2}{#3}{\ensuremath{\displaystyle\BODY}}%
\end{lrbox}%
\pgfmathsetmacro{\mywd}{\the\wd\EqSaveBox+\pgfkeysvalueof{/eqrwapbox/xsep}}%
\pgfmathtruncatemacro{\myln}{(\the\ht\EqSaveBox+2*\pgfkeysvalueof{/eqrwapbox/ysep})/12}%
\pgfmathsetmacro{\myrest}{(\myln*12pt-\the\ht\EqSaveBox)}%
\edef\temp{\noexpand\wrapfigure[\myln]{#1}{\mywd pt}}%
\temp
\vspace*{\myrest pt}%
\hfill\usebox\EqSaveBox
\endwrapfigure}

\begin{document}

\section{Electric Power}


Lorem ipsum dolor sit amet, consectetuer adipiscing elit.


\begin{InlayEq}{green!70!blue}{green!50!black}
P = \frac{\mathrm{d}w}{\mathrm{d}t}
\end{InlayEq}

\blindtext

\blindtext


\begin{InlayEq}{red!20}{red!40}
P = \frac{\mathrm{d}w}{\mathrm{d}t}
\end{InlayEq}

\blindtext

\begin{InlayEq}[l]{red!20}{red!40}
P = \frac{\mathrm{d}w}{\mathrm{d}t}
\end{InlayEq}

\noindent
\blindtext

\end{document}

在此处输入图片描述

它没有解决分页符问题,因为这是一个固有问题wrapfig,据我所知,没有解决方案。但我认为其他问题都得到了解决。

相关内容