7
$\begingroup$

I can add the value of a slider to the right of it using the Appearance-->Labelled option, but what if I want to add text after the automatic label. How can I do that?

Normally I want to do this to show the units of the value. For example, if the slider label is "4.7", I might want it to read "4.7 meters".

$\endgroup$
8
$\begingroup$

There are many ways to do this. The most basic is to use Control, added few versions earlier just for this purpose. Here is an example. Control can be inserted inside Row or Column or Grid for example

Manipulate[x,
 Row[{Control[{{x, 1, "x="}, 0, 1, .1}],
   Spacer[5],
   Dynamic[x],
   Spacer[2],
   "meters"}]
 ]

Mathematica graphics

$\endgroup$
5
$\begingroup$

You can use Quantity to specify the initial value and domain of a control:

Manipulate[x, {{x, Quantity[1, "Meters"], "x ="},
               Quantity[Range[0, 1, .1], "Meters"],
               ControlType -> Manipulator , 
               Appearance -> "Labeled"}]

enter image description here

Few more alternatives:

Manipulate[Quantity[x, "Meters"], 
 Row[{Control[{{x, 1, "x="}, 0, 1, .1}], Spacer[5], Dynamic@Quantity[x, "Meters"]}]]

Manipulate[Quantity[x, "Meters"],
 Labeled[Control[{{x, 1, "x="}, 0, 1, .1}], Dynamic@Quantity[x, "Meters"], Right]]
$\endgroup$
  • $\begingroup$ This looks good, but what if the text is not a quantity? How can I place arbitrary text instead of "Meters"? $\endgroup$ – philmcole May 13 '18 at 8:56
  • $\begingroup$ @philmcole, nasser's and eldo's answers should work for that case. $\endgroup$ – kglr May 15 '18 at 19:56
1
$\begingroup$
Framed[
 Row[{
   "Interval",
   IntervalSlider[Dynamic[m], {0, 3, 0.1}, Appearance -> "Markers"],
   Dynamic[m],
   " meters"}],
 Background -> GrayLevel@0.9,
 FrameMargins -> 15]

enter image description here

Thanks to alancalvitty's comment: Much nicer is:

Framed[
 Row[{
   "Interval",
   IntervalSlider[
    Dynamic[m], {0, 3, 0.1},
    Appearance -> "Markers"],
   Dynamic[m], " meters"}],
 BaseStyle -> Directive[FontFamily -> "Helvetica", FontSize -> 14],
 RoundingRadius -> 10,
 Background -> GrayLevel @ 0.9,
 FrameMargins -> 15,
 FrameStyle -> GrayLevel @ 0.7]

enter image description here

$\endgroup$
  • $\begingroup$ Eldo, that's nice. Add these to Framed: RoundingRadius -> 10, BaseStyle -> Directive[FontFamily -> "Helvetica", FontSize -> 14]] $\endgroup$ – alancalvitti Oct 1 '14 at 18:18

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.