标记自定义环境,如方程式

标记自定义环境,如方程式

我试图以与标记一组方程式相同的方式标记一组自定义环境,如下面的输出所示。即,我希望“反应 1”以与行末的“方程式 1”相同的方式显示。

在此处输入图片描述

我已设法用计数器正确标记环境,并且它们在块文本中被正确引用。但是,我无法找到在输出行末尾显示标签的方法。我是 LATEX 新手,因此任何建议都将不胜感激!

输入如下:

\documentclass[12pt,a4paper]{report}
\usepackage{chemfig}
\setatomsep{2em}
\usepackage[fleqn]{amsmath}
\setlength{\mathindent}{0pt}
\renewcommand\theequation{Equation\,\arabic{equation}}
\setcounter{equation}{0}

%%%%%%%%%%PROBLEM INPUT
\newcounter{reaction}
\renewcommand\thereaction{Reaction\,\arabic{reaction}}
\setcounter{reaction}{0}
\newenvironment{reaction}[1][]{\refstepcounter{reaction}}
%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

The general formula for the curative needed is given by 

\ref{RequiredCurative}. 
\begin{equation}\label{RequiredCurative} a = b + c\end{equation} \par 
A generic curing reaction as described above is shown in \ref{Curing} below.\medskip 
\begin{flushleft}\begin{reaction}\label{Curing}\chemfig{A-B -> C-D}\end{reaction}\end{flushleft}

\end{document}

答案1

因为只需要一行“反应”,所以将编号放在reaction环境的结束代码中就足够了。然而,OP 中缺少结束代码。

该宏\reactionfmt是一个包装器,可以更轻松地更改格式。

\documentclass[12pt,a4paper]{report}
\usepackage{chemfig}
\setatomsep{2em}
\usepackage[fleqn]{amsmath}
\setlength{\mathindent}{0pt}
\renewcommand\theequation{Equation\,\arabic{equation}}
\setcounter{equation}{0}

%%%%%%%%%%PROBLEM INPUT
\newcounter{reaction}
\renewcommand\thereaction{Reaction\,\arabic{reaction}}
\setcounter{reaction}{0}
\newenvironment{reaction}[1][]{\refstepcounter{reaction}}{\hfill\reactionfmt}

\newcommand{\reactionfmt}{(\thereaction)}
%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

The general formula for the curative needed is given by 

\ref{RequiredCurative}. 
\begin{equation}\label{RequiredCurative} a = b + c\end{equation} \par 
A generic curing reaction as described above is shown in \ref{Curing} below.\medskip 
%\begin{flushleft}
  \begin{reaction}\label{Curing}
    \chemfig{A-B -> C-D}
  \end{reaction}
%\end{flushleft}

\end{document}

在此处输入图片描述

相关内容