[Tex/LaTex] How to split an equation over two (or more) lines

breqnequationsline-breakingmath-mode

I am having the following equation:

\begin{equation}
  Q(\lambda,\hat{\lambda}) = -\frac{1}{2} P(O \mid \lambda ) \sum_s \sum_m \sum_t \gamma_m^{(s)} (t) \left( n \log(2 \pi ) + \log \left| C_m^{(s)} \right| + \left( \mathbf{o}_t - \hat{\mu}_m^{(s)} \right) ^T C_m^{(s)-1} \left(\mathbf{o}_t - \hat{\mu}_m^{(s)}\right) \right)
\end{equation}

which does not very well fit on one line. How can I split this over two lines? What I have in mind is that I specify the splitting place, and that the first line is left aligned and the second line right aligned to make clear that it is still the same equation.

The linebreak \\ does not work.

Best Answer

Use either breqn to break lines automatically or use amsmath and its many environments exactly for this purpose. For example, with breqn:

\documentclass{article}
\usepackage{breqn}
\begin{document}
\begin{dmath}
  Q(\lambda,\hat{\lambda}) = -\frac{1}{2} P{(O \mid \lambda )} \sum_s \sum_m \sum_t \gamma_m^{(s)} (t) \left( n \log(2 \pi ) + \log \left| C_m^{(s)} \right| + \left( \mathbf{o}_t - \hat{\mu}_m^{(s)} \right) ^T C_m^{(s)-1} \left(\mathbf{o}_t - \hat{\mu}_m^{(s)}\right) \right)
\end{dmath}
\end{document}

Note, the expression around \mid required braces to prevent it from breaking at this point; I'm sure there is a better way to do that; anyway, here's the output:

rendered

With amsmath, you need to specify the break points manually: (as others have also mentioned)

\usepackage{amsmath}
...
\begin{multline}
  A+B+C+ \\ +D+E+F 
\end{multline}

The users guide to amsmath is called amsldoc.pdf, but you can access it by typing texdoc amsmath on the command line. The main environments you'll use there would be align, split, and multline.

Related Question