I have a problem writing an equation in eqnarray environment, where I split a single line into two lines. The first line starting with \left[ and the second line ending with \right], but I could not compile it using latex.
- 223,288
4 Answers
You should use align instead ofeqnarray as per this question that compares eqnarray vs align, and Stefan Kottwitz blong entry: \eqnarray vs \align environment.
Here is an example of using the \right., and \left. pair to complete the matching pair using the align environment. Note that the size of the brackets is not the same in the first example. This is due to the fact that the \left. <math> \right] of the second line does not see the vertical spacing of the \left[ <math> \right. that the first line does. To fix that you need to add a \vphantom{} with the term which has the largest vertical spacing in the first line. This yields the second result:

\documentclass{standalone}
\usepackage{amsmath}
\begin{document}
\begin{align*}
y &= \left[\frac{1}{2}\right. \\
&\qquad + \left.x^2+c\right]
\end{align*}
%
\begin{align*}
y &= \left[\frac{1}{2}\right. \\
&\qquad + \left.x^2+c\vphantom{\frac{1}{2}}\right]
\end{align*}
\end{document}
- 11,466
- 223,288
-
There's a little typo in the second line before the image: you wrote
\vpahantom{}. – Gonzalo Medina Nov 28 '11 at 00:45 -
the style recommended in most "how to typeset math" manuals is to indent the lines starting with + by a couple of quads. in the texbook, ch.19, dek uses \qquad in several such examples. – barbara beeton Nov 28 '11 at 15:00
-
-
@barbarabeeton: Thanks for pointing that out. Have added a
\qquad. – Peter Grill Nov 28 '11 at 16:23
Another option would be to use the big-g delimiters instead of the \left, \right construct; using the big-g delimiters you don't have to worry for pairing the symbols in every line:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
y &= \biggl[ \frac{1}{2} \\
&+ x^2 + c \biggr]
\end{align*}
\end{document}

- 11,466
- 505,128
you can use the breqn package.
instead of \begin{equation} or \begin{equation*}, use the environment dmath or dmath*. the delimiters will be sized properly, and the line broken in an appropriate location. there are also multi-line environments if your display needs them.
there are some limitations; for details, see the package documentation -- texdoc breqn if you have a tex live installation; otherwise, look on ctan.
- 88,848
-
@barbaraL Out of curiosity, from the AMS submissions, do you know how frequently is
breqnused in the wild. – Aditya Nov 27 '11 at 20:53 -
1@Aditya -- i've grepped for the package name in some of the files in current production, and didn't find it. my guess is that it's not that well "advertised", and if an author isn't already using it when a book or paper goes into production here, the copyeditors are so used to the "old" methods of breaking lines that they just don't try it. (it was still very much a beta when michael downes died, so it didn't get the exposure here that would have put it into the local toolbox.) – barbara beeton Nov 28 '11 at 14:52
-
Thank you for the info. Hopefully the usage of breqn will slowly pick up. – Aditya Nov 29 '11 at 13:09
Another option is to use nath class. It is not completely compatible with amsmath, but does provide its own multi-line math environments, which might be sufficient for simple math displays.
One of the features of nath is automatic delimiter scaling that works across multiple lines. For example
\documentclass{article}
\usepackage{nath}
\begin{document}
\begin{equation}
y = \wall [ \sum_{i=1}^n a_i \\
+ x^2 + c ] \return
\end{equation}
\end{document}
gives

- 757,742
- 62,301
-
2
-
@egreg: The display math (
alignetc) and matrix commands (bmatrixetc), and extensible arrow fromamsmathare incompatible withnath. Text mode commands (\text,\dots,\cfrac,\binom) work. It would have been much nicer if both packages had split their display math macros and other macros into separate packages which could be intermixed. – Aditya Nov 27 '11 at 20:50 -
it's not completely true that
amsmathis monolithic. there are several ancillary packages (which admittedly are automatically loaded byamsmath):amsopn(operator names),amstext(the\textfacility) andamsbsy(bold symbols). (there's alsoamscd, but other packages serve that function better.) any of these can be used withoutamsmath; whether or not they're compatible withnath, i don't know. an overhaul ofamsmathis tentatively scheduled for next year;nathis one of the non-ams packages on our list to look at, but i can't promise compatibilty after the overhaul. – barbara beeton Nov 29 '11 at 17:44 -
Thanks @barbara. My guess is that compatibility with
nathis difficult becausenathchanges a lot of TeX internals, likebreqn. In some sense, likebreqn,nathshould be the one ensuring compatibility withamsmath; not the other way round. Ifamsmathcould include some of thenathfeatures ("correct" scaling of\left...\rightaround operators with limits; an "intelligent"\fracmacro (perhaps with a different name), automatic\substackif the subscript or superscript has multiple lines) that will be great. – Aditya Nov 29 '11 at 18:03
It is always best to compose a fully compilable MWE that illustrates the problem including the
– Peter Grill Nov 27 '11 at 19:13\documentclassand the appropriate packages so that those trying to help don't have to recreate it.\right., and adding a\left.on the second line. If there are differences in vertical spacing between the lines, you'll need to use\vphantom. If you provide a small MWE we can adjust it for you. – Peter Grill Nov 27 '11 at 19:15eqnarray. See, e.g., http://tex.stackexchange.com/q/197/586 – Torbjørn T. Nov 27 '11 at 19:24eqnarrayenvironment (and hence why one shouldn't use it!), see Lars Madsen's essay "Avoid eqnarray!", published in the PracTeX Journal in 2006, available at http://tug.org/pracjourn/2006-4/madsen. – Mico Nov 27 '11 at 22:56