2

Following LaTeX displays the numerator to the left. Question: How can we align the numerator (just like the denominator is) to the center:

\frac{\pi^2}{6}

Display of the above LaTeX:

enter image description here

I tried this suggestion from @DavidCarlisle for another scenario - and it (as asked by the OP there) displays the denominator to the left that makes both numerator and denominator look aligned to the left. But, in my case, I would like the numerator to be aligned to the center (with the denominator).

\frac{\pi^2}{6\hfill}

Display of the above LaTeX:

enter image description here

Desired output:

enter image description here

6
  • 1
    numerator and denominator are centred \pi^2 is wider than \pi, if you want a ^2 that has no width then \pi\rlap{^2} – David Carlisle Apr 29 at 23:27
  • @DavidCarlisle On MikTex, $$\frac{\pi\rlap{^2}}{6}$$ giving error: ! Missing $ inserted. <inserted text> $ l.8 $$\frac{\pi\rlap{^2}}{6} $$ – nam Apr 30 at 1:26
  • 1
    Use \mathrlap and place the ^ before it. Also (off topic), use \[...\] rather than $$. (The fraction line may be too narrow.) – barbara beeton Apr 30 at 2:25
  • @barbarabeeton \[\frac{\pi^{\mathrlap{2}}}{6}\] gives error: ! Undefined control sequence. <argument> \pi ^{\mathrlap{2}} l.6 \[\frac{\pi^{\mathrlap{2}}}{6} \] – nam Apr 30 at 15:51
  • I failed to mention that \mathrlap requires mathtools. But the third example in @Werner's answer looks better anyhow. – barbara beeton Apr 30 at 17:13
2

Here are some options:

enter image description here

\documentclass{article}

\begin{document}

\[
  \frac{\pi^2}{6} \quad % Default
  \frac{\hphantom{^2}\pi^2}{6} \quad % Symmetric exponent around \pi
  \frac{\!\hphantom{^2}\pi^2\!}{6} % Reduced horizontal width of numerator
\]

\end{document}
2

Use \! at the end of the numerator. Sometimes we need to correct the math spacing to get visually better results. For example:

{\pi^2\! \over 6}, \quad \Gamma\!_2.
1

To get a zero-width ², you'll want to define

\newcommand\zwe[1]{\rlap{${}^{#1}$}}

\[
  \frac{\pi\zwe{2}}{6}
\]

although this will have the superscript extending beyond the fraction bar. An alternative definition for \zwe would be to take both the base and exponent as arguments and use an \hphantom on the left to balance the superscript on the right:

\newcommand\zwe[2]{\hphantom{{}^{#2}}#1^{#2}}

\[
  \frac{\zwe{\pi}{2}}{6}
\]

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.