Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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-Alvarez May 18 '13 at 7:42
add comment

2 Answers

up vote 4 down vote accepted

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}
share|improve this answer
add comment

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.

share|improve this answer
    
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. –  canaaerus Jul 28 '12 at 10:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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