3
$\begingroup$

I need to show a layer of information on a 3D graphics, inside a manipulate box. Currently, all the code is working great, except that the text should be aligned to the left, while the output numbers should be aligned to the right (with a small spacing between text and the numbers). Here's a MWE to show my problem, and a preview picture :

Info := Text[Row[{
    "Initial velocity :\t\t\t\t\t", NumberForm[0.678889, {12, 3}], "\[ScriptC]\n",
    "Final drift velocity :\t\t\t", NumberForm[0.567892, {12, 3}], "\[ScriptC]\n",
    "Final velocity :\t", NumberForm[0.5467899, {12, 3}], "\[ScriptC]\n",
    "Final adiabatic velocity :\t", NumberForm[0.2135467, {12, 3}], "\[ScriptC]\n",
    "Relative deviation of velocity :\t", NumberForm[112.6732145, {3, 1}], "%\n",
    "Ratio of radii :\t", NumberForm[237.9867, {3, 1}]
}, BaseStyle -> {FontSize -> 14, FontFamily -> "Courier", TextAlignment -> Left}],
{0.3, 0.075}]

ParametricPlot3D[{Sin[6 t], Cos[12 t], Sin[3 t]}, {t, -10, 10},
    PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}},
    Boxed -> True,
    Axes -> True,
    AxesOrigin -> {0, 0, 0},
    Epilog -> Info,
    SphericalRegion -> True,
    ImageSize -> {700, 700}]

Preview :

text and numbers

Currently, using several tabs (\t) doesn't work very well.

So how can I align all the text lines to the left, and align all the numbers to the right? (or even align numbers on their point separator, if possible?)

$\endgroup$
3
$\begingroup$

You could define Info like this:

Info := Inset[
  Grid[{{"Initial velocity : ", 
     NumberForm[0.678889, {12, 3}], 
     "\[ScriptC]"}, {"Final drift velocity : ", 
     NumberForm[0.567892, {12, 3}], 
     "\[ScriptC]"}, {"Final velocity : ", 
     NumberForm[0.5467899, {12, 3}], 
     "\[ScriptC]"}, {"Final adiabatic velocity : ", 
     NumberForm[0.2135467, {12, 3}], 
     "\[ScriptC]"}, {"Relative deviation of velocity : ", 
     NumberForm[112.6732145, {3, 1}], "%"}, {"Ratio of radii : ", 
     NumberForm[237.9867, {3, 1}]}}, 
   BaseStyle -> {FontSize -> 14, FontFamily -> "Courier"}, 
   Alignment -> Left], {0.3, 0.075}]
$\endgroup$
  • $\begingroup$ Appears to work very well. I'll study this... $\endgroup$ – Cham Feb 21 '16 at 17:24
  • $\begingroup$ This solution is doing exactly what I was asking. Thanks a lot ! I'm very tempted to mark it immediately as "THE" solution. Just a question before : what controls the spacing after the numbers, just before their units ? What if I prefer a smaller spacing for the units only ? $\endgroup$ – Cham Feb 21 '16 at 17:34
  • $\begingroup$ See the ItemSize option for Grid. Also using Frame->All to see the grid cells. $\endgroup$ – Chris Degnen Feb 21 '16 at 17:45
  • $\begingroup$ Wow ! The Frame->All option is nice, as a table in the 3D view ! $\endgroup$ – Cham Feb 21 '16 at 17:50
  • $\begingroup$ You could also put the 2nd & 3rd column together with Row, inside the grid. $\endgroup$ – Chris Degnen Feb 21 '16 at 17:52

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.