[Tex/LaTex] Right align a line in align-environment

alignhorizontal alignment

Searching the website I found plenty of similarly related questions, such as this, this or this one. Nevertheless none of the answers to the questions I found so far addressed precisely this issue.

As it happens, I have a series of equations and some of them are too long to fit a line. I would like to break them in two parts, with the upper part being aligned to the $=$-sign and the bottom part being aligned on the right margin. The output, in this case obtained using \hspace, should look like this

\documentclass[11pt]{article}

\usepackage[english]{babel}
\usepackage{amsmath}

\begin{document}

Here I write a line to be sure of the precise and exact extension of the margin.

\begin{align*}
\mathrm{HTr}K^\Gamma_{\overline{M}_{-k}}(t) = &  \sum_{\gamma \in H(\Gamma)} \int_X \sum_{[\kappa] \in \Gamma\backslash\Gamma_\gamma} \sum_{n=1}^\infty  j(\kappa^{-1}\gamma^n\kappa,z)^k\times{} \\
& \hspace{4.6cm} \times K_{-k,\text{hyp}}(t;\kappa^{-1}\gamma^n\kappa(z),z) \mu_\text{hyp}(z) 
\intertext{Now I comment on the next step,}
= &  \sum_{\gamma \in H(\Gamma)} \int_X \sum_{[\kappa] \in \Gamma\backslash\Gamma_\gamma} \sum_{n=1}^\infty  j(\kappa^{-1}\gamma^n\kappa,z)^k\times{} \\
& \hspace{4.6cm} \times K_{-k,\text{hyp}}(t;\kappa^{-1}\gamma^n\kappa(z),z) \mu_\text{hyp}(z) 
\intertext{And finally it simplifies}
= & \; 0.
\end{align*}
\end{document}

enter image description here

Is there a way to automatically align the second line to the right margin? I imagine something like flushright that works inside the align environment, or, as the present answer seems to suggest, a way to realign the equations into a multline-environment.

Thank you!

Best Answer

The environment you want is multline*, not align*:

\documentclass[11pt]{article}

\usepackage[english]{babel}
\usepackage{amsmath}

\DeclareMathOperator{\HTr}{HTr}

\begin{document}

Here I write a line to be sure of the precise and exact extension of the margin.
\begin{multline*}
\HTr K^\Gamma_{\overline{M}_{-k}}(t) =
  \sum_{\gamma \in H(\Gamma)} \int_X \sum_{[\kappa] \in \Gamma\setminus\Gamma_\gamma}
  \sum_{n=1}^\infty  j(\kappa^{-1}\gamma^n\kappa,z)^k\times{} \\
\times K_{-k,\mathrm{hyp}}(t;\kappa^{-1}\gamma^n\kappa(z),z) \mu_{\mathrm{hyp}}(z)
\end{multline*}
\end{document}

enter image description here

Note the {} after the trailing \times. Also \mathrm{HTr} is wrong and the same is for \text{hyp}; your \backslash should be \setminus.

For splitting lines keeping the alignment at the relation signs, there is multlined (requires mathtools):

\documentclass[11pt]{article}

\usepackage[english]{babel}
\usepackage{mathtools}

\DeclareMathOperator{\HTr}{HTr}

\begin{document}

Here I write a line to be sure of the precise and exact extension of the margin.

\begin{align*}
\HTr K^\Gamma_{\overline{M}_{-k}}(t) 
&= \begin{multlined}[t]
   \sum_{\gamma \in H(\Gamma)} \int_X \sum_{[\kappa] \in \Gamma\setminus\Gamma_\gamma}
     \sum_{n=1}^\infty  j(\kappa^{-1}\gamma^n\kappa,z)^k\times{} \\[2ex]
   \times K_{-k,\text{hyp}}(t;\kappa^{-1}\gamma^n\kappa(z),z) \mu_{\mathrm{hyp}}(z)
   \end{multlined}
\intertext{Now I comment on the next step,}
&= \begin{multlined}[t]
   \sum_{\gamma \in H(\Gamma)} \int_X \sum_{[\kappa] \in \Gamma\setminus\Gamma_\gamma}
     \sum_{n=1}^\infty  j(\kappa^{-1}\gamma^n\kappa,z)^k\times{} \\[2ex]
   \times K_{-k,\mathrm{hyp}}(t;\kappa^{-1}\gamma^n\kappa(z),z) \mu_{\mathrm{hyp}}(z)
   \end{multlined}
\intertext{And finally it simplifies}
&= 0.
\end{align*}
\end{document}

enter image description here