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.
Asked
Active
Viewed 1.3k times
9
Javad
- 763
- 2
- 7
- 8
2 Answers
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:

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

\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}
Werner
- 603,163
-
Thanks. How can I have a customized caption for my
alignenvironment. E.g.,Equation set 1:instead ofFigure 1:. – Javad Apr 20 '14 at 05:24 -
2The use of
\captionofwithout a proper container (such ascenter,minipageor 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\captionofhad been used without container!). – Gonzalo Medina Apr 20 '14 at 05:26 -
@GonzaloMedina: I know that
\captionofwithout container allows you to use\captionas-is afterwards, since\@captypehas been set - the only test used to see whether\captionis valid. – Werner Apr 20 '14 at 05:28 -
@Javad: Do you have a bunch of these "equation sets"? I've added something to manage this. Perhaps it's sufficient. – Werner Apr 20 '14 at 05:29
-
@Werner but that's not what I meant; using no container can produce odd results (not errors, but certainly problems). I wish I could find the relevant thread :( – Gonzalo Medina Apr 20 '14 at 05:34
-
@GonzaloMedina Were you thinking of any of these? \captionof messes with paragraph indent parskip=half option ignored after captionof – Torbjørn T. Jul 22 '15 at 21:46
-
@TorbjørnT.:
\captionofsets\@captype. It means that you can use\captionof{table}{..}in one place, and then somewhere else\caption(outside of a float, but in the same group) and still yield atablecaption. – Werner Jul 22 '15 at 21:49 -
@TorbjørnT. Those can be used as examples too, but no. The one I have in mind is more "spectacular". The problem manifested after several pages. – Gonzalo Medina Jul 22 '15 at 21:50
-
@Werner I know, you said that already, Gonzalo was looking for something else. – Torbjørn T. Jul 22 '15 at 21:51
-
@Werner - I used this method and got nice captions. Then I added corresponding
\label{}'s. But where my caption might beTable 2., a reference to the label comes out as2.6. How can I fix that? – CAB Mar 21 '17 at 20:14 -
1
-
@Werner, no, I had the
\labelon a separate line. It works fine now. Thanks! – CAB Mar 31 '17 at 19:33
2
A little tweak on Werner's answer. His answer has the problem of not allowing line break inside the caption.

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}
loved.by.Jesus
- 3,848

\captionis associated with a float, which has an accompanying counter representation. For exampleFigure 1:orTable 2:. What would you want in this case for youralignenvironment? Or do you not want any of that? – Werner Apr 20 '14 at 04:42Figure 1:for myalignenvironment. – Javad Apr 20 '14 at 04:45captionorcapt-ofprovide a\captionof{figure}{...}. – Heiko Oberdiek Apr 20 '14 at 04:57