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:

comments not right enough

or the comments bleed into the margin:

comments too far right

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:

correct placement

The LaTeX code is given. I have to use the report document class. Thank you.

% For binomial coefficients that look better i.e. \mbinom

% First example: comments aren't far enough right
&= \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|$]} 


% Second example: comments bleed into the margin
&= \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.

  • 1
    ‘amsmath’ defines ‘\tag*{label}’, which typeset custom label at a place where equation number would be. It is usually at the right margin. The starred version causes the label to be typeset literally.
    – Celdor
    Commented Jun 11, 2022 at 2:08
  • 1
    Welcome to tex.sx. Your hypothesis that the total width of the display block is caused by the length of the longest left-hand plus the longest right-hand component is correct. "Shortening" the over-long left-hand component of the longest line by using \mathrlap (requires mathtools) 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.) Commented Jun 11, 2022 at 2:40

2 Answers 2


I suggest you use an align* environment and place the comments in \tag* "wrappers"; \tag* is a macro provided by the amsmath package. User @Celdor has already made this suggestion in a comment.

To limit the extent to which the presence of the comments push the main math material to the left, I suggest "hiding" the [induction substring in an \llap directive, effectively making it disappear from the width calculations that are performed in the background.

To provide a visual clue that the \mathbbm{1}_{...} elements -- indicator functions, right? -- are "math operators" (in the same way that \ln and \sin are math operators), the code below creates a macro named \one that's given math-operator status.

enter image description here

\usepackage[showframe]{geometry} % omit 'showframe' option in real doc.
\usepackage{mathtools} % for \mathclap macro; load amsmath autom.
\newcommand\one[1]{\mathop{\mathbbm{1}^{}_{#1}}} % indicator function
\usepackage{nccmath} % For \mbinom macro
%%\usepackage{float} % not needed


&= \sum_{\substack{B \le \beta \\ |B| < \ell}} 
   (-1)^{|B|} \mbinom{\beta}{B} f_{B} 
   \sum_{\substack{P \le A \\ \mathclap{|P| = |B|}}} 
   \mbinom{A}{P} g(P + B) \Psi_{\!A - P} 
   \tag*{\llap{[induction} hypothesis]} \\
&= \sum_{P \le A } \sum_{B \le \beta}  
   \one{|P| = |B|} \one{|B| < \ell} \,
   (-1)^{|B|} \mbinom{A}{P} \mbinom{\beta}{B} \Psi_{\!A - P} 
   \tag*{[Thm.\ 1]} \\
&= \sum_{P \le A } \sum_{B \le \beta}  
   \one{|P| = |B|} \one{|P| < \ell} \,
   (-1)^{|P|} \mbinom{A}{P} \mbinom{\beta}{B} \Psi_{\!A - P} 
   \tag*{[since $|P| = |B|$\,]} 

You can create your own macro \commentedmath with two parameters: math and comment based on TeX primitive:

\hbox to\hsize {$math$ \hss comment}

For example, like this:

   \hbox to\hsize{$\displaystyle{}#1$\hss[#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} }   {induction hypothesis}
{ = \sum_{P\le A} \sum_{B\le\beta} \mathbbm{1}_{|P|=|B|} \mathbbm{1}_{|B|<\ell} 
  \, (-1)^{|B|} \mbinom{A}{P} \mbinom{\beta}{B} 
  \Psi_{A-P} }                                  {Thm. 1}
{ = \sum_{P\le A} \sum_{B\le\beta} \mathbbm{1}_{|P|=|B|} \mathbbm{1}_{|P|<\ell}
  \; (-1)^{|P|} \mbinom{A}{P} \mbinom{\beta}{B} 
  \Psi_{A-P} }                                  {since $|P|=|B|$}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .