2
$\begingroup$

In this question Manipulate with a variable number of sliders one of the answer is

DynamicModule[{n = 5, data = Table[RandomReal[], {20}]}, 
 Column[{Slider[Dynamic[n], {1, 20, 1}], 
   Dynamic[Grid[
     Table[With[{i = i}, {Slider[Dynamic[data[[i]]]], 
        Dynamic[data[[i]]]}], {i, n}]]]}]]

Unfortunately the sliders are developped up to down and I wonder if there is a way to develop them side by side or positionned in a matrix.

Here is the normal behavior

---s---

---s1---

---s2---

---s3---

which after expansion will give

---s---
---s1---

---s2---

---s3---

---s4---

---s5---
. . .

I want --- because it takes less space

---s---
---s1--- ---s3---

---s2--- ---s4---

---s5--- .

   .            .    

   .            . 

   .            .

and why not with 3 or more columns

$\endgroup$
2
  • 2
    $\begingroup$ Have you tried to play with Column/Grid used there? $\endgroup$
    – Kuba
    Commented Aug 24, 2017 at 7:51
  • $\begingroup$ Yes without success $\endgroup$ Commented Aug 24, 2017 at 8:36

1 Answer 1

4
$\begingroup$

Answer to the question after editing

You can use Multicolumn to automatically format elements of a list arranged in a grid of many columns.

DynamicModule[
 {
  n = 5,
  data = Table[RandomReal[], {20}]
  },
 Column[
  {
   Slider[Dynamic[n], {1, 20, 1}],
   Dynamic[
    Multicolumn[
     Table[
      With[{i = i}, 
       Column[{Slider[Dynamic[data[[i]]]], Dynamic[data[[i]]]}]], {i, 
       n}]
     , 3]
    ]
   }
  ]
 ]

Mathematica graphics

Answer to the question before editing

Change Column for Row. Transpose the table.

DynamicModule[
 {
  n = 5
  , data = Table[RandomReal[], {20}]
  },
 Row[
  {
   Slider[Dynamic[n], {1, 20, 1}],
   Dynamic[
    Grid[Transpose@Table[
       With[{i = i}, {Slider[Dynamic[data[[i]]]], Dynamic[data[[i]]]}]
       , {i, n}]
     ]
    ]
   }
  ]
 ]
$\endgroup$
2
  • $\begingroup$ I have edited the question. Hope to have been clearer $\endgroup$ Commented Aug 24, 2017 at 8:55
  • 3
    $\begingroup$ @cyrille.piatecki, doe this answer the new question? In the future, please explain what you need in the question in detail from the beginning. If you then realize you need something different, ask another question. Read here. Now, let's do a clean up of the obsolete comments. $\endgroup$
    – rhermans
    Commented Aug 24, 2017 at 9:05

Your Answer

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

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