Draw a Box Around Equation Latex
This folio outlines some more than avant-garde uses of mathematics markup using LaTeX. In item it makes heavy utilize of the AMS-LaTeX packages supplied past the American Mathematical Society.
Equation numbering [edit | edit source]
The equation
environment automatically numbers your equation:
\begin {equation} f(x)=(10+a)(x+b) \stop {equation} |
|
You can also employ the \label
and \ref
(or \eqref
from the amsmath parcel) commands to label and reference equations, respectively. For equation number 1, \ref
results in and \eqref
results in :
\begin {equation} \label {eq:someequation} half-dozen^ii - v = 36-5 = 31 \end {equation} this references equation \ref {eq:someequation}. | |
Farther data is provided in the labels and cross-referencing chapter.
To have the enumeration follow from your department or subsection heading, yous must use the amsmath package or use AMS class documents. Then enter
\numberwithin {equation}{section}
to the preamble to get enumeration at the section level or
\numberwithin {equation}{subsection}
to take the enumeration go to the subsection level.
\documentclass [12pt] {article} \usepackage {amsmath} \numberwithin {equation}{subsection} \begin {document} \department {First Section} \subsection {A subsection} \begin {equation} 50' = {L}{ \sqrt {1-\frac {five^ii}{c^2}}} \end {equation} \finish {document} |
|
If the style you follow requires putting dots subsequently ordinals (as it is required at least in Polish typography), the \numberwithin {equation}{subsection}
command in the preamble will event in the equation number in the above example being rendered equally follows: (one.1.1).
To remove the duplicate dot, add the post-obit control immediately after \numberwithin {equation}{department}
:
\renewcommand { \theequation }{ \thesection\arabic {equation}}
For a numbering scheme using \numberwithin {equation}{subsection}
, use:
\renewcommand { \theequation }{ \thesubsection\arabic {equation}}
in the preamble of the document.
Note: Although it may look like the \renewcommand
works by itself, it won't reset the equation number with each new department. It must be used together with transmission equation number resetting later on each new section beginning, or with the much cleaner \numberwithin
.
Subordinate equation numbering [edit | edit source]
To number subordinate equations in a numbered equation environment, place the part of document containing them in a subequations environment:
\begin {subequations} \label {eq:Maxwell} Maxwell'due south equations: \begin {marshal} B'&=-\nabla \times E, \label {eq:MaxB} \\ Eastward'&=\nabla \times B - iv\pi j, \label {eq:MaxE} \cease {align} \end {subequations} |
|
Referencing subordinate equations tin be done using either of two methods: adding a characterization after the \brainstorm {subequations}
command, viz. \label {eq:Maxwell}
, which volition reference the main equation (1.one in a higher place), or adding a characterization at the end of each line, before the \\
command, which volition reference the sub-equation (1.1a or one.1b above). Every bit shown, it is possible to add both labels in case both types of references are needed.
Vertically aligning displayed mathematics [edit | edit source]
A trouble often encountered with displayed environments (displaymath and equation) is the lack of any ability to bridge multiple lines. While information technology is possible to define lines individually, these will not be aligned.
Above and below [edit | edit source]
The \overset
and \underset
commands[1] typeset symbols above and below expressions. Without AmsTex the same result of \overset
can be obtained with \stackrel
. This can be particularly useful for creating new binary relations:
\[ A \overset { ! }{ = } B; A \stackrel { ! }{ = } B \] |
|
or to show usage of Fifty'Hôpital's rule:
\[ \lim _{10 \to 0 }{ \frac {e^x - ane }{ two 10}} \overset { \left [ \frac { 0 }{ 0 } \right ] }{ \underset { \mathrm {H}}{ = }} \lim _{x \to 0 }{ \frac {e^x}{ 2 }} = { \frac { 1 }{ 2 }} \] |
|
Information technology is convenient to define a new operator that will set the equals sign with H and the provided fraction:
\newcommand { \Heq }[1]{ \overset { \left [#one\correct] }{ \underset { \mathrm {H}}{=}}}
which reduces the above case to:
\[ \lim _{x \to 0 }{ \frac {eastward^ten - 1 }{ 2 x}} \Heq { \frac { 0 }{ 0 }} \lim _{x \to 0 }{ \frac {eastward^x}{ 2 }} = { \frac { 1 }{ 2 }} \]
If the purpose is to make comments on item parts of an equation, the \overbrace
and \underbrace
commands may be more useful. However, they have a dissimilar syntax (and can be aligned with the \vphantom
command):
\[ z = \overbrace { \underbrace {x}_ \text {existent} + i \underbrace {y}_ \text {imaginary} }^ \text {complex number} \] |
|
Sometimes the comments are longer than the formula being commented on, which tin cause spacing problems. These can be removed using the \mathclap
command[ii]:
\[ y = a + f ( \underbrace {b ten}_{ \ge 0 \text { past assumption}} ) = a + f ( \underbrace {b x}_{ \mathclap { \ge 0 \text { past assumption}}} ) \] |
|
Alternatively, to utilize brackets instead of braces use \underbracket
and \overbracket
commands[2]:
\[ z = \overbracket [ 3 pt ] { \underbracket {x}_{ \text {real}} + \underbracket [ 0 . 5 pt ][ 7 pt ] {iy}_{ \text {imaginary}} }^{ \text {complex number}} \] |
|
The optional arguments set the rule thickness and bracket meridian respectively:
\underbracket [dominion thickness][bracket elevation] {argument}_{text below}
The \xleftarrow
and \xrightarrow
commands[1] produce arrows which extend to the length of the text. Yet once more, the syntax is different: the optional argument (using [
and ]
) specifies the subscript, and the mandatory statement (using {
and }
) specifies the superscript (which tin can be left empty by inserting a bare space).
\[ A \xleftarrow { \text {this way}} B \xrightarrow [ \text {or that way} ] { } C \] |
|
For more extensible arrows, you must use the mathtools parcel:
\brainstorm {get together} a \xleftrightarrow [under] {over} b\\ % A \xLeftarrow [under] {over} B\\ % B \xRightarrow [under] {over} C\\ % C \xLeftrightarrow [nether] {over} D\\ % D \xhookleftarrow [under] {over} E\\ % E \xhookrightarrow [under] {over} F\\ % F \xmapsto [nether] {over} G\\ \end {gather} |
|
and for harpoons:
\begin {get together} H \xrightharpoondown [under] {over} I\\ % I \xrightharpoonup [under] {over} J\\ % J \xleftharpoondown [nether] {over} K\\ % K \xleftharpoonup [under] {over} L\\ % Fifty \xrightleftharpoons [nether] {over} M\\ % 1000 \xleftrightharpoons [under] {over} N \stop {gather} |
|
align and align* [edit | edit source]
The align and align* environments, bachelor through the amsmath packet, are used for arranging equations of multiple lines. Equally with matrices and tables, \\
specifies a line break, and &
is used to bespeak the point at which the lines should be aligned.
The marshal* surroundings is used like the displaymath or equation* environment:
\begin {align*} f(x) &= (x+a)(x+b) \\ &= ten^ii + (a+b)x + ab \cease {align*} |
|
Notation that the align environment must not exist nested inside an equation (or similar) environment. Instead, marshal is a replacement for such environments; the contents within an align are automatically placed in math style.
align* suppresses numbering. To force numbering on a specific line, use the \tag {...}
command before the line break.
marshal is similar, simply automatically numbers each line like the equation environs. Individual lines may exist referred to by placing a \characterization {...}
before the line suspension. The \nonumber
or \notag
control tin exist used to suppress the number for a given line:
\begin {marshal} f(x) &= 10^4 + 7x^three + 2x^2 \nonumber \\ & \qquad {} + 10x + 12 \end {align} |
|
Notice that we've added some indenting on the second line. As well, nosotros need to insert the double braces ({}
) before the + sign, otherwise latex won't create the right spacing after the + sign. The reason for this is that without the braces, latex interprets the + sign as a unary operator, instead of the binary operator that information technology actually is.
More than complicated alignments are possible, with additional &
's on a single line specifying multiple "equation columns", each of which is aligned. The following example illustrates the alignment rule of align*:
\begin {align*} f(x) &= a x^2+b x +c & g(10) &= d x^iii \\ f'(x) &= two a x +b & g'(x) &= 3 d x^2 \end {align*} |
|
Braces spanning multiple lines [edit | edit source]
If you desire a brace to continue across a new line, do the following:
\begin {align} f(ten) &= \pi \left\{ x^four + 7x^3 + 2x^2 \correct.\nonumber\\ & \qquad \left. {} + 10x + 12 \right\} \finish {align} |
|
In this structure, the sizes of the left and right braces are not automatically equal, in spite of the apply of \left\{
and \right\}
. This is because each line is typeset as a completely separate equation —notice the use of \right.
and \left.
so in that location are no unpaired \left
and \correct
commands within a line (these aren't needed if the formula is on one line). Y'all can control the size of the braces manually with the \big
, \Large
, \bigg
, and \Bigg
commands.
Alternatively, the height of the taller equation tin be replicated in the other using the \vphantom
command:
\brainstorm {align} A &= \left(\int _t Xxx \right.\nonumber\\ & \qquad \left.\vphantom { \int _t} YYY \dots \correct) \terminate {align} |
|
Using aligned braces for piecewise functions [edit | edit source]
You tin can likewise use \left\{
and \right.
to typeset piecewise functions:
\[ f ( 10 ) = \left\{ \begin {array}{lr} x^ 2 & : x < 0 \\ x^ 3 & : x \ge 0 \end {array} \right . \] |
|
The cases environment [edit | edit source]
The cases environs[1] allows the writing of piecewise functions:
\[ u ( x ) = \brainstorm {cases} \exp {x} & \text {if } 10 \geq 0 \\ 1 & \text {if } x < 0 \stop {cases} \] |
|
LaTeX will and then accept intendance of defining and or adjustment the columns.
Within cases, text way math is used with results such as:
Brandish manner may be used instead, by using the dcases environment[2] from mathtools:
\[ a = \brainstorm {dcases} \int 10 \, \mathrm {d} 10 \\ b^ 2 \end {dcases} \] |
|
Frequently the 2d column consists mostly of normal text. To set it in the normal Roman font of the document, the dcases* environment may be used:[ii]
\[ f ( x ) = \begin {dcases * } x & when $x$ is even \\ - x & when $10$ is odd \end {dcases * } \] |
|
Other environments [edit | edit source]
Although align and marshal* are the most useful, there are several other environments that may besides exist of interest:
Environment name | Clarification | Notes |
---|---|---|
eqnarray and eqnarray* | Similar to align and marshal* | Not recommended because spacing is inconsistent |
multline and multline* [1] | First line left aligned, final line correct aligned | Equation number aligned vertically with outset line and not centered every bit with other environments |
gather and gather* [1] | Consecutive equations without alignment | |
flalign and flalign* [one] | Like to marshal, but left aligns first equation column, and right aligns last cavalcade | |
alignat and alignat* [1] | Takes an statement specifying number of columns. Allows control of the horizontal space between equations | This environment takes one argument, the number of "equation columns": count the maximum number of & s in any row, add 1 and split up by 2. [1] |
There are also a few environments that don't form a math environment past themselves and tin can be used every bit building blocks for more elaborate structures:
Math surroundings name | Description |
---|---|
gathered [1] | Allows gathering equations to be set under each other. |
split [1] | Similar to marshal, but used inside some other displayed mathematics environment and only supports a single equation cavalcade (i.e. a single & symbol). |
aligned [i] | Like to align, to exist used inside another mathematics environs. |
alignedat [1] | Similar to alignat, and likewise takes an boosted argument specifying the number of columns of equations to gear up. Information technology can stack inside alignat. |
For example:
\begin {equation} \left.\begin {aligned} B'&=-\partial \times E,\\ Due east'&=\partial \times B - 4\pi j, \end {aligned} \correct\} \qquad \text {Maxwell's equations} \terminate {equation} |
|
\begin {alignat}{2} \sigma _i &= x + y & \quad \sigma _2 &= \frac {x}{y} \\ \sigma _1' &= \frac { \fractional x + y}{ \fractional x} & \sigma _2' &= \frac { \partial \frac {x}{y}}{ \partial x} \end {alignat} |
|
\begin {gather*} a_0=\frac {1}{ \pi } \int\limits _{-\pi }^{ \pi }f(x)\,\mathrm {d}x\\ [6pt] \brainstorm {dissever} a_north=\frac {ane}{ \pi } \int\limits _{-\pi }^{ \pi }f(x)\cos nx\,\mathrm {d}x=\\ =\frac {one}{ \pi } \int\limits _{-\pi }^{ \pi }x^2\cos nx\,\mathrm {d}10 \end {separate} \\ [6pt] \begin {split} b_n=\frac {1}{ \pi } \int\limits _{-\pi }^{ \pi }f(ten)\sin nx\,\mathrm {d}x=\\ =\frac {one}{ \pi } \int\limits _{-\pi }^{ \pi }10^2\sin nx\,\mathrm {d}x \end {dissever} \\ [6pt] \finish {get together*} |
|
Indented Equations [edit | edit source]
To indent an equation, you can set fleqn in the document grade and then specify a certain value for the \mathindent
variable:
\documentclass [a4paper,fleqn] {study} \usepackage {amsmath} \setlength { \mathindent }{1cm} \begin {document} \noindent Euler's formula is given beneath: \brainstorm {equation*} east^{ix} = \cos {ten} + i \sin {x}. \end {equation*} \noindent This is a very important formula. \cease {document} |
|
Page breaks in math environments [edit | edit source]
To suggest that LaTeX insert a folio break inside an amsmath surroundings, y'all may apply the \displaybreak
command before the line break. Only every bit with \pagebreak
, \displaybreak
can take an optional statement between 0 and 4 denoting the level of desirability of a page suspension. Whereas 0 means "it is permissible to break here", iv forces a break. No argument means the same as 4.
Alternatively, you may enable automated page breaks in math environments with \allowdisplaybreaks
. Information technology also can accept an optional statement cogent the priority of page breaks in equations. Similarly, i ways "allow page breaks but avoid them" and 4 means "break whenever yous want". You tin can prohibit a folio interruption after a given line using \\*
.
LaTeX will insert a page break into a long equation if it has additional text added using \intertext {}
without whatever additional commands.
Specific usage may look similar this:
\brainstorm {align*} & \vdots\\ &=12+7 \int _0^two \left( -\frac {1}{four} \left(e^{-4t_1}+e^{4t_ane-viii} \right) \right)\,dt_i\displaybreak [3] \\ &= 12-\frac {7}{four} \int _0^2 \left( due east^{-4t_ane}+due east^{4t_one-8} \right)\,dt_1\\ & \vdots % \stop {marshal*} |
|
Folio breaks earlier display maths (of all various forms) are controlled by \predisplaypenalty
. Its default 10000 means never pause immediately before a display. Knuth (TeXbook chapter 19) explains this as a printers' tradition non to accept a displayed equation at the start of a page. It can be relaxed with
Sometimes an equation might look best kept together preceding text by a higher penalty, for case, a unmarried-line paragraph about a unmarried-line equation, especially at the stop of a section.
Boxed Equations [edit | edit source]
For a single equation or alignment building block, with the tag outside the box, use \boxed {}
:
\begin {equation} \boxed {ten^2+y^2 = z^2} \terminate {equation} |
|
If you want the entire line or several equations to be boxed, utilise a minipage inside an \fbox {}
:
\fbox { \addtolength { \linewidth }{-ii\fboxsep } % \addtolength { \linewidth }{-2\fboxrule } % \brainstorm {minipage}{ \linewidth } \begin {equation} ten^two+y^2=z^2 \end {equation} \end {minipage} } |
|
There is too the mathtools \Aboxed {}
which is able to box across alignment marks:
\brainstorm {marshal*} \Aboxed { f(x) & = \int h(x)\, dx} \\ & = g(10) \finish {marshal*} |
|
Custom operators [edit | edit source]
Although many common operators are available in LaTeX, sometimes you will need to write your own, due east.1000. to typeset the argmax operator. The \operatorname
and \operatorname*
commands[1] brandish custom operators; the *
version sets the underscored option underneath like the \lim
operator:
\[ \operatorname {arg \, max}_a f ( a ) = \operatorname * {arg \, max}_b f ( b ) \] |
|
However, if the operator is ofttimes used, it is preferable to ascertain a new operator that can be used throughout the unabridged certificate. The \DeclareMathOperator
and \DeclareMathOperator*
commands[1] are specified in the header of the document:
\DeclareMathOperator* { \argmax }{arg\,max}
This defines a new command which may exist referred to in the body:
|
Advanced formatting [edit | edit source]
Limits [edit | edit source]
In that location are defaults for placement of subscripts and superscripts. For case, limits for the lim operator are usually placed below the symbol:
\brainstorm {equation} \lim _{a\to \infty } \tfrac {1}{a} \end {equation} |
|
To override this beliefs, employ the \nolimits
operator:
\brainstorm {equation} \lim\nolimits _{a\to \infty } \tfrac {1}{a} \terminate {equation} |
|
A lim in running text (inside $ ... $
) will have its limits placed on the side, so that additional leading won't be required. To override this behavior, use the \limits
command.
Similarly ane can put subscripts under a symbol that usually has them on the side:
\begin {equation} \int _a^b x^two \mathrm {d} x \end {equation} |
|
Limits below and nether:
\begin {equation} \int\limits _a^b x^ii \mathrm {d} ten \cease {equation} |
|
To change the default placement of summation-blazon symbols to the side for every case, add the nosumlimits selection to the amsmath package. To alter the placement for integral symbols, add intlimits to the options. nonamelimits can be used to change the default for named operators similar det, min, lim, etc.
To produce one-sided limits, use \underset
as follows:
\brainstorm {equation} \lim _{a \underset {>}{ \to } 0} \frac {1}{a} \terminate {equation} |
|
Subscripts and superscripts [edit | edit source]
You can place symbols in subscript or superscript (in summation style symbols) with \nolimits
:
\brainstorm {equation} \sum\nolimits' C_n \terminate {equation} |
|
It's impossible to mix them with typical usage of such symbols:
\begin {equation} \sum _{n=1} \nolimits' C_n \end {equation} |
|
To add together both a prime and a limit to a symbol, 1 might use the \sideset
command:
\begin {equation} \sideset {}{'} \sum _{n=i}C_n \terminate {equation} |
|
It is very flexible: for example, to put letters in each corner of the symbol utilise this control:
\begin {equation} \sideset {_a^b}{_c^d} \sum \stop {equation} |
|
If you lot wish to place them on the corners of an capricious symbol, you lot should utilise \fourIdx
from the fouridx bundle.
But a simple grouping can likewise solve the problem:
\brainstorm {equation} { \sum\limits _{northward=1} }'C_due north \end {equation} |
|
since a math operator tin can be used with limits or no limits. If you want to change its land, simply group it. You can make it another math operator if you want, then you tin can have limits and then limits again.
Multiline subscripts [edit | edit source]
To produce multiline subscript, utilise the \substack
command:
\begin {equation} \prod _{ \substack { ane\le i \le northward\\ 1\le j \le m}} M_{i,j} \end {equation} |
|
Text in aligned math brandish [edit | edit source]
To add together pocket-sized interjections in math environments, use the \intertext
command:
\begin {minipage}{3in} \begin {align*} \intertext {If} A &= \sigma _1+\sigma _ii\\ B &= \rho _i+\rho _2\\ \intertext {then} C(ten) &= e^{Ax^2+\pi }+B \cease {marshal*} \cease {minipage} |
|
Note that whatsoever usage of this command does not change the alignment.
Also, in the higher up example, the command \shortintertext {}
from the mathtools package could accept been used instead of \intertext
to reduce the amount of vertical white space added between the lines.
Irresolute font size [edit | edit source]
There may exist a time when y'all would adopt to have some control over the font size. For case, using text-style maths, by default a simple fraction will look like this: , whereas you may prefer to take it displayed larger, like when in display way, merely still keeping information technology in-line, like this: .
A simple approach is to utilize the predefined sizes for maths elements:
Size control | Clarification |
---|---|
\displaystyle | Size for equations in display mode |
\textstyle | Size for equations in text style |
\scriptstyle | Size for first sub/superscripts |
\scriptscriptstyle | Size for subsequent sub/superscripts |
A classic example to come across this in apply is typesetting continued fractions (though it'southward better to utilise the \cfrac
command[1] described in the Mathematics chapter instead of the method provided below). The following code provides an example.
\begin {equation} 10 = a_0 + \frac {ane}{a_i + \frac {1}{a_ii + \frac {1}{a_3 + a_iv}}} \cease {equation} |
|
As you tin run into, as the fractions continue, they get smaller (although they will not get whatsoever smaller than in this example, where they have reached the \scriptstyle
limit). If y'all want to keep the size consistent, y'all could declare each fraction to use the display style instead; e.g.
\begin {equation} ten = a_0 + \frac {ane}{ \displaystyle a_1 + \frac {1}{ \displaystyle a_2 + \frac {ane}{ \displaystyle a_three + a_4}}} \finish {equation} |
|
Some other approach is to use the \DeclareMathSizes
command to select your preferred sizes. Yous tin can only define sizes for \displaystyle
, \textstyle
, etc. I potential downside is that this command sets the global maths sizes, as it tin only be used in the document preamble.
But it's fairly easy to employ: \DeclareMathSizes {ds}{ts}{ss}{sss}
, where ds is the display size, ts is the text size, etc. The values you input are assumed to exist point (pt) size.
Note that the changes but accept place if the value in the first argument matches the current document text size. It is therefore common to see a set of declarations in the preamble, in the result of the principal font existence changed. Eastward.one thousand.,
\DeclareMathSizes {10}{18}{12}{8} % For size 10 text \DeclareMathSizes {11}{19}{13}{ix} % For size 11 text \DeclareMathSizes {12}{twenty}{fourteen}{x} % For size 12 text
Forcing \displaystyle for all math in a document [edit | edit source]
Put
\everymath { \displaystyle }
before
to strength all math to
.
Adjusting vertical white infinite around displayed math [edit | edit source]
At that place are 4 parameters that control the vertical white space around displayed math:
\abovedisplayskip=12pt \belowdisplayskip=12pt \abovedisplayshortskip=0pt \belowdisplayshortskip=7pt
Short skips are used if the preceding line ends, horizontally, earlier the formula. These parameters must be gear up afterwards
.
Notes [edit | edit source]
- ↑ a b c d e f g h i j k l grand n Requires amsmath packet
- ↑ a b c d requires the mathtools package
Source: https://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics