[Tex/LaTex] Equation and then right-justified comment on same line

formattingmath-mode

How can I create an equation which is centered, and then comment on it on the same line in a right-justified way? I'm looking for something sort of like this

enter image description here

But that I basically rigged by putting a bunch of \qquads in there to place it just right. And even there the equation isn't quite centered.

I imagine if the comment was too long I would put it in a parbox. But in the one above, I couldn't get the comment to go any farther to the right than that without it skipping a line.

Best Answer

You could load the amsmath package, set up an unnumbered display math environment, and use the \tag* macro to right-justify the explanatory string. For instance:

enter image description here

(The vertical lines just indicate the boundaries of the textblock.)

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
a^2+b^2=c^2 \tag*{Pythagoras}
\]
\end{document}

Addendum -- The method shown above manages to center the equation on the textblock if the argument of \tag* is no wider than roughly 1". If you need to typeset more text than fits in a single 1"-long line, I suggest you put it in a tabular environment, as follows -- again, the vertical framelines are just there to to indicate the edges of the textblock:

enter image description here

\documentclass{article}
\usepackage{amsmath,   % for '\tag*' macro
            array,     % for '\newcolumntype' macro
            ragged2e}  % for '\RaggedLeft' macro
\newcolumntype{P}[1]{>{\RaggedLeft}p{#1}}
\usepackage{showframe} % just for this example
\begin{document}
\[
a^2+b^2=c^2 
\]
\[
a^2+b^2=c^2 \tag*{Pythagoras}
\]
\[
a^2+b^2=c^2 
  \tag*{%
  \begin{tabular}{@{}P{1in}@{}}
     Way past the seven hills, in the hut of 
     the seven dwarfs, there lived\dots
  \end{tabular}}
\]
\end{document}