4

I'm writing a large equation for which I need to introduce line breaks in order to make it more legible. I'm using the following code:

\documentclass{report}
\usepackage{mathtools}

\begin{document}
\begin{align}
        H &= \lambda_{R_x}V_x + \lambda_{R_y}V_y + \lambda_{R_z}V_z \nonumber \\
          &\mathrel{\phantom{=}} \kern+\nulldelimiterspace +\,\lambda_{V_x}\left(\frac{T}{m}\cos{\psi}\cos{\phi}\right) \nonumber \\ 
          &\mathrel{\phantom{=}} \kern+\nulldelimiterspace +\,\lambda_{V_y}\left(\frac{T}{m}\cos{\psi}\sin{\phi}\right) \nonumber \\
          &\mathrel{\phantom{=}} \kern+\nulldelimiterspace +\,\lambda_{V_z}\left(\frac{T}{m}\sin{\psi} - g\right) \nonumber \\
          &\mathrel{\phantom{=}} \kern+\nulldelimiterspace +\,\lambda_{m}\left(-\frac{T}{c}\right) \nonumber \\
          &\mathrel{\phantom{=}} \kern+\nulldelimiterspace +\,\mu_{u}\left(u^2_x + u^2_y + u^2_z -1\right) \nonumber\\
\end{align}

\end{document}

The output is the following:

enter image description here

I don't know what I should modify within the code in order to make the equation number aligned with the last math expression. As you can see, the equation number appears further down.

7
  • 1
    Just get rid of the last `\nonumber \\` – Willoughby Apr 15 at 16:18
  • 1
    a @Willoughby said but also why the complicated \mathrel{\phantom{=}} \kern+\nulldelimiterspace +\, I would just have written \quad{}+ – David Carlisle Apr 15 at 16:20
  • I tried it @Willoughby, but what I get it's a double label: the first one correctly aligned to the last math expression (as I would), the second one just immediately below the first one. – Catarella Apr 15 at 16:21
  • 1
    The last line of align doesn't need a \\, by adding that you add a new line in the align environment which gets numbered – Willoughby Apr 15 at 16:22
  • 1
    Just for information: where did you get the idea of \kern\nulldelimiterspace? “Cabbage for a snack” we'd say in Italy. ;-) – egreg Apr 15 at 16:50
8

If you want to number only the last equation it is easier to use aligned with the [b] specifier, which spares you typing all the \nonumbers. Note also that your construction to align the + signs and get the correct spacing is overly complicated. You can put & after = and preserve the correct spacing by adding an empty group ={}&.

\documentclass{report}
\usepackage{mathtools}

\begin{document}

\begin{equation}
\begin{aligned}[b]
H ={}& \lambda_{R_x}V_x + \lambda_{R_y}V_y + \lambda_{R_z} V_z  \\
     &+\lambda_{V_x}\left(\frac{T}{m} \cos\psi \cos\phi\right) \\ 
     &+\lambda_{V_y}\left(\frac{T}{m} \cos\psi \sin\phi\right) \\
     &+\lambda_{V_z}\left(\frac{T}{m} \sin\psi - g\right) \\
     &+\lambda_{m}\left(-\frac{T}{c}\right) \\
     &+\mu_{u} \left(u^2_x + u^2_y + u^2_z -1\right)
\end{aligned}
\end{equation}

\end{document}

enter image description here

Personally I'd get rid of all \left/\right, and replace them by \biggl/\biggr. (Except the last one of course.) (But do you really need them?) Note also that

\cos{\psi}

isn't doing what you probably think, since \cos & Co. take no argument. If you don't want to write \cos(\psi), then \cos\psi is absolutely fine.

1
  • That's really useful @campa. Thank you for the complete answer. I was overcomplicating the code! – Catarella Apr 15 at 16:55
6

Here's another aligned-based solution, which gets by without having to produce large parentheses.

enter image description here

\documentclass{report}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}[b]
H &= \lambda_{R_x}V_x + \lambda_{R_y}V_y + \lambda_{R_z}V_z \\
  &\quad+\frac{T}{m}\bigl(\lambda_{V_x}\cos\psi\cos\phi
                         +\lambda_{V_y}\cos\psi\sin\phi  
                         +\lambda_{V_z}(\sin\psi - g) \bigr) \\
  &\quad-\frac{T}{c}\,\lambda_{m}  +\mu_{u}(u^2_x + u^2_y + u^2_z -1)
\end{aligned}
\end{equation}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.