2
$\begingroup$

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?

$\endgroup$

2 Answers 2

2
$\begingroup$

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}] 
$\endgroup$
1
  • $\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, 2012 at 3:00
5
$\begingroup$

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_] := 
 DisplayForm[
  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}]

nicefrac

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).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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