3
$\begingroup$

I created a Manipulate code which is using several sliders, with the same font output (style, size, font familly, ...). How can I save some space by defining a global style for all the slider controls ?

Here's a simple MWE to show what I mean :

Manipulate[
    ParametricPlot[
        {a Sin[b t + c], d Cos[f t + g]}, {t, 0, 6 Pi},
        Frame -> True, 
        PlotRange -> {{-5, 5}, {-5, 5}}
    ],
    {{a, 1, Style[a, 12, Italic, FontFamily -> "Times"]}, 0, 5, 0.01},
    {{b, 1, Style[b, 12, Italic, FontFamily -> "Times"]}, 0, 10, 0.01},
    {{c, 1, Style[c, 12, Italic, FontFamily -> "Times"]}, 0, 2 Pi, 0.01},
    {{d, 1, Style[d, 12, Italic, FontFamily -> "Times"]}, 0, 5, 0.01},
    {{f, 1, Style[f, 12, Italic, FontFamily -> "Times"]}, 0, 10, 0.01},
    {{g, 1, Style[g, 12, Italic, FontFamily -> "Times"]}, 0, 2 Pi, 0.01}
]

How can we declare the style once for all the controls ? I know it's possible, but I'm unable to find the proper command for this.

$\endgroup$
4
$\begingroup$

You can use the option LabelStyle:

labelstyle = Directive[12, Italic, FontFamily -> "Times"];

Manipulate[ParametricPlot[{a Sin[b t + c], d Cos[f t + g]}, {t, 0, 6 Pi}, 
  Frame -> True, PlotRange -> {{-5, 5}, {-5, 5}}], 
  {{a, 1}, 0, 5,   0.01}, {{b, 1}, 0, 10,  0.01}, 
  {{c, 1}, 0, 2 Pi, 0.01}, {{d, 1}, 0, 5, 0.01}, 
  {{f, 1}, 0, 10, 0.01}, {{g, 1}, 0, 2 Pi, 0.01}, LabelStyle -> labelstyle]

Mathematica graphics

You can override LabelStyle settings by specifying styles for individual controls:

Manipulate[ParametricPlot[{a Sin[b t + c],  Cos[ t ]}, {t, 0, 6 Pi}, 
  Frame -> True,  PlotRange -> {{-5, 5}, {-5, 5}}], 
  {{a, 1, Style["abCDeFGh", FontFamily -> "Lucida Handwriting", Red, Bold,  20]},
    0, 5, 0.01}, 
  {{b, 1}, 0, 10, 0.01}, {{c, 1}, 0, 2 Pi, 0.01},  LabelStyle -> labelstyle]

Mathematica graphics

| improve this answer | |
$\endgroup$
  • $\begingroup$ Doh ! Thanks ! I knew it was so simple ! $\endgroup$ – Cham Apr 23 '16 at 16:07
1
$\begingroup$

I just found another way :

textStyle = Sequence[12, Italic, FontFamily -> "Times"];

Manipulate[
    ParametricPlot[
        {a Sin[b t + c], d Cos[f t + g]}, {t, 0, 6 Pi},
        Frame -> True, 
        PlotRange -> {{-5, 5}, {-5, 5}}
    ],
    {{a, 1, Style[a, textStyle]}, 0, 5, 0.01},
    {{b, 1, Style[b, textStyle]}, 0, 10, 0.01},
    {{c, 1, Style[c, textStyle]}, 0, 2 Pi, 0.01},
    {{d, 1, Style[d, textStyle]}, 0, 5, 0.01},
    {{f, 1, Style[f, textStyle]}, 0, 10, 0.01},
    {{g, 1, Style[g, textStyle]}, 0, 2 Pi, 0.01}
]

Since I'm also using some buttons with another font style (Helvetica instead of Times), this solution appears to be better for my needs.

| improve this answer | |
$\endgroup$

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.