对齐环境的标题

对齐环境的标题

我想在align环境中的一组方程式下添加标题(即\begin{align} ... \end{align})。我尝试\caption{...}align环境中进行操作,但没有成功。

答案1

您可以使用以下方式强制将标题置于常规浮动之外:caption包裹或微小的capt-of包裹,每个方法\captionof{<float>}都可以诱使 LaTeX 设置浮动标题:

在此处输入图片描述

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

对于自定义标题,我建议创建一个宏来引用该集合,使用类似下面的内容:

在此处输入图片描述

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

答案2

对 Werner 的回答做了一些调整。他的回答存在不允许标题内换行在此处输入图片描述

我已通过修改他的代码解决了该问题。

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

享受您的方程式+标题。:) 在此处输入图片描述

相关内容