Aligning Control in Manipulate
You can use the Method
suboption "ControlAreaDisplayFunction"
to modify the control labels to have the same size:
Manipulate[a,
Control[{a, 0, 1, 0.1}],
Dynamic[If[a < 1, Control[{{abc, 0}, {0, 1}}],
Control[{{abcdef, 0}, {0, 1}}]]], ControlPlacement -> Left,
ContentSize -> {100, 100}, Alignment -> Center,
Method -> {"ControlAreaDisplayFunction" ->
(Replace[#, RawBoxes[s_] :> Item[s, ItemSize -> {5, 2}], All] &)}]
Alternatively, you can use
Method -> {"ControlAreaDisplayFunction" -> (Replace[#,
RawBoxes[s_] :> Pane[s, Alignment -> Right,
ImageSize -> Rasterize["abcdef", "RasterSize"]], All] &)}
Note: As far as I know the option Method
and its suboptions are not documented. I came across $ManipulateMethodOptions
during a spelunking expedition using ??*`*Manipulat*
. Clicking on one of the results gave:
Manipulate`Dump`$ManipulateMethodOptions
{"BookmarkAnimationClipping" -> True,
"BookmarkDurationMultiplier" -> 1.5`,
"ContentAreaBackground" -> Automatic,
"ControlAreaDisplayFunction" -> (#1 &), "ExtraVariables" :> {},
"DynamicCore" -> True, "HeuristicControllerBindings" -> True,
"InlineCell" -> False, "SingleEvaluation" -> True,
"ShowControls" -> True, "TemplateExpand" -> False}
Update: An alternative approach is to wrap control labels with Pane
and use the rastersize of the longest label as the ImageSize
:
is = Rasterize["abcdef", "RasterSize"];
pane = Pane[#, ImageSize -> is, Alignment -> Right] &;
Manipulate[a,
Control[{{a, 0, pane@"a"}, 0, 1, 0.1}],
Dynamic[If[a < 1, Control[{{abc, 0, pane@"abc"}, {0, 1}}],
Control[{{abcdef, 0, pane@"abcdef"}, {0, 1}}]]],
ControlPlacement -> Left, ContentSize -> {100, 100}, Alignment -> Center]
Update 2: To make a control invisible without adding vertical space between its neighbors:
Manipulate[a,
Dynamic @ Grid[{{pane @ "a", Control[{{a, 0, ""}, 0, 1, 0.1}]},
If[a < 1, {pane @ "abcdef", Control[{{abcdef, 0, ""}, {0, 1}}]}, ## &[]],
{pane@"b", Control[{{b, 0, ""}, 0, 1, 0.1}]}},
Alignment -> {{Right, Left}, Automatic}], ControlPlacement -> Left]
You can put your Control
s in a Column
to lay out your controls in a arbitrary way. From here, you can use the Alignment
option for Column.
Manipulate[a,
Column[{Control[{{a, 0}, {0, 1}}],
Dynamic[If[a == 0, Control[{{abc, 0}, {0, 1}}],
Control[{{abcdef, 0}, {0, 1}}]]]}, Alignment -> Right],
ControlPlacement -> Left]
You could use Grid
. Like so:
Manipulate[a,
Dynamic @
Grid[
{{"a", Control[{{a, 0, ""}, 0, 1, 0.1}]},
If[a < 1,
{"abc", Control[{{abc, 0, ""}, {0, 1}}]},
{"abcde", Control[{{abcdef, 0, ""}, {0, 1}}]}]},
Alignment -> {{Right, Left}, Automatic}],
ControlPlacement -> Left]
Update
The following is added to address concerns raised by the OP in a comment to this answer.
Maybe this will work for you.
Manipulate[a,
Dynamic @
Grid[
{{"a", Control[{{a, 0, ""}, 0, 1, 0.1}]},
If[a < 1,
{"abc", Control[{{abc, 0, ""}, {0, 1}}]},
{"", SpanFromLeft}]},
Alignment -> {{Right, Left}, Automatic}],
ControlPlacement -> Left]