This code
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\begin{split}
z = \left( a + b + c \right. \\
\left. + \frac{d}{e} \right)
\end{split}
\end{align*}
\end{document}
produces the following output:
The two delimiters have different sizes. A common trick to obtain matching sizes is to use \vphantom
like so:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\begin{split}
z = \left( a + b + c +\vphantom{\frac{d}{e}}\right. \\
\left. + \frac{d}{e} \right)
\end{split}
\end{align*}
\end{document}
which produces the following output:
However, such an approach
- becomes rapidly complex as the number of line breaks increases;
- is not maintainable at all (because, if a line's contents change, the argument of
\vphantom
may have to be modified as well to obtain the desired output).
Alternative approach 1: manually size the delimiters (using \big
and the likes). Sadly, that's not very maintainable either.
Alternative approach 2: using some math environment provided by the breqn
package, which allows for line breaks between two \left
/\right
delimiters and takes care of delimiter sizing. However, I'd like to stay away from breqn
, if possible.
Can you think of a way to make associated \left
/right\
delimiters to automatically have the same size despite line breaks, without (explicitly) using the \vphantom
trick? Ideally, the solution should work for multiple nested pairs of delimiters. For example, in the following, the inner delimiters should have the same size and the outer delimiters should have the same size:
\left( \left( ... \right. \right. \\
\left. \left. ... \right) \right)
Best Answer
The following example uses package
zref
to remember the size of the math formula in labels. Packagemleftright
is used to reduce the additional horizontal spacing by\left
and\right
.Inside a complex math block, the following macros can be used:
The macros can be nested, The
<label>
is needed to identify the pairs of delimiters. Inside the math block (math environment, ...) the<label>
names for the pairs must be unique. After the math block\mzreset
can be called. It frees the<label>
names and they can be reused.Example file: