2

I'm trying to tag a set of custom environments in the same way I've tagged a set of equations as in the output below. i.e. I'd like "Reaction 1" to display in the same way as "Equation 1" at the end of the line.

enter image description here

I've managed to label the environments correctly with a counter, and they are correctly referenced in the block text. However, I'm unable to find a way to display the tag at the end of the output line. I'm new to LATEX so any suggestions would be greatly appreciated!

Input is as follows:

\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}
4
  • Does your reaction environment have only one line? It is quite easy then. By the way, your reaction environment definition is missing the {} code statement.
    – user31729
    Commented Feb 9, 2017 at 22:22
  • Thanks. Yes, only one line for the foreseeable cases
    – AndyC
    Commented Feb 9, 2017 at 23:31
  • \hfill will generally overpower things like flushleft, flushright and center. It expands to fill all the unused space in a line. Commented Feb 10, 2017 at 1:52
  • Maybe have a look at the numberedblock package: ctan.org/pkg/numberedblock Commented Feb 10, 2017 at 18:06

1 Answer 1

1

As there is only one line 'reaction' required, it is sufficient to put the numbering in the end code of the reaction environment. The end code has been missing in the O.P., however.

The macro \reactionfmt is wrapper for easier change of formatting.

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .