9

I would like to add a caption under a set of equations that I have in the align environment (i.e., \begin{align} ... \end{align}). I tried \caption{...} inside the align environment, but it didn't work.

3
  • Typically a \caption is associated with a float, which has an accompanying counter representation. For example Figure 1: or Table 2:. What would you want in this case for your align environment? Or do you not want any of that?
    – Werner
    Commented Apr 20, 2014 at 4:42
  • I would like to get something like Figure 1: for my align environment.
    – Javad
    Commented Apr 20, 2014 at 4:45
  • Package caption or capt-of provide a \captionof{figure}{...}. Commented Apr 20, 2014 at 4:57

2 Answers 2

7

You can force a caption outside a regular float using the caption package or the tiny capt-of package, each providing \captionof{<float>} which tricks LaTeX into setting a float-like caption:

enter image description here

\documentclass{article}
\usepackage{amsmath,capt-of,lipsum}
\begin{document}
\lipsum*[1]
\begin{align}
  f(x) &= ax^2 + bx + c \\
       &= g(x)
\end{align}

\begingroup\vspace*{-\baselineskip}
\captionof{figure}{A beautiful equation.}
\vspace*{\baselineskip}\endgroup

\lipsum*[2]
\end{document}

For a custom caption, I'd suggest creating a macro to reference the set using something like the following:

enter image description here

\documentclass{article}
\usepackage{amsmath,lipsum}
\newcounter{equationset}
\newcommand{\equationset}[1]{% \equationset{<caption>}
  \refstepcounter{equationset}% Step counter
  \noindent\makebox[\linewidth]{Equation set~\theequationset: #1}}% Print caption
\begin{document}
\lipsum*[1]
\begin{align}
  f(x) &= ax^2 + bx + c \\
       &= g(x)
\end{align}
\equationset{A beautiful equation.}

\medskip

\lipsum*[2]
\end{document}
12
  • Thanks. How can I have a customized caption for my align environment. E.g., Equation set 1: instead of Figure 1:.
    – Javad
    Commented Apr 20, 2014 at 5:24
  • 2
    The use of \captionof without a proper container (such as center, minipage or similar) can produce unexpected results; I can't find now the question in this site illustrating this in a spectacular way (the problem appeared several pages after \captionof had been used without container!). Commented Apr 20, 2014 at 5:26
  • @GonzaloMedina: I know that \captionof without container allows you to use \caption as-is afterwards, since \@captype has been set - the only test used to see whether \caption is valid.
    – Werner
    Commented Apr 20, 2014 at 5:28
  • @Javad: Do you have a bunch of these "equation sets"? I've added something to manage this. Perhaps it's sufficient.
    – Werner
    Commented Apr 20, 2014 at 5:29
  • 1
    @CAB: Are you using \equationset{Caption\label{abc}}?
    – Werner
    Commented Mar 21, 2017 at 21:07
2

A little tweak on Werner's answer. His answer has the problem of not allowing line break inside the caption. enter image description here

I have fixed the problem modifying his code.

\documentclass{article}
\usepackage{amsmath}
\usepackage{calc}
\usepackage{ifthen}

%-- Defines a CAPTION for a set of equations and numbers
%   the set of equations is numbered
% note: the caption adapts the text alignment to the length. 
\newcounter{captionedequationset} %numbering
\newdimen\captionlength
\newcommand{\captionedequationset}[1]{
    \refstepcounter{captionedequationset}% Step counter
    \setlength{\captionlength}{\widthof{#1}} %
    \addtolength{\captionlength}{\widthof{Equation set~\thecaptionedequationset: }}
    %If the caption is shorter than the line width then
    % the caption is centred, otherwise is flushed left.
    \ifthenelse{\lengthtest{\captionlength < \linewidth }} %
    {\begin{center}
            Equation set~\thecaptionedequationset: #1
        \end{center}} 
    { \begin{flushleft} 
        Equation set~\thecaptionedequationset: #1 %
        \end{flushleft}}}

\begin{document}

  \begin{gather}
      ax^2 +bx+c \\
      \sin(\omega x) + \cos(\omega x) 
  \end{gather}
  \captionedequationset{Lovely!} 

  \begin{gather}
      ax^2 +bx+c \\
      \sin(\omega x) + \cos(\omega x) 
  \end{gather}
  \captionedequationset{These are probably the cutest equations ever seen in \LaTeX---I really like them!---but somebody else may think differently. }

\end{document}

Enjoy your equations+captions. :) enter image description here

You must log in to answer this question.

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