14

Related with How can I use multline within an align environment?.

Consider this document:

\documentclass{minimal}
\usepackage{amsmath,mathtools}
\begin{document}
\begin{align*}
 & \left[k(k+\hbar),[k(k+\hbar),z]\right] \\
 & \qquad = 2[k(k+\hbar),m_yx-m_xy+i\hbar z] \\
 & \qquad = 2m_y[k(k+\hbar),x]-2m_x[k(k+\hbar),y]+2i\hbar[k(k+\hbar),z] \\
 & \qquad = 4m_y(ym_z-m_yz)-4m_x(m_xz-xm_z)+2\left\{k(k+\hbar)z-zk(k+\hbar)\right\} \\
 & \qquad = \!\begin{multlined}[t][10.5cm]
  4(m_xx+m_yy+m_zz)-4(m_x^2+m_y^2+m_z^2)z+{} \\
  +2\left\{k(k+\hbar)z-zk(k+\hbar)\right\} .
 \end{multlined}
\end{align*}
\end{document}

enter image description here

This gives the alignment I'm looking for. But there are a couple of nitpicks:

1) Why do I need the \! before \begin{multlined}? Is there some other way of coding that removes the need for it?

2) The use of a hardcoded width ([10.5cm]) is less than optimal. I'd like to have the last line shoved to the right, or maybe right-aligned with the longest line. Any chance this can be achieved?

  • 2
    I usually write this as [.7\displaywidth], with various values of .7, to avoid needing to know the actual width. I still have to find the correct coefficient in each case, of course. – Mariano Suárez-Álvarez May 18 '13 at 7:42
4

I can offer a quick fix for your \! problem, but I don't know if it has unwanted side effects. For some reason that I don't know, the definition of multlined contains

 \MH_if_boolean:nF {outer_mult}{\null\,}

in its internal macro \MT_mult_internal:n. It appears that this \, is the culprit! So to avoid the \,, you can set the boolean outer_mult "true". At least in your example, this has the desired effect that you don't need \! any more. Maybe the package maintainers can explain the role of outer_mult and its associated \,.

\documentclass{article}
\usepackage{amsmath,mathtools}
\MHInternalSyntaxOn
\MH_set_boolean_T:n {outer_mult}
\MHInternalSyntaxOff
\begin{document}
\begin{align*}
 & \left[k(k+\hbar),[k(k+\hbar),z]\right] \\
 & \qquad = 2[k(k+\hbar),m_yx-m_xy+i\hbar z] \\
 & \qquad = 2m_y[k(k+\hbar),x]-2m_x[k(k+\hbar),y]+2i\hbar[k(k+\hbar),z] \\
 & \qquad = 4m_y(ym_z-m_yz)-4m_x(m_xz-xm_z)+2\left\{k(k+\hbar)z-zk(k+\hbar)\right\} \\
 & \qquad = \begin{multlined}[t][10.5cm]
  4(m_xx+m_yy+m_zz)-4(m_x^2+m_y^2+m_z^2)z+{} \\
  +2\left\{k(k+\hbar)z-zk(k+\hbar)\right\} .
 \end{multlined}
\end{align*}
\end{document}
3

Looking into the mathtools documentation I found shortly after multlined the command \MoveEqLeft. It seems to help a lot in your case. You could do

\documentclass{minimal}
\usepackage{amsmath,mathtools}
\begin{document}
\begin{align*}
 \MoveEqLeft \left[k(k+\hbar),[k(k+\hbar),z]\right] \\
  & = 2[k(k+\hbar),m_yx-m_xy+i\hbar z] \\
  & = 2m_y[k(k+\hbar),x]-2m_x[k(k+\hbar),y]+2i\hbar[k(k+\hbar),z] \\
  & = 4m_y(ym_z-m_yz)-4m_x(m_xz-xm_z)+2\left\{k(k+\hbar)z-zk(k+\hbar)\right\} \\
  & = \begin{multlined}[t][10.5cm]
  4(m_xx+m_yy+m_zz)-4(m_x^2+m_y^2+m_z^2)z+{} \\
  +2\left\{k(k+\hbar)z-zk(k+\hbar)\right\} .
 \end{multlined}
\end{align*}
\end{document}

Unfortunately, as far as I can see, there seems to be no better solution with standard means like amsmath and mathtools. Of course if you would allow left alignment on the last line (of course with some more indentation), you could omit the nested environments altogether.

  • Yes, \MoveEqLeft helps, but still I need the \! to properly align the start of multlined. As for the alignment of the last line, I wasn't trying to align it with the longest line of the parent, but rather to the right margin (or almost, considering the possible equation numbers there). Aligning with the longest line of the parent is just a bonus. – Jellby Jul 28 '12 at 9:58
  • @Jellby: Oh. You are certainly right and I didn't notice that in the output. – bodo Jul 28 '12 at 10:28

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.