Any trick to add a separator inside the grid between the lines at the point where it is needed

To add a separator between the lines in the grid, I know how to do this using the parameter Dividers. But this is used at the end, and then you need to know the line number, which should be below the separator. Thus, for a large grid, I find that I am using a trial version and an error until I find the correct line number. Then, when I change the grid later, I have to run the trial version and error again to put the divider in the right place if it changes after my changes.

In this example, there is a grid with 3 rows, and I want to add a separator below to say the second row, so I can do this:

Grid[{
  {1},
  {2},
  {3}
  }, Frame -> True, Dividers -> {All, 3 -> True}]

Another way: to put Falseand Truein the correct order where I want the divisor, for example

Grid[{
  {1},
  {2},
  {3}
  }, Frame -> True, Dividers -> {All, {True, False, True, True}}]

enter image description here

It would be nice if I could do something like this (how can this be done for Manipulate) (of course, this does not work here below)

Grid[{
  {1},
  {2},
  Delimiter,
  {3}
  }, Frame -> True]

or

Grid[{
  {1},
  {Item[2,Dividers->True]},
  {3}
  }, Frame -> True]

or such a thing.

This will simplify code maintenance.

I looked at using Item, etc. for this, but could not understand.

Does anyone know about this to do this?

change

btw, , , Dividers. Grid, Grid, . , , , . , , , Spacings .. , / , .

, Mathematica Grid, .

, Mathematica GUI-.

, 60% , , . GUI- . Matlab GUIDE , 5% , .

, WRI GUI- Mathematica, , - Mathematica, . :)

(2)

. , Manipulate. :

Manipulate[x,

 Grid[{
   {Control[{{x, 0, "x"}, 0, 10, 1}]},
   {Control[{{y, 0, "y"}, 0, 10, 1}]}
   }, Frame -> None, Dividers -> {None, {False, True, False}}
  ]
 ]

enter image description here

( Grid ). . , Wizard , :

Manipulate[x,

 myGrid[{
   {Control[{{x, 0, "x"}, 0, 10, 1}]},
   spec["Divider"],
   {Control[{{y, 0, "y"}, 0, 10, 1}]}
   }, Frame -> None
  ],

 Initialization :>
  {
   specfunc["Divider", lst_] := Dividers -> {None, # -> True & /@ lst};

   myGrid[dat_, opts : OptionsPattern[]] :=
    Module[{x = 1}, 
     Grid[#, opts, Sequence @@ #2] & @@ 
      Reap[If[MatchQ[#, _spec], Sow[x, #[[1]]]; ## &[], x++; #] & /@ 
        dat, _, specfunc]
     ]

   }
 ]

, Mathematica , , .

Manipulate , , :

myGrid[{
  {Control[{{x, 0, "x"}, 0, 10, 1}]},
  spec["Divider"],
  {Control[{{y, 0, "y"}, 0, 10, 1}]}
  }, Frame -> None
 ]

specfunc["Divider", lst_] := Dividers -> {None, # -> True & /@ lst};
myGrid[dat_, opts : OptionsPattern[]] :=
 Module[{x = 1}, 
  Grid[#, opts, Sequence @@ #2] & @@ 
   Reap[If[MatchQ[#, _spec], Sow[x, #[[1]]]; ## &[], x++; #] & /@ 
     dat, _, specfunc]
  ]

enter image description here

, , Manipulate.

btw, Manipulate . , , With[{},.... Grid....], .

, , .

[] , ?

(3) - , Manipulate:

:

Manipulate[x,

 Evaluate@grid[{
    {Control[{{x, 0, "x"}, 0, 10, 1}]}
    }
   ],

 Initialization :> 
  {
   grid[tab_, opts___] := 
     Module[{divlocal, divglobal, div, pos}, 
      divglobal = (Dividers /. opts) /. Dividers -> {False, False};
      If[Depth[divglobal] == 1, divglobal = {divglobal, divglobal}];
      If[Length[divglobal] == 1, AppendTo[divglobal, False]];
      pos = Position[tab, Dividers -> _, 1];
      divlocal = 
       MapIndexed[# - #2[[1]] + 1 -> Dividers /. tab[[#]] &, 
        Flatten[pos]];
      divglobal[[2]] = {divglobal[[2]], divlocal};
      Grid[Delete[tab, pos], Dividers -> divglobal, opts]];


   }
 ]

:

ReplaceAll::rmix: Elements of {False,{}} are a mixture of lists and nonlists. >>

Evaluate@grid[{
   Dividers -> {Thick, Blue},
   {Control[{{x, 0, "x"}, 0, 10, 1}]}
   }
  ],

Dynamic@ Evaluate@ . - , ? ?

+5
2

, , , Dividers.

grid[tab_, opts___] :=
 Module[{divlocal, divglobal, div, pos},

  (* extract option value of Dividers from opts to divglobal *)
  (* default value is {False, False} *)
  divglobal = (Dividers /. {opts}) /. Dividers -> {False, False};

  (* transform divglobal so that it is in the form {colspecs, rowspecs} *)
  If[Head[divglobal] =!= List, divglobal = {divglobal, divglobal}];
  If[Length[divglobal] == 1, AppendTo[divglobal, False]];

  (* Extract positions of dividers between rows from tab *)
  pos = Position[tab, Dividers -> _, 1];

  (* Build list of rules for divider specifications between rows *)
  divlocal = MapIndexed[# - #2[[1]] + 1 -> Dividers /. tab[[#]] &, Flatten[pos]];

  (* Final settings for dividers are {colspecs, {rowspecs, divlocal}} *)
  divglobal[[2]] = {divglobal[[2]], divlocal};
  Grid[Delete[tab, pos], Dividers -> divglobal, opts]]

, Dividers->spec , spec - False, True, (, ..).

tab = {{1, 2, 3}, Dividers -> {Thick, Blue}, {4, 5, 6}, {7, 8, 9}, 
   Dividers -> False, {10, 11, 12}};

grid[tab, Dividers -> All]

Mathematica graphics

Edit

- .

+4

, (spec ) , (specfunc ) . , , .

specfunc["Divider", lst_] := Dividers -> {All, # -> True & /@ lst}

myGrid[dat_, opts:OptionsPattern[]] :=
 Module[{x = 1},
  Grid[#, opts, Sequence @@ #2] & @@
   Reap[
     If[MatchQ[#, _spec], Sow[x, #[[1]]]; ## &[], x++; #] & /@ dat,
     _,
     specfunc
   ]
 ]

:

dat =
{
   {1, 2, 3},
   {4, 5, 6},
   spec["Divider"],
   {7, 8, 9}, 
   spec["Divider"],
   {"a", "b", "c"}
};

myGrid[dat, Frame -> True]

Mathematica graphics


, "Divider", , , spec MatchQ[#, _String] Sow[x, #].


, , , Manipulate , . , ​​ Manipulate , , .

, , , , , :

Manipulate[x,
 Evaluate[
  {specfunc["Divider", lst_] := Dividers -> {All, # -> True & /@ lst};
   myGrid[dat_, opts : OptionsPattern[]] := 
    Module[{x = 1}, 
     Grid[#, opts, Sequence @@ #2] & @@ 
      Reap[If[MatchQ[#, _spec], Sow[x, #[[1]]]; ## &[], x++; #] & /@ 
        dat, _, specfunc]]};
  myGrid[{{Control[{{x, 0, "x"}, 0, 10, 1}]}, 
    spec["Divider"], {Control[{{y, 0, "y"}, 0, 10, 1}]}}, 
   Frame -> True]
  ]
 ]
+2

All Articles