5

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.

5

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}
  • A drawback is the equation is not centred w.r.t. the remaining blank space. – Bernard Oct 28 '16 at 19:58
  • @Bernard - I understood the OP's requirement as wanting to center the equation on the textblock. (For sure, the equation in the OP's screenshot doesn't look like it's centered in the "remaining blank space.) However, I may have misunderstood the objective. – Mico Oct 28 '16 at 20:09
  • @Mico I wanted to center it on the textblock. – Eric Auld Oct 28 '16 at 20:11
  • @Mico: Maybe you're right. I just wondered. Anyway the typographical effect depends very much on the length of the comment, of the formula, on the equations around. I don't think there is a general rule. – Bernard Oct 28 '16 at 20:12
  • 1
    You could also try \tag*{\hskip -100pt Pythagoras' Theorem} (say). – GuM Oct 28 '16 at 21:54
0

enter image description here

MWE:

\documentclass[]{article}
\usepackage{geometry}
\usepackage{lipsum}

\usepackage{array,tabularx,mathtools}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}


\begin{document}
\lipsum[2]
\[
\begin{tabularx}{\textwidth}{@{}CCR@{}}
    &   $\mod(R,M)\cong  M$  & Any $M$ module $M$
\end{tabularx}

\]
\lipsum[2]
\end{document}
0

A little convoluted, but this also works:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath}



\begin{document}

Text before.
\begin{flalign*}
    &&a^2+b^2&=c^2
    &\llap{Pythagoras' Theorem}
\end{flalign*}
Text in between.
\[
    a^2+b^2=c^2
\]
Text after.

\end{document}

Output:

Output of the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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