\left and \right in equation across multiple lines
Once we
- replace the
align
environment toaligned
(since it is within theequation
environment and you want a single equation number). - add a closing
\right.
before the end of the first line, and - add an opening
\left(
on the second line after the alignment point
we get:
The \left
and \right
constructs can not cross line, or alignment points. If there is a need to open a \left
on one line and close it on a subsequent line, then the first line needs to have a \right.
before the end of the line, and the next line needs to have a \left.
before the closing \right
construct.
Hence the \left
, \right
are balanced on each line. Similar logic applies to each side of an alignment point.
Code:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
\label{eq:foo}
s_{i}^{G}= & \min
\left(
\sqrt
{ \min
(
(
x_{i}^{G}-x
)
^2,
(
w_{T} - x_{i}^{G}-x
)
^2
)
+
y
}
\right.
,\\
&
\left.
\sqrt
{ \min
(
(
x_{i}^{G}-x
)
^2,
(
w_{T} - x_{i}^{G}-x
)
^2
)
+
\min
(
(
y_{i}^{G}-y
)
^2,
(
h_{T} - y_{i}^{G}-y
)
^2
)
}
\right)
\end{aligned}
\end{equation}
\end{document}
I think this is an example of why the \left...\right
construct is more problematic than useful in some situations. I propose to use the \bigX
, \BigX
, \biggX
, \BiggX
family of commands instead; they do not need to be paired and one doesn't have to make manual adjustments when a line change occurs and the lines don't have the same height.
Below, two variations of the expression using this family of commands (the size of the inner parentheses was also corrected); the second one using additionally \smash
:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
\label{eq:foo}
s_{i}^{G}= & \min
\biggl(
\sqrt
{
\min
\bigl(
(
x_{i}^{G}-x
)
^2,
(
w_{T} - x_{i}^{G}-x
)
^2
\bigr)
+
y
}
,\\
&\quad
\sqrt
{
\min
\bigl(
(
x_{i}^{G}-x
)
^2,
(
w_{T} - x_{i}^{G}-x
)
^2
\bigr)
+
\min
\bigl(
(
y_{i}^{G}-y
)
^2,
(
h_{T} - y_{i}^{G}-y
)
^2
\bigr)
}
\biggr)
\end{aligned}
\end{equation}
\begin{equation}
\begin{aligned}
\label{eq:foo}
s_{i}^{G}= & \min
\Bigl(
\sqrt
{\smash[b]{
\min
\bigl(
(
x_{i}^{G}-x
)
^2,
(
w_{T} - x_{i}^{G}-x
)
^2
\bigr)
+
y
}}
,\\
&\quad
\sqrt
{\smash[b]{
\min
\bigl(
(
x_{i}^{G}-x
)
^2,
(
w_{T} - x_{i}^{G}-x
)
^2
\bigr)
+
\min
\bigl(
(
y_{i}^{G}-y
)
^2,
(
h_{T} - y_{i}^{G}-y
)
^2
\bigr)
}}\,
\Bigr)
\end{aligned}
\end{equation}
\end{document}
As Guido mentions in his comment, a solution for the problem of the displacement of the equation number is to replace the combination of equation
and aligned
with multline
:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{multline}
\label{eq:foo}
s_{i}^{G}= \min
\biggl(
\sqrt
{
\min
\bigl(
(
x_{i}^{G}-x
)
^2,
(
w_{T} - x_{i}^{G}-x
)
^2
\bigr)
+
y
}
,\\
\sqrt
{
\min
\bigl(
(
x_{i}^{G}-x
)
^2,
(
w_{T} - x_{i}^{G}-x
)
^2
\bigr)
+
\min
\bigl(
(
y_{i}^{G}-y
)
^2,
(
h_{T} - y_{i}^{G}-y
)
^2
\bigr)
}
\biggr)
\end{multline}
\begin{multline}
s_{i}^{G}= \min
\Bigl(
\sqrt
{\smash[b]{
\min
\bigl(
(
x_{i}^{G}-x
)
^2,
(
w_{T} - x_{i}^{G}-x
)
^2
\bigr)
+
y
}}
,\\
\sqrt
{\smash[b]{
\min
\bigl(
(
x_{i}^{G}-x
)
^2,
(
w_{T} - x_{i}^{G}-x
)
^2
\bigr)
+
\min
\bigl(
(
y_{i}^{G}-y
)
^2,
(
h_{T} - y_{i}^{G}-y
)
^2
\bigr)
}}\,
\Bigr)
\end{multline}
\end{document}
As already mentioned, \left(
and \right.
are pairs, not \left(
and \right)
.
There is a package called breqn
that provides the possibility to use \left
and \right
across linebreaks:
Code
\documentclass{article}
\usepackage{amsmath}
\usepackage{breqn}
\begin{document}
\begin{align}
s_{i}^{G}= & \min
\left(\sqrt{\min((x_{i}^{G}-x)^2,(w_{T} - x_{i}^{G}-x)^2)+y}\right., \notag\\
& \left.\sqrt{\min((x_{i}^{G}-x)^2,(w_{T} - x_{i}^{G}-x)^2)+\min((y_{i}^{G}-y)^2, (h_{T} - y_{i}^{G}-y)^2)}\right)
\end{align}
\begin{dmath}
s_{i}^{G}= \min \left(\sqrt{\min((x_{i}^{G}-x)^2,(w_{T} - x_{i}^{G}-x)^2)+y},\\
\mathrel{\phantom{=}} \sqrt{\min((x_{i}^{G}-x)^2,(w_{T} - x_{i}^{G}-x)^2)+\min((y_{i}^{G}-y)^2, (h_{T} - y_{i}^{G}-y)^2)}\right)
\end{dmath}
\end{document}
The macro \notag
hides the equation tag in the first line since both lines correspond to one and only one equation (or you use the aligned
environment).
Output
Drawbacks
Closing \left(
with \right.
works fine as long as both parts of the equation are of equal heights. For an equation like (this is only a example, neither the equation itself nor the horizontal space in front of the second part should be a point of discussion):
\begin{align}
x & = \left( \frac{1}{2} \right. \notag \\
& \quad \left. {} + 1\right)
\end{align}
The output does not look good:
Again, you can use breqn
or, and this needs the author's attention, \vphantom
:
\begin{align}
x & = \left( \frac{1}{2} \right. \notag \\
& \quad \left. {\vphantom{\frac{1}{2}}} + 1\right)
\end{align}
\begin{dmath}
x = \left( \frac{1}{2} \\
\mathrel{\phantom{=}} {} + 1\right)
\end{dmath}
Output: