简体   繁体   English

在 LaTeX 中为方程添加标题

[英]Adding a caption to an equation in LaTeX

Well, it seems simple enough, but I can't find a way to add a caption to an equation.嗯,这看起来很简单,但我找不到为方程添加标题的方法。 The caption is needed to explain the variables used in the equation, so some kind of table-like structure to keep it all aligned and pretty would be great.需要标题来解释方程中使用的变量,因此某种类似于表格的结构以保持所有对齐和美观会很棒。

The \\caption command is restricted to floats: you will need to place the equation in a figure or table environment (or a new kind of floating environment). \\caption命令仅限于浮点数:您需要将方程放置在图形或表格环境(或一种新的浮动环境)中。 For example:例如:

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

The point of floats is that you let LaTeX determine their placement.浮点数的关键在于您让 LaTeX 确定它们的位置。 If you want to equation to appear in a fixed position, don't use a float.如果你想让方程出现在一个固定的位置,不要使用浮点数。 The \\captionof command of the caption package can be used to place a caption outside of a floating environment. 字幕包\\captionof命令可用于将字幕放置在浮动环境之外。 It is used like this:它是这样使用的:

\[ E = m c^2 \]
\captionof{figure}{A famous equation}

This will also produce an entry for the \\listoffigures , if your document has one.如果您的文档有一个条目,这也会为\\listoffigures生成一个条目。

To align parts of an equation, take a look at the eqnarray environment , or some of the environments of the amsmath package: align, gather, multiline,...要对齐方程的一部分,请查看eqnarray环境amsmath包的一些环境:align、gather、multiline...

You may want to look at你可能想看看http://tug.ctan.org/tex-archive/macros/latex/contrib/float/ which allows you to define new floats using \\newfloat http://tug.ctan.org/tex-archive/macros/latex/contrib/float/允许您使用\\newfloat定义新的浮点数

I say this because captions are usually applied to floats.我这样说是因为标题通常应用于浮动。

Straight ahead equations (those written with $ ... $ , $$ ... $$ , begin{equation}... ) are in-line objects that do not support \\caption .直接方程(用$ ... $$$ ... $$begin{equation}...编写的那些)是不支持\\caption对象。

This can be done using the following snippet just before \\begin{document}这可以在\\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
}

and when adding an equation use something like并在添加方程时使用类似的东西

\begin{eqfloat}
\begin{equation}
f( x ) = ax + b
\label{eq:linear}
\end{equation}
\caption{Caption goes here}
\end{eqfloat}

As in this forum post by Gonzalo Medina , a third way may be:正如在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}

More details of the commands used from package caption : here .caption使用的命令的更多详细信息: here

A screenshot of the output of the above code:上面代码的输出截图:

输出截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM