1

I am using align for multiline equations and works fine but I am encountering a limitation. I have terms between parenthesis opened and closed with \left( \right). Since there are many terms between them I need to split \right) to the next column of \left(. However in this way it does not compile.

Here my example. This compiles

\begin{align*}

&= \sigma^2 \left(\cancel{\left(X^TX\right)^{-1}}\cancel{X^T X}   \left(X^TX\right)^{-1} + \left(X^T X\right)^{-1}X^TD^T \right)+\\
&\quad + D X \left(X^TX\right)^{-1} +DD^T =\\
\end{align*}

and this does not:

\documentclass{article}
\usepackage{amsmath, cancel}
\begin{document}
\begin{align*}
    &= \sigma^2 \left(\cancel{\left(X^TX\right)^{-1}}\cancel{X^T X}   \left(X^TX\right)^{-1} + \left(X^T X\right)^{-1}X^TD^T +\\
    &\quad + D X \left(X^TX\right)^{-1} +DD^T \right)=\\
    \end{align*}
\end{document}
M. Al Jumaily
  • 4,035
  • 2
  • 11
  • 26
  • 2
    \left command has to be completed by a \right command in the same line of the equation. So, try \right. in the end of the first line and \left. in the beginning of the second line. (dot version will print nothing but will help the commands to be complete) – koleygr Aug 23 '19 at 19:30

3 Answers3

3

It is possible to use also the environment multlined with a different aspect.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools,amssymb,cancel}
\begin{document}
\[
\begin{multlined}
= \sigma^2 \Bigl(\cancel{\left(X^TX\right)^{-1}}\cancel{X^T X}\left(X^TX\right)^{-1} +  \left(X^T X\right)^{-1}X^TD^T\\ 
+ D X \left(X^TX\right)^{-1} +DD^T\Bigr)=
\end{multlined}
\]
\end{document}

Addendum

With @GuM's comment you will have:

    \documentclass[a4paper,12pt]{article}
    \usepackage{mathtools,amssymb,cancel}
    \begin{document}

    \begin{multline*}
    = \sigma^2 \Bigl(\cancel{\left(X^TX\right)^{-1}}\cancel{X^T X}\left(X^TX\right)^{-1} +  \left(X^T X\right)^{-1}X^TD^T\\ 
    + D X \left(X^TX\right)^{-1} +DD^T\Bigr)=
    \end{multline*}

    \end{document}

enter image description here

GuM
  • 21,558
Sebastiano
  • 54,118
  • 1
    Instead ofing say \[ \begin{multlined} ... \end{multlined} \], just say \begin{multline*} ... \end{multline*}. – GuM Aug 23 '19 at 20:57
  • Although your code works with \Bigl( \Bigr), it does not with for example \left( \right) or \left[ \right] – Francesco Boi May 06 '20 at 11:32
  • Of course it can' t work. The multline environment is similar to splitting the equation and so you use \Bigl( or \Bigr) to compile correctly. There are many answers that justify this concept. If you need help, I'm available. I remember you that \left(... \right) also cause problems with the correct size of the brackets. – Sebastiano May 06 '20 at 19:18
1

So what you can do is to use \left. for opening a left brace that is not visible as well as \right. for a hidden right brace. So before you add \\, add \right. Then, add \left. as soon as you start the next line.

Output

\documentclass{article}
\usepackage{amsmath, cancel}
\begin{document}
\begin{align*}
  &= \sigma^2 \left( \cancel{\left(X^TX\right)^{-1}}\cancel{X^T X} \left(X^TX\right)^{-1} + \left(X^T X\right)^{-1}X^TD^T +\right.\\
  &\left.\quad + D X \left(X^TX\right)^{-1} +DD^T \right)=\\
\end{align*}
\end{document}
M. Al Jumaily
  • 4,035
  • 2
  • 11
  • 26
  • 1
    No, wait: with this method, in general, there is no guarantee that the closing parenthesis will be the same size as the opening one. – GuM Aug 23 '19 at 20:54
1

You can not have linebreaks between the \left and \right delimiters, because they define a group. With \right. and \left. you can get line breaks as pointed out by koleygr and M. Al Jumaily, but the parenthesis might have different size. I recommend this solution to get brackets with automatically matching sizes (works even with nested parenthesis).