Math & ScienceCustom equation numbering

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
magicmoose
Posts: 90
Joined: Fri Nov 06, 2009 7:29 am

Custom equation numbering

Post by magicmoose »

Hi,

I have some special equations in my document that I want to label differently to the rest. I want the to be labelled like (C1), (C2), etc. At the moment all I have managed to do is use

Code: Select all

\begin{equation*} \sum_i x_{ij}\leq 1\quad\text{for each $j=1,\ldots,J$.} \tag{C1}\end{equation*}
but I would like it to be automatic and be so that I can reference to them.

Thanks
Last edited by magicmoose on Tue Oct 12, 2010 11:34 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Custom equation numbering

Post by gmedina »

Hi,

you could define a new equation-like environment with its own counter and its appropriate representation; take a look at the following example:

Code: Select all

\documentclass{article}
\usepackage{amsmath}

\newcounter{Cequ}
\newenvironment{CEquation}
  {\stepcounter{Cequ}%
    \addtocounter{equation}{-1}%
    \renewcommand\theequation{C\arabic{Cequ}}\equation}
  {\endequation}

\begin{document}

\begin{CEquation}\label{equ:1}
  a = b.
\end{CEquation}

\begin{equation}
  c=d.
\end{equation}

\begin{CEquation}\label{equ:2}
  e = f.
\end{CEquation}

As we can see from equations \eqref{equ:1} and \eqref{equ:2}
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
magicmoose
Posts: 90
Joined: Fri Nov 06, 2009 7:29 am

Re: Custom equation numbering

Post by magicmoose »

Thanks a lot, thank is really nice :)

Can this be extended for align environments as well?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Custom equation numbering

Post by gmedina »

magicmoose wrote:Thanks a lot, thank is really nice :)

Can this be extended for align environments as well?
You're welcome, and yes, it can be extended; here's a little example:

Code: Select all

\documentclass{article}
\usepackage{amsmath}

\newcounter{Cequ}
\newcounter{Caux}

\newenvironment{CEquation}
  {\stepcounter{Cequ}%
    \addtocounter{equation}{-1}%
    \renewcommand\theequation{C\arabic{Cequ}}\equation}
  {\endequation}

\newenvironment{CAlign}
  {\setcounter{Caux}{\theequation}
    \setcounter{equation}{\theCequ}%
    \renewcommand\theequation{C\arabic{equation}}
    \align}
  {\endalign\setcounter{Cequ}{\value{equation}}\setcounter{equation}{\theCaux}}

\begin{document}

\begin{CEquation}\label{equ:1}
  a = b.
\end{CEquation}

\begin{equation}
  c=d.
\end{equation}

\begin{CEquation}\label{equ:2}
  e = f.
\end{CEquation}

\begin{CAlign}
  e &= f \label{equ:4} \\
  &= g  \label{equ:5}.
\end{CAlign}

\begin{equation}
  c=d.
\end{equation}

\begin{CEquation}\label{equ:6}
  e = f.
\end{CEquation}

\begin{equation}\label{equ:7}
  c=d.
\end{equation}

As we can see from equations \eqref{equ:1} and \eqref{equ:2}
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
magicmoose
Posts: 90
Joined: Fri Nov 06, 2009 7:29 am

Re: Custom equation numbering

Post by magicmoose »

Thanks a lot that is exactly what I what I was hoping for :D
Post Reply