I am trying to use alignat*
to have flushed-right comments on equations. The comments are correctly aligned, but I can't find a way to ensure they are flushing to the document's margins. Either the comments don't go all the way right:
or the comments bleed into the margin:
It seems like the comment placement is determined by the longest equation length and the longest comment length. However, that's not necessary, because some long equations have short comments that won't run into them. I would like it to be something like this:
The LaTeX code is given. I have to use the report
document class. Thank you.
\documentclass[11pt]{report}
\usepackage[fleqn]{amsmath}
\usepackage{amssymb}
% For binomial coefficients that look better i.e. \mbinom
\usepackage{nccmath}
\usepackage{float}
\usepackage{geometry}
\usepackage{bbm}
\begin{document}
% First example: comments aren't far enough right
{\setlength{\mathindent}{0cm}
\begin{alignat*}{2}
&= \sum_{\substack{B \le \beta \\ |B| < \ell}} (-1)^{|B|} \mbinom{\beta}{B} f_{B} \sum_{\substack{P \le A \\ |P| = |B|}} \mbinom{A}{P} g(P + B) \Psi_{A - P} &\small\text{[induction hypothesis]} \\
&= \sum_{P \le A } \sum_{B \le \beta} \mathbbm{1}_{|P| = |B|} \mathbbm{1}_{|B| < \ell} \thinspace (-1)^{|B|} \mbinom{A}{P} \mbinom{\beta}{B} \Psi_{A - P} &\small\text{[Thm.~1]} \\ \\
&= \sum_{P \le A } \sum_{B \le \beta} \mathbbm{1}_{|P| = |B|} \mathbbm{1}_{|P| < \ell} \thinspace (-1)^{|P|} \mbinom{A}{P} \mbinom{\beta}{B} \Psi_{A - P} &\small\text{[since $|P| = |B|$]}
\end{alignat*}}
\bigskip
\bigskip
% Second example: comments bleed into the margin
{\setlength{\mathindent}{0cm}
\begin{alignat*}{2}
&= \sum_{\substack{B \le \beta \\ |B| < \ell}} (-1)^{|B|} \mbinom{\beta}{B} H_{\beta - B} \sum_{\substack{P \le A \\ |P| = |B|}} \mbinom{A}{P} \langle H_{P}, H_{B} \rangle H_{A - P} &\small\text{[induction hypothesis]} \\
&= \sum_{P \le A } \sum_{B \le \beta} \mathbbm{1}_{|P| = |B|} \mathbbm{1}_{|B| < \ell} \thinspace (-1)^{|B|} \mbinom{A}{P} \mbinom{\beta}{B} \langle H_{P}, H_{B} \rangle \Psi_{A - P} \Psi_{\beta - B} &\small\text{[Thm.~2]} \\
&\vdots \\
&= \sum_{\substack{P \le A \\ |P| < |A| = \ell} } \thinspace (-1)^{|P|} \mbinom{A}{P} H_{A - P} \thinspace \partial^{P} H_{\beta} &\small\text{[induc.~on $\partial^{P}\Psi_{\beta}$ for $|P| < \ell$]} \\
&= \mathcal{S}_2.
\end{alignat*}}
\end{document}
\mathrlap
(requiresmathtools
) plus setting the right-hand elements using\tag*
as already suggested should give the result you're looking for. (I won't say this is the best solution, but I'm not in a position to experiment at the moment.)