I'm trying to label a 2D plot with something like $A/B$ rather than $\frac{A}{B}$. I have tried:

Plot[Sin[x], {x, 0, 10}, AxesLabel -> {HoldForm[A/B], y}]

However, this leaves the $x$-axis as $\frac{A}{B}$. Any ideas?


Use InputForm:

Plot[Sin[x], {x, 0, 10}, AxesLabel -> {InputForm[A/B], y}]

Or just string:

Plot[Sin[x], {x, 0, 10}, AxesLabel -> {"A/B", y}]

You can also wrap these things in Style to get further:

Plot[Sin[x], {x, 0, 10}, AxesLabel -> {Style["A/B", 18, Bold, FontFamily -> "Georgia"], y}] 
  • $\begingroup$ String works perfectly. I actually needed something in the form of $A/B_C$, which didn't render correctly with InputForm. Thanks. $\endgroup$
    – cosmoguy
    Nov 26 '12 at 3:00

If you would like to get a display along the lines of the $\LaTeX$ command \nicefrac (with a shifted baseline for the numerator and denominator), you could do the following:

niceFrac[x_, y_] := 
  RowBox[{AdjustmentBox[HoldForm[x], BoxBaselineShift -> -.5], "/", 
    AdjustmentBox[HoldForm[y], BoxBaselineShift -> .5]}]]
SetAttributes[niceFrac, HoldAll]

Plot[Sin[x], {x, 0, 10}, AxesLabel -> {niceFrac[A, B], y}]


What I did in the function niceFrac is to give the first argument a nudge upward, and the second argument an equal downward push relative to the / symbol. This may be a useful compromise when you don't want to be completely one-dimensional but also don't want to waste too much space with the stacked fraction.

I added the HoldAll attribute only to allow you to typeset more complicated expressions that you don't want to evaluate (could be left out).


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.