[Basic skills of papers] [LaTeX] formulas and their numbers

When writing science and engineering papers, it is inevitable to use a lot of formulas. Every time I write a thesis, even if it is a used publicity format, I need to find the previous template or check it online now. The former tests my file resource management, and the latter may require a lot of testing, which is very troublesome. Therefore, I decided to organize a version by myself, and add it as I use it, so that I can check it in the future. At the same time, everyone is welcome to collect and help me improve together, thank you~

0. Icon index

In order to facilitate intuitive search, all the correct formats implemented by this blog are listed below, and you can directly click to navigate.
equation basic format
equation basic format
equation multi-line equation
equationMultiline formula
equation does not number formula
equation*
subequations basic format
basic format of subequations
subequations only number some rows
Only number some lines in subequations
subequations formulas have classification (such as piecewise function)
There are classifications of formulas
subequations piecewise function numbering line by line (you can only number some lines)
free number per line
align for each line of the formula Numbering (not sub-numbering)
Separate numbering (not subnumbering) for each row of the formula
align Only number the last row of the formula (not sub-numbering)
Separate numbering (not subnumbering) for only the last row of the formula

1. equation: the whole formula has only one number

1) Basic format

% 整个公式只有一个编号
\begin{equation}\label{eqn-1} 
  y = ax + b
\end{equation}

equation basic format
The label is added to cite the formula in the text. When quoting, just use "\eqref{label name}" (there should be no spaces after the backslash "\", here is to avoid CSDN format display problems), such as "\eqref{eqn-1}", display The format of is "(equation number)", such as "(1)". The format using "\ref{label name}" (no space after the backslash "\") can also be quoted, but the display format does not have parentheses, only the formula number, such as "1". The latter is recommended when citing figures, tables or algorithms. In addition, note that the label is unique, and the same label cannot appear in the paper. Once there are duplicate labels, although no error will be reported during compilation, confusion will occur when referencing.

2) Multiple lines

When you need to use multi-line formulas, you can use the following format.

% 整个公式只有一个编号,
\begin{equation}\label{eqn-2}
  \begin{aligned}
    y & = ax + b\\
    z & = cx + d
  \end{aligned}
\end{equation}

equationMultiline formula
The aligned is used to realize the multi-line formula in the equation and can assist the alignment of each line in the formula, and the alignment position uses "&". The number of "&" is not limited, and it can even be 0, but the number of "&" used in each line must be the same, otherwise an error will be reported during compilation.

If you don't nest aligned , the second thing is that the lines cannot be aligned, and the most important thing is that line breaks cannot be achieved.

% 错误演示:不嵌套aligned的equation
\begin{equation}\label{eqn-3}
    y = ax + b\\
    z = cx + d
\end{equation}

Aligned equation formulas without nesting

3) Unnumbered formulas

Sometimes the formula used does not need to be numbered, and equation* can be used instead . The difference from the previous one is that this format adds a "*" after the equation . Specific examples are as follows.

% 此时相应公式不编号,因没有编号,故无法引用
\begin{equation*}
  \begin{aligned}
    y & = ax + b\\
    z & = cx + d
  \end{aligned}
\end{equation*}

equation*

2. subequations: Each line of the formula has a subnumber

Using equation can solve our needs to a certain extent, but when citing a formula in a paper, sometimes you only want to cite a certain sub-line in the formula, that is to say, it is best for each line of the formula to have its own number. At this time, use Subequations are the most convenient and direct way.

1) Basic format

%每个子行都有唯一编号
\begin{subequations}\label{eqn-4}
  \begin{align}
    y & = a + b\\
    z & = c + d
  \end{align}
\end{subequations}

basic format of subequations
Among them, align is also used for the alignment of each row in the formula. It should be noted that the ones here are different from those nested in the equation , not aligned . The basic usage of align is the same as that of aligned , and "\\" is also used to wrap lines, and "&" is used to assist alignment.

Note: If align is changed to align* , the function of not numbering the formula can also be realized. That is, remove the last two numbers in the figure above.

Nested align is necessary here , otherwise the formula will be numbered and can be quoted, but it will not be displayed, which will lead to confusion in the numbering of the formula; and at this time, the content display rules in subequations are consistent with the text (including font, indentation, writing The formula needs to add "$", etc.).

%有编号也能引用但不显示,内容的显示规则与正文一致
\begin{subequations}\label{eqn-5}
    y = ax + b\\
    \indent z = cx + d
\end{subequations}

Subequations without nested align

2) Only number some rows

Sometimes in the paper there will be a formula derivation process, in which case the intermediate steps do not need to be numbered. In order to achieve this, just add **\nonumber** at the end of the line that does not need to be numbered (before the newline "\\"), as follows:

\begin{subequations}\label{eqn-6}
  \begin{align}
    y & = ax + (bx+c) \nonumber\\
     & = (a + b)x + c\\
    z & = mx + (nx+p) \nonumber\\
     & = (m + n)x + p
  \end{align}
\end{subequations}

Only number some lines in subequations

3) There are classification situations in the formula (such as piecewise function)

In some cases, piecewise functions need to be used in papers, that is, different results are obtained under different conditions, and cases are needed at this time .

\begin{subequations}\label{eqn-7}
  \begin{align}
    y & =
    \begin{cases}
      a x^2 + b x + d, & \mbox{if}~x > 0 \\
      cx + d, & \mbox{otherwise}
    \end{cases}\\
    z & =
    \begin{cases}
      mx + p, & \mbox{if}~x > 1 \\
      nx + q, & \mbox{otherwise}
    \end{cases}
  \end{align}
\end{subequations}

There are classifications of formulas
Note that "\mbox{text content}" is required to display the text in the formula, and it is necessary to use "~" to add a space between the text and the variable in the formula. If "\mbox" is not used, the display effect of the first "otherwise" in the figure below will appear; if "~" is not used, "if" and " xx " will appearx "pasted together.
Bad example without using \mbox and ~

Cases can also be nested in the equation, using the same method.

4) The piecewise function is numbered line by line (you can only number some lines)

In some cases, the multi-line formula shown in the paper is a system of equations that needs to be combined, that is, a brace needs to be added to the leftmost side of the formula, and cases can be used at this time . But if each line on the right side of the curly braces needs to be numbered, then a new method needs to be introduced. numcases is suggested here .

% 使用numcases需要现在文档开头引入宏包cases(注意包名不是numcases)
\usepackage{cases}
...
\begin{subequations}\label{eqn-8}
  \begin{numcases}{\mbox{case}~1:}
      m = 3x + 2y + 5z \label{eqn-8-1}\\
      n = 2x + 5y + 3z \notag\\
      p = 3x + 4y + 2z \label{eqn-8-3}
  \end{numcases}
\end{subequations}

free number per line
Note that if a line does not need to be numbered, just add "\notag" at the end of the line (before the line break "\\"), and adding "\label{}" does not affect the actual numbering.
If it is just a simultaneous equation, you can directly remove the content on the left side of the braces, as shown in the following example

\begin{subequations}\label{eqn-8}
  \begin{numcases}{} % 这里相对于前面的变化在于,去掉了{}中的内容
      m = 3x + 2y + 5z \label{eqn-8-1}\\
      n = 2x + 5y + 3z \notag\\
      p = 3x + 4y + 2z \label{eqn-8-3}
  \end{numcases}
\end{subequations}

Simultaneous equations with row numbering

References: Baidu Library - Latex - Entry, Number, Description

The only inelegant thing about this method is that it cannot be aligned. If you nest aligned (not align ) in numcases , you can achieve alignment, but you can't achieve line-by-line numbering. If you have a more elegant way of writing, welcome to share in the comment area~

3. align: Each line is individually numbered (not a sub-number)

1) Number each line of the formula separately (not sub-number)

\begin{align}\label{eqn-9}
      y & = a n^3 + b n^2 + c n + d \nonumber\\
      & = a n^3
\end{align}

Separate numbering (not subnumbering) for each row of the formula

2) Only number the last line of the formula separately (not subnumber)

\begin{align}
      y & = a n^3 + b n^2 + c n + d \nonumber\\
      & = a n^3 \label{eqn-9}
\end{align}

Separate numbering (not subnumbering) for only the last row of the formula

4. Super long formula

1) Display super-long formulas side by side in two columns of papers (not implemented yet)

To be supplemented (Need to look through previous draft papers)

Guess you like

Origin blog.csdn.net/AbaloneVH/article/details/125599538