[Tex/LaTex] Aligning equations across multiple lines with proper \left( and \right)

alignline-breaking

I have the following set of equations:

\begin{align}
y_1' &= y_2\\
y_2' &=\dfrac{1}{m}\left(0.05 \,k_f\, sin\left(\dfrac{2 \pi v}{10} t \right) + 0.05 \,k_r\, sin\left(\dfrac{2 \pi v}{10} t - \dfrac{2 \pi (l_1+l_2)}{d}\right) - (k_f+k_r)y_1 - (k_r l_2-k_f l_1)y_3\right)\\
y_3' &= y_4\\
y_4' &= \dfrac{1}{J_0} \left(0.05\,k_r l_2\, sin\left(\dfrac{2 \pi v}{10} t  - \dfrac{2 \pi (l_1+l_2)}{d}\right) - 0.05\,k_f l_1\, sin\left(\dfrac{2 \pi v}{10} t \right) - (k_r l_2 - k_f l_1) y_1 - (k_r l_2^2 + k_f l_1^2) y_3 \right)
\end{align}

enter image description here

The second and fourth equations are too long, so I'd like to break them across multiple lines. I'm trying to use the split environment, but I'm having trouble getting it to work right. My current best attempt for just the first two equations is:

\begin{align}
y_1' &= y_2\\
\begin{split}
y_2' &=\dfrac{1}{m}\left(0.05 \,k_f\, sin\left(\dfrac{2 \pi v}{10} t \right) + 0.05 \,k_r\, sin\left(\dfrac{2 \pi v}{10} t - \dfrac{2 \pi (l_1+l_2)}{d}\right) -  \right.\\
&\left.  (k_f+k_r)y_1 - (k_r l_2-k_f l_1)y_3 \right)\\
\end{split}
\end{align}

The result looks like this:
enter image description here
Somehow the last \right) doesn't know to measure up to the first one, and the equals signs are not actually aligning despite the presence of the ampersands. Also, I would like to make the second line of the second equation move further to the right, but adding an extra & to both lines in appropriate places causes another Extra }, or missing \right error. How would I go about fixing this?

Best Answer

Some suggestions

  • Don't auto-size the outermost parentheses in equations (2) and (4) -- use \biggl[ and \biggr] instead.

    Avoiding the autosizing of the outermost parentheses spares you having to type \right. at the end of the first line and \left. at the start of the second, and having to insert something like \vphantom{\left(\frac{2\pi}{10}\right)} somewhere on the second line in each of the two-line equations just in order to inform LaTeX what the size of the closing \right) parenthesis should be based on.

  • Use \sin instead of sin, and get rid of the \, directives ahead of the \sin terms.

  • Consider loading the mleftright package to get better spacing of the remaining \left( ... \right) pairs.

  • Material in an align environment is in displaymath style by default; no need to write \dfrac instead of just \frac.

enter image description here

\documentclass{article} 
\usepackage{amsmath,mleftright}
\mleftright % for better spacing between "\sin" and "\left("
\begin{document}    
\begin{align}
y_1' &= y_2\\
y_2' &=\frac{1}{m}\biggl[0.05 \,k_f\sin\left(\frac{2 \pi v}{10} t \right) 
       + 0.05 \,k_r\sin\left(\frac{2 \pi v}{10} t - \frac{2 \pi (l_1+l_2)}{d}\right) \notag\\
     &\qquad - (k_f+k_r)y_1 - (k_r l_2-k_f l_1)y_3\biggr]\\
y_3' &= y_4\\
y_4' &= \frac{1}{J_0} \biggl[0.05\,k_r l_2\sin\left(\frac{2 \pi v}{10} t  - \frac{2 \pi (l_1+l_2)}{d}\right) 
      - 0.05\,k_f l_1\sin\left(\frac{2 \pi v}{10} t \right) \notag\\
     &\qquad- (k_r l_2 - k_f l_1) y_1 - (k_r l_2^2 + k_f l_1^2) y_3 \biggr]
\end{align}
\end{document}
Related Question