调整相对于 \newenvironment 的方程编号缩进

调整相对于 \newenvironment 的方程编号缩进

我正在为讲义中解释的示例创建一个新环境(高级环境),但是当我在新建的示例环境中使用方程环境创建方程时,它不符合我在环境中设置的缩进。这可能吗?

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes.symbols}
\usepackage{lipsum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Example Environment 
\newcounter{boxnum}
\newenvironment{egenv}[1]{%
\begingroup\addvspace\medskipamount%
  \stepcounter{boxnum}{\sffamily\bfseries\large EXAMPLE
  \tikz [baseline=(char.base)] \node[shape=rectangle,draw=blue!50,inner sep=2.5pt,fill=Cerulean,text=white] (char) {\arabic{boxnum}};%
  \quad{#1}\vskip0.75\baselineskip}
  \setlength{\leftskip}{20pt}%
  \setlength{\rightskip}{20pt}%
  \setlength{\parfillskip}{0pt plus 2fil}
}{%
  \par\hfill{\color{Cerulean}$\blacksquare$}%
  \par\addvspace\medskipamount%
\endgroup
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\parindent0pt
\begin{document}

\lipsum[2]
\begin{equation}
  (x-h)^2+(y-k)^2=r^2
\end{equation}

\begin{egenv}{Combined (double) Inequalities}
\lipsum[3]
\end{egenv}

\begin{egenv}{Combined (double) Inequalities}
\lipsum[3]
\begin{equation}\label{stdform}
  (x-h)^2+(y-k)^2=r^2
\end{equation}
\begin{equation}\label{stdformnn}
  (x-h)^2+(y-k)^2=r^2
\end{equation}
\lipsum[3]
\end{egenv}
\end{document}

得出:

在此处输入图片描述

当然,我希望方程编号在我的环境之外恢复其正常的右缩进。我看过使用 amsmath 更改方程编号的外观这似乎做了我想要做的事情:

\makeatletter
\let\mytagform@=\tagform@
\def\tagform@#1{\maketag@@@{\bfseries(\ignorespaces#1\unskip\@@italiccorr)}\hspace{20pt}}
\renewcommand{\eqref}[1]{\textup{\mytagform@{\ref{#1}}}}
\makeatother

但上述影响是全球性的。任何对此问题的帮助都将不胜感激。

答案1

有几种方法可以解决这个问题 - 如果你不介意加载包,那么你可以使用包adjustwidth中的环境changepage并使用

\begin{adjustwidth}{20pt}{20pt}

在此处输入图片描述

您还可以使用list环境(这是changepage包所做的),这也可能有助于您的“终点标记”(请参阅​​下面的注释)。

其他一些注意事项:

  • 你可能希望使用假设你稍后\refstepcounter可能会想要\label和你的环境\ref
  • “结束标记”不能保证与环境保持一致。您可以尝试通过制作“不中断项目”来解决这个问题,详情如下https://tex.stackexchange.com/a/47586/6621

我已list在下面的 MWE 中留下了解决方案的评论,以便您可以随意尝试一下。

平均能量损失

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{changepage}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes.symbols}
\usepackage{lipsum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Example Environment 
\newcounter{boxnum}
\newenvironment{egenv}[1]{%
\begingroup\addvspace\medskipamount%
  \refstepcounter{boxnum}{\sffamily\bfseries\large EXAMPLE
  \tikz [baseline=(char.base)] \node[shape=rectangle,draw=blue!50,inner sep=2.5pt,fill=Cerulean,text=white] (char) {\arabic{boxnum}};%
  \quad{#1}\vskip0.75\baselineskip}
 % You can experiment with the `list` environment if you like
 % \begin{list}{}{%
 % \setlength{\leftmargin}{20pt}%
 % \setlength{\rightmargin}{20pt}%
 % \setlength{\parfillskip}{0pt plus 2fil}
 % }%
 %\item%
 \begin{adjustwidth}{20pt}{20pt}
}{%
  \par\hfill{\color{Cerulean}$\blacksquare$}%
  %\item\hfill{\color{Cerulean}$\blacksquare$}%
  %\end{list}
  \end{adjustwidth}
  \par\addvspace\medskipamount%
\endgroup
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\parindent0pt
\begin{document}

\lipsum[2]
\begin{equation}
  (x-h)^2+(y-k)^2=r^2
\end{equation}

\begin{egenv}{Combined (double) Inequalities}
\lipsum[3]
\end{egenv}

\begin{egenv}{Combined (double) Inequalities}
\lipsum[3]
\begin{equation}\label{stdform}
  (x-h)^2+(y-k)^2=r^2
\end{equation}
\begin{equation}\label{stdformnn}
  (x-h)^2+(y-k)^2=r^2
\end{equation}
\lipsum[3]
\end{egenv}
\end{document}

相关内容