在LaTeX中给一个公式添加标题

60

看起来很简单,但我找不到一种方法来为方程添加标题。 需要标题来解释方程中使用的变量,因此保持所有内容对齐和美观的表格结构将会很好。


你所说的“equation”,是指定理吗? - dmckee --- ex-moderator kitten
实际上我是指一个公式,带有一些变量,然后在下面的文本中解释了每个变量的含义。 - Farinha
通常可以通过在文本中提供解释来实现这一点——为此,latex 提供了行内数学模式、公式环境、定理环境等。如果您想将您的工作与文本区分开来,请使用下面解释的 float 包。 - dmckee --- ex-moderator kitten
3个回答

63

\caption命令只能用于浮动体:您需要将方程式放置在一个图形或表格环境中(或者是一种新的浮动环境)。例如:

\begin{figure}
\[ E = m c^2 \]
\caption{A famous equation}
\end{figure}

浮动体的目的在于让 LaTeX 决定其位置。如果您希望公式出现在固定位置,则不要使用浮动体。caption package\captionof 命令可用于将标题放置在非浮动环境之外。使用方法如下:
\[ E = m c^2 \]
\captionof{figure}{A famous equation}

这也会在文档中生成一个条目,如果你的文档有 \listoffigures 的话。
要对齐方程的部分,请查看 eqnarray 环境 或者 amsmath 包的一些环境:align、gather、multiline 等等。

1
在我的看法中,向\listoffigures中添加一个不需要的条目是这种方法的致命缺陷。 - WolfLink

12

就像Gonzalo Medina在论坛帖子中所述,第三种方法可能是:

\documentclass{article}
\usepackage{caption}

\DeclareCaptionType{equ}[][]
%\captionsetup[equ]{labelformat=empty}

\begin{document}

Some text

\begin{equ}[!ht]
  \begin{equation}
    a=b+c
  \end{equation}
\caption{Caption of the equation}
\end{equ}

Some other text
 
\end{document}

caption包中使用的命令的更多细节: 这里
上述代码的输出截图: 输出截图

1
这个问题在我的标题前面添加了“1:”,但是我的方程式编号为(5)。我该如何从标题中删除“1:”?另外,链接已失效。 - MattS
1
这是如何操作的。使用caption*代替caption\caption*{公式5:我的文本} - MattS
1
@MattS 太棒了!感谢您丰富了这个答案,链接现在已更新! - MattAllegro

12

你可能需要查看http://tug.ctan.org/tex-archive/macros/latex/contrib/float/,它允许您使用\newfloat定义新的浮动体。

我这么说是因为标题通常应用于浮动体上。

直接编写的方程(使用$ ... $$$ ... $$begin{equation}...)是行内对象,不支持\caption

可以在\begin{document}之前使用以下片段实现此目的。

\usepackage{float}
\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{eqfloat}
\begin{equation}
f( x ) = ax + b
\label{eq:linear}
\end{equation}
\caption{Caption goes here}
\end{eqfloat}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接