# Automatically generating and labelling controls in Manipulate

Consider the following code

Manipulate[n,
Dynamic@Grid[{
{"n", Control[{{n, 1, ""}, 1, 10, 1, Appearance -> "Labeled"}]},
{"eq1", Control[{{eq1, x == 1, ""}, InputField, ImageSize -> Small}]}
}],
Alignment -> {{Right, Left}, Automatic}, ControlPlacement -> Left]


Now, my goal is to generate n InputField-type controls. That is, whenever I change the value of n, I add or remove equation controls with not only the correct labelling (eq1, eq2, etc), but also the correct variable labelling (within the Control, I get {eqi,x==1,""}} for each i between 1 and n). How can I do this efficiently?

A first idea that occured to me was to simply use Table, something like

Manipulate[n,
Dynamic@Grid[{
{"n", Control[{{n, 1, ""}, 1, 10, 1, Appearance -> "Labeled"}]},
Table[{"eqi",
Control[{{eqi, x == 1, ""}, InputField, ImageSize -> Small}]}, {i, n}]
}],
Alignment -> {{Right, Left}, Automatic}, ControlPlacement -> Left]


where I am, for the moment, ignoring the relabelling bit (i should be 1, 2, etc). This, however, doesn't work, since I get

I tried to use Flatten, Column and Sequence@@, but no success. I want to have something like

In the end, I have two questions:

1. How do I fix the layout of the Table controls?
2. How do I introduce new variables and controls with the correct ordered labelling?

Any ideas/suggestions are appreciated.

• Regarding the labelling, it seems that StringForm does the trick. I still don't know how to do the variable labelling though. Mar 2 '20 at 15:06

Manipulate[Column[{n, Column[eq[[;; n]]]}, Dividers -> 1],
{{eq, ConstantArray[x == 1, 15]}, ControlType -> None},
Dynamic@Grid[Join[{{"n", Control@{{n, 1, ""}, 1, 15, 1, Appearance -> "Labeled"}}},
Table[With[{i = i}, {Style["eq" <> ToString@i, 12],
InputField[Dynamic[eq[[i]]], ImageSize -> Small]}],
{i, n}]]],
Alignment -> {{Right, Left}, Automatic},
ControlPlacement -> Left]


• My answer is based on your code from the linked question. This answer, however, does not address 1. I do intend to keep the Grid encapsulating all controls, including n. That's why I used Sequence@@. Thank you nonetheless. Mar 3 '20 at 14:57
• @samwolfe, pls see the update.
– kglr
Mar 3 '20 at 15:05