2
$\begingroup$

I'm creating a big manipulate box with several sliders, and each slider must have a small explication text (units, for example) after a mathematical symbol. As a simple example, here's the code I'm currently using for a slider :

{{phi, 0, Style[Subscript[\[CurlyPhi], 0] "(degrees)", Bold, 10]},
    0, 360, 0.1,
    ImageSize -> Large,
    Appearance -> {"Labeled", "Closed"}
}

Currently, this isn't displayed correctly since it gives (degrees)phi_0, instead of phi_0 (degrees).

So what should I do to define a properly displayed symbol with text after it ?

$\endgroup$
7
  • 2
    $\begingroup$ You have multiplied the subscript and the string, instead use Row to format expressions in a row, e.g. Row[{Subscript[φ, 0], "(degrees)"}] $\endgroup$ Feb 13 '16 at 21:21
  • $\begingroup$ Remember to make all parts a String and to join them by <>. $\endgroup$
    – gwr
    Feb 13 '16 at 21:21
  • $\begingroup$ Now, which one is best ? String or Row ? $\endgroup$
    – Cham
    Feb 13 '16 at 21:51
  • $\begingroup$ Using Row, how do you change the font size ? $\endgroup$
    – Cham
    Feb 13 '16 at 22:00
  • 1
    $\begingroup$ Style[ToString[Subscript[\[CurlyPhi], 0], TraditionalForm] <> " (degrees)", Bold, 10] $\endgroup$
    – Bob Hanlon
    Feb 13 '16 at 22:51
3
$\begingroup$

I'd use BaseStyle with Row and use Style only on pieces which needed their own special style. I would also protect the φ with HoldForm. In general I wrap expressions that contain symbols and are used for labels with HoldForm. It's mainly a habit, because if the symbols happen to have, or later happen to get assigned, values, then the values will mess up the labels.

Manipulate[
 phi,
 {{phi, 0, 
   Row[{HoldForm@Subscript[φ, 0], "(degrees)"}, " ", BaseStyle -> {Bold, 10}]},
  0, 360, 0.1, ImageSize -> Large, 
  Appearance -> {"Labeled", "Closed"}}]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ I'll mark this answer just because it is showing more options. These could be usefull. $\endgroup$
    – Cham
    Feb 14 '16 at 15:02
  • $\begingroup$ @Cham Thanks. Yes there's not much difference between them. One's preference is, I suppose, a matter of, um, style. ;-) $\endgroup$
    – Michael E2
    Feb 14 '16 at 15:10
3
$\begingroup$

I would use Style with Row like this

Manipulate[
 phi,
 {{phi, 0, Style[Row[{Subscript[φ, 0] , " (degrees)"}], Bold, 10]}, 0, 360, 1, 
    ImageSize -> Large, Appearance -> {"Labeled"}}]

demo

$\endgroup$
1
  • $\begingroup$ Both answers are good and merit to be assigned "THE" answer. Which one should I mark ? $\endgroup$
    – Cham
    Feb 14 '16 at 13:50

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