• 검색 결과가 없습니다.

Multiline Equations

문서에서 The Not So Short Introduction to LATEX (페이지 108-116)

The math environments discussed so far only allow typesetting a single line equation. However, sometimes an equation might be too long to fit.

\begin{equation}

a = b + c + d + e + f + g + h + i + j

+ k + l + m + n + o + p

\end{equation}

𝑎 = 𝑏+𝑐+𝑑+𝑒+𝑓+𝑔+ℎ+𝑖+𝑗+𝑘+𝑙+𝑚+𝑛+𝑜+𝑝 (1)

3.4 Multiline Equations 91

In this case, it is necessary to introduce line breaks inside the equation.

When doing so, it is important to remember a few rules to improve the readability:

1. In general one should always break an equation before an equality sign or operator.

2. A break before an equality sign is preferable to a break before any operator.

3. A break before a plus- or minus-operator is preferable to a break before a multiplication-operator.

4. Any other type of break should be avoided if at all possible.

This section will introduce several environments to typeset equations with linebreaks inside them. These and more are described in more detail in the amsmath [55] package documentation.

3.4.1 Long Equations

The easiest way to display long equations is the multline environment.

It allows introducing line breaks with the \\command.

\begin{multline}

a + b + c + d + e + f + g + h + i \\

= j + k + l + m + n

\end{multline}

𝑎 + 𝑏 + 𝑐 + 𝑑 + 𝑒 + 𝑓 + 𝑔 + ℎ + 𝑖

= 𝑗 + 𝑘 + 𝑙 + 𝑚 + 𝑛 (1)

The first line in multline environment is aligned to the left, and the last one to the right, while all the others are centred.

\begin{multline}

a + b + c + d + e \\

+ f + g + h + i \\

= j + k + l + m + n

\end{multline}

𝑎 + 𝑏 + 𝑐 + 𝑑 + 𝑒 + 𝑓 + 𝑔 + ℎ + 𝑖

= 𝑗 + 𝑘 + 𝑙 + 𝑚 + 𝑛 (1)

If you do not want some particular inner line centred, you can use

\shoveleftand\shoveright commands to force the line to be left or

right aligned.

\begin{multline}

a + b + c \\

\shoveleft{+ d + e + f} \\

\shoveright{+ g + h + i} \\

= j + k + l + m + n

\end{multline}

𝑎 + 𝑏 + 𝑐 + 𝑑 + 𝑒 + 𝑓

+ 𝑔 + ℎ + 𝑖

= 𝑗 + 𝑘 + 𝑙 + 𝑚 + 𝑛 (1)

As with equation*, there also exists a starred multline* version that suppresses the equation number.

3.4.2 Multiple Unaligned Equations

When typsetting multiple equations within several equation environ-ments, unneeded spacing appears between them.

\begin{equation}

2 + 2 = 4

\end{equation}

\begin{equation}

2 \times 2 = 4

\end{equation}

\begin{equation}

2 + 2 \times 2 = 6

\end{equation}

2 + 2 = 4 (1)

2 × 2 = 4 (2)

2 + 2 × 2 = 6 (3)

Use the gather environment to eliminate the extra space. It allows you to break lines using the\\ command, and centres each equation.

\begin{gather}

2 + 2 = 4 \\

2 \times 2 = 4 \\

2 + 2 \times 2 = 6

\end{gather}

2 + 2 = 4 (1)

2 × 2 = 4 (2)

2 + 2 × 2 = 6 (3)

The equation numbering commands, such as \eqref,\labeland \tag, now apply to the line they are present in. Additionally the command

3.4 Multiline Equations 93

\notagallows you to suppress equation numbering for a particular line.

\begin{gather}

2 + 2 = 4

\tag{Easy}\label{easy} \\

2 \times 2 = 4 \notag \\

2 + 2 \times 2 = 6

\label{hard}

\end{gather}

Note:~\eqref{easy} is easier than~\eqref{hard}.

2 + 2 = 4 (Easy) 2 × 2 = 4

2 + 2 × 2 = 6 (1) Note: (Easy) is easier than (1).

The above example also illustrates that the centring of the equations inside the environment may depend upon the length of the tag. Keep this in mind if your tags and/or equations get long.

As always, the starred version of the environment, gather*, sup-presses all equation numbers.

3.4.3 Multiple Aligned Equations

If the gathered equations have a natural midpoint, it may be the case that the align environment is much better suited to typeset them. It allows you to align the equations by inserting the & character, the same as in the tabular environment. Note that the & should come before any binary operator, in order to produce the correct spacing.

\begin{align}

2 + 2 & = 2 \times 2 \\

3 + 3 & \neq 3 \times 3 \\

2 + 2 \times 2 & < 8

\end{align}

2 + 2 = 2 × 2 (1) 3 + 3 ≠ 3 × 3 (2) 2 + 2 × 2 < 8 (3)

The align environment allows placing multiple bits of math on a single line by using & as a separator. The bits are considered to be paired, so every second alignment character will produce a bigger space to accommodate for the spacing between columns.

\begin{align}

a & \succeq b & c & \leq d \\

a & \geq d & d & \prec c

\end{align}

𝑎 ⪰ 𝑏 𝑐 ≤ 𝑑 (1)

𝑎 ≥ 𝑑 𝑑 ≺ 𝑐 (2)

The align environment is also really useful when writing transfor-mations of a single equation over multiple lines.

\begin{align}

\sum_{k=0}^n k

&= \sum_{k=0}^{n-1} k + n \\

&= \frac{n(n-1)}{2} + n \\

&= \frac{n(n+1)}{2}

\end{align}

𝑛

𝑘=0

𝑘 =

𝑛−1

𝑘=0

𝑘 + 𝑛 (1)

= 𝑛(𝑛 − 1)

2 + 𝑛 (2)

= 𝑛(𝑛 + 1)

2 (3)

We can even use additional columns to add line-by-line comments with the\textcommand.

\begin{align*}

\sum_{k=0}^n k

&= \sum_{k=0}^{n-1} k + n

&& \text{definition} \\

&= \frac{n(n - 1)}{2} + n

&& \text{induction} \\

&= \frac{n(n + 1)}{2}

&& \text{trivial}

\end{align*}

𝑛

𝑘=0

𝑘 =

𝑛−1

𝑘=0

𝑘 + 𝑛 definition

= 𝑛(𝑛 − 1)

2 + 𝑛 induction

= 𝑛(𝑛 + 1)

2 trivial

The\phantomcommand from subsection 3.7.3 allows us to correctly align equation systems.

\begin{align}

a + b + c

&= d + e + f \nonumber \\

& \phantom{=}\ + g + h

\nonumber \\

& \phantom{=}\ + i \\

&= j + k + l

\end{align}

𝑎 + 𝑏 + 𝑐 = 𝑑 + 𝑒 + 𝑓 + 𝑔 + ℎ

+ 𝑖 (1)

= 𝑗 + 𝑘 + 𝑙 (2)

LATEX encloses relation symbols in thick spaces\; and binary symbols in medium spaces\:. The symbols = and + in our example are each of this type. The \phantom command strips = of its relation status, leaving it short of two thick spaces. On the other hand, LATEX interprets + following\phantomas a binary symbol, creating a spurious medium

space. So we need an extra normal space: \ = \; + \; - \:.

If this aproach seems a bit complicated to you, have a look at subsec-tion 3.4.5.

3.4 Multiline Equations 95

3.4.4 Equations as Building Blocks

All the environments presented above can be used inside other equations by appending “-ed” to their name. They no longer number the equations inside them, and accept an optional vertical positioning argument, with the same semantics as those accepted by tabular (see Section 2.18 on page 53).

\[\begin{multlined}[t]

1 + 2 \\

+ 3 + 4

\end{multlined} =

\begin{gathered}[c]

1 + 2 \\

+ 3 + 4

\end{gathered} =

\begin{aligned}[b]

1 & + 2 \\

& + 3 + 4

\end{aligned}

\]

1 + 2 + 3 + 4

= 1 + 2 +3 + 4=

1 + 2 + 3 + 4

These are useful if you want to, for example, break an equation into multiple lines with alignment, but still retain only a single equation number.

\begin{equation}

\begin{aligned}

2 + 2 \times 2

&= 2 \times 2 + 2 \\

&\neq 2 \times (2 + 2) \\

\end{aligned}

\end{equation}

2 + 2 × 2 = 2 × 2 + 2

≠ 2 × (2 + 2) (1)

They can be also freely nested, if the need arises.

\begin{align}

a + b + c

&= \begin{multlined}[t]

d + e \\

+ e + f \\

\end{multlined} \\+ h

&= \begin{aligned}[t]

i &+ j \\

&- k \\

&\div m \\

&\times n

\end{aligned} \\

&= o + p + q

\end{align}

𝑎 + 𝑏 + 𝑐 = 𝑑 + 𝑒 + 𝑒 + 𝑓

+ ℎ

(1)

= 𝑖 + 𝑗

− 𝑘

÷ 𝑚

× 𝑛

(2)

= 𝑜 + 𝑝 + 𝑞 (3)

3.4.5 IEEEeqnarray Environment

If the environments defined in amsmath do not meet your needs, you can try the IEEEeqnarray from the IEEEtrantools [69] package. It allows you to specify the alignment of each math column separately, like in the tabular environment. Here we will present some of its basic functionali-ties. More information about IEEEeqnarray can be found in Appendix F of [68].

To specify column alignments, use l, c and r. Their uppercase version also adds a small space around the column, which is useful in case of binary operators. For example, to emulate the align environment we could use rCl, i.e., three columns: the first column right-justified, the middle one centred with a little more space around it, and the third column left-justified.

\begin{IEEEeqnarray}{rCl}

a & = & b + c \\

& = & d + e + f + g + h \\

& = & i + j + k

\end{IEEEeqnarray}

𝑎 = 𝑏 + 𝑐 (1)

= 𝑑 + 𝑒 + 𝑓 + 𝑔 + ℎ (2)

= 𝑖 + 𝑗 + 𝑘 (3)

In contrast to the amsmath environments, IEEEeqnarray does not try to avoid collisions between the equation and its number.

\begin{IEEEeqnarray}{rCl}

a & = & b + c \\

& = & d + e + f + g + h + i + j \\

& = & k + l + m + n.

\end{IEEEeqnarray}

𝑎 = 𝑏 + 𝑐 (1)

= 𝑑 + 𝑒 + 𝑓 + 𝑔 + ℎ + 𝑖 + 𝑗(2)

= 𝑘 + 𝑙 + 𝑚 + 𝑛. (3)

3.4 Multiline Equations 97

To avoid this, use the \IEEEeqnarraynumspace on the offending line. It will shift the whole equation left to accommodate the number present on the given line.

\begin{IEEEeqnarray}{rCl}

a & = & b + c \\

& = & d + e + f + g + h + i + j

\IEEEeqnarraynumspace \\

& = & k + l + m + n.

\end{IEEEeqnarray}

𝑎 = 𝑏 + 𝑐 (1)

= 𝑑 + 𝑒 + 𝑓 + 𝑔 + ℎ + 𝑖 + 𝑗(2)

= 𝑘 + 𝑙 + 𝑚 + 𝑛. (3)

You can also use \IEEEeqnarraymulticol to adjust only a single line within the environment, with its usage being similar to that of the

\multicol environment.

\begin{IEEEeqnarray}{rCl}

\IEEEeqnarraymulticol{3}{l}{

a + b + c + d = e + f } \\e + f & = & g + h \\

& = & i + j + k + l + m

\end{IEEEeqnarray}

𝑎 + 𝑏 + 𝑐 + 𝑑 = 𝑒 + 𝑓 (1)

𝑒 + 𝑓 = 𝑔 + ℎ (2)

= 𝑖 + 𝑗 + 𝑘 + 𝑙 + 𝑚 (3)

If a particular line should not have an equation number, the number can be suppressed using \notag, as discussed before. Additionally, IEEEtrantools defines \IEEEyesnumber and \IEEEyessubnumber. The former command can be used to turn on numbering within the starred version of an environment.

\begin{IEEEeqnarray*}{rCl}

a & = & b + c \\

& = & d + e \IEEEyesnumber\\

& = & f + g

\end{IEEEeqnarray*}

𝑎 = 𝑏 + 𝑐

= 𝑑 + 𝑒 (1)

= 𝑓 + 𝑔 The latter changes the numbering to indicate sub expressions.

\begin{IEEEeqnarray}{rCl}

a & = & b + c \\

& = & d + e \notag \\

& = & f + g

\IEEEyessubnumber

\end{IEEEeqnarray}

𝑎 = 𝑏 + 𝑐 (1)

= 𝑑 + 𝑒

= 𝑓 + 𝑔 (1a) Note that\labelcommands should eventually follow after these.

Here is an alternative approach to the \phantom example above.

Notice the extra\negmedspace required to properly separate the plus sign from the variable name. The \negmedspace{} command adds a medium negative space, which cancels the space that LATEX inserts between variable and operator in a formula like 𝑎 + 𝑏, while playing the role of a variable when LATEX decides whether the next symbol is a relation symbol or a unary operator.

\begin{IEEEeqnarray*}{rCl}

a & = & b + c + d \\

& & + e \quad \text{too narrow!}\\

& & \negmedspace{} + e \\

& = & f + 2e

\end{IEEEeqnarray*}

𝑎 = 𝑏 + 𝑐 + 𝑑

+𝑒 too narrow!

+ 𝑒

= 𝑓 + 2𝑒

문서에서 The Not So Short Introduction to LATEX (페이지 108-116)