Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have used the float package to create an equation float, eqfloat, so I can add captions to equations. Within the eqfloat I used the equation environment to typeset the math.

I want to keep the right hand arabic numbering within parentheses that is added by the equation environment but I also would like the eqfloat caption below the equation to use the same number as the equation environment.

The following code achieves this by making the eqfloat use the same counter as the equation environment and then manually adjusting the equation numbering within each eqfloat.

Is there a better way to make the eqfloat caption reference the current value of the equation environment counter?

Is it possible to prevent the custom float environment from increasing the counter and only to reference the current value of the equation counter?

\documentclass[a4paper]{article}

\usepackage[margin=25pt, labelfont=bf]{caption}
\usepackage{amsmath, amsfonts, pifont, float, color, url}
\usepackage[pdftex, plainpages=false, pdfpagelabels, bookmarks=true]{hyperref}

\newfloat{eqfloat}{h}{eqflts}
\floatname{eqfloat}{Equation}
\makeatletter
\let\c@eqfloat\c@equation
\makeatother

\begin{document}
    ...
    \begin{eqfloat}
        \begin{equation}
            E = mc^2
        \end{equation}
        \addtocounter{equation}{-1}
        \caption{Equation caption here.}
        \label{eq:example}
    \end{eqfloat}

\end{document}
share|improve this question
    
Welcome to TeX.sx! –  Peter Jansson Feb 6 '13 at 13:34
add comment

1 Answer 1

up vote 7 down vote accepted

Package aliascnt can be used for aliasing the counter. It also takes care for the other companion macros of a counter (e.g.\the<counter> or \theH<counter> for hyperref). Therefore the following example uses the class book for a more complicate counter. \newaliascnt is called before \newfloat, because then \newfloat detects the new "counter" and does not assign a counter register.

The line \addtocounter{equation}{-1} can be automated by adding it to \caption inside environment eqfloat.

\documentclass[a4paper]{book}

\usepackage[margin=25pt, labelfont=bf]{caption}
\usepackage{amsmath, amsfonts, pifont, float, color, url}
\usepackage[pdftex, plainpages=false, pdfpagelabels,
bookmarks=true]{hyperref}

\usepackage{aliascnt}
\newaliascnt{eqfloat}{equation}
\newfloat{eqfloat}{h}{eqflts}
\floatname{eqfloat}{Equation}

\newcommand*{\ORGeqfloat}{}
\let\ORGeqfloat\eqfloat
\def\eqfloat{%
  \let\ORIGINALcaption\caption
  \def\caption{%
    \addtocounter{equation}{-1}%
    \ORIGINALcaption
  }%
  \ORGeqfloat
}

\begin{document}
    \chapter{Test}
    \begin{eqfloat}
        \begin{equation}
            E = mc^2
        \end{equation}
        \caption{Equation caption here.}
        \label{eq:example}
    \end{eqfloat}

See \ref{eq:example}.
\end{document}

Result

share|improve this answer
    
Thanks, this does exactly what I wanted –  KeithJ108 Feb 8 '13 at 12:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.