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.
2 Answers
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}
-
Thanks. How can I have a customized caption for my
align
environment. E.g.,Equation set 1:
instead ofFigure 1:
.– JavadCommented Apr 20, 2014 at 5:24 -
2The use of
\captionof
without a proper container (such ascenter
,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
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}
\caption
is associated with a float, which has an accompanying counter representation. For exampleFigure 1:
orTable 2:
. What would you want in this case for youralign
environment? Or do you not want any of that?Figure 1:
for myalign
environment.caption
orcapt-of
provide a\captionof{figure}{...}
.