1
$\begingroup$

I have:

Clear[s, t]
s[t_] = 189 - 48 t - 11 t^2 + 2 t^3;
v[t_] = s'[t];
a[t_] = s''[t];
Manipulate[
 Graphics[{
   Arrowheads[{-0.02, 0.02}],
   Arrow[{{s[-6], 0}, {s[10], 0}}],
   Red, PointSize[Large],
   Point[{s[t], 0}]
   },
  PlotLabel -> 
   StringForm["Velocity = ``, Acceleration = ``", Round[v[t], .1], 
    Round[a[t], .1]]], {{t, -5}, -6, 10, Appearance -> "Labeled"}]

I'd like to figure out the simplest way to keep the plot label from jumping around as the slider moves.

$\endgroup$

1 Answer 1

3
$\begingroup$

There are two issues:

  1. The number of digits in "Velocity" and "Acceleration" change.
  2. Even when the number of digits are equal you are not using a fixed width font so the space needed varies.

There are a few ways of addressing this. One method is to use Grid and ItemSize instead of StringForm to keep the space reserved for the numbers constant.

Manipulate[Graphics[{
   Arrowheads[{-0.02, 0.02}],
   Arrow[{{s[-6], 0}, {s[10], 0}}],
   Red, PointSize[Large],
   Point[{s[t], 0}]},
  PlotLabel ->
   Grid[{{"Velocity = ", Round[v[t], .1] , " Acceleration = ", Round[a[t], .1]}},
    ItemSize -> {{Automatic, {2 -> 4, 4 -> 4}}, Automatic}]
  ],
 {{t, -5}, -6, 10, Appearance -> "Labeled"}]

Hope this helps.


ItemSize spec for OP's comment below.

In the Details and Options section for Grid have a read of the item Settings for the options Alignment, Background, Frame, ItemSize, and ItemStyle can be given as follows to apply separately to different items and The $\text{spec}_{k}$ can have the following forms directly underneath it.

The first specification is for the column widths and the second for the row heights. It specifies Automatic widths for all columns except columns 2 and 4 as well as Automatic heights for all rows.

$\endgroup$
2
  • $\begingroup$ This does help, a very nice answer. However, I'm not understanding the ItemSize -> {{Automatic, {2 -> 4, 4 -> 4}}, Automatic}. I'm looking in the documentation and Automatic says "separately size items to fit within the total formatting width ." And I think 2->4 and 4->4 specifies the width for item 2 and 4 in the list to four character width, but I'm still not understanding. Would you mind adding a paragraph to your answer explaining this piece of the code? Thanks so much. $\endgroup$
    – David
    Mar 5, 2016 at 23:30
  • $\begingroup$ In the Details and Options section for Grid have a read of the item Settings for the options Alignment, Background, Frame, ItemSize, and ItemStyle can be given as follows to apply separately to different items. $\endgroup$
    – Edmund
    Mar 5, 2016 at 23:39

Your Answer

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

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