Group Abstract Group Abstract

Message Boards Message Boards

0
|
75 Views
|
1 Reply
|
1 Total Like
View groups...
Share
Share this post:
GROUPS:

Alignment of grid rows and columns

Posted 5 days ago

After running the code, the rows and columns in the grid are not aligned. How can I set them to align properly?

{a = m, b = n, c = s, d = t}
    Flatten[MapThread[{#1 == #2 // Simplify} &, {{"a+b", "ab", "c+d", "cd",
          "ac+bd", "ad+bc"}, {a + b, a b, c + d, c d, a c + b d, 
         a d + b c}}], 1];
    % // Partition[#, UpTo@4] & // Grid

enter image description here

POSTED BY: Wen Dao
Posted 4 days ago

Grid has an Alignment option. You didn't specify what alignment you wanted. Aligning horizontally as left, center, or right is simple. If you want to align on the "==", then you'll need to create your expressions differently. You code creates expressions that are a mix of strings and symbols, and I don't think Alignment can "look into" such expressions to find the marker to align on. I would approach it as follows:

expressions = {a + b, a b, c + d, c d, a c + b d, a d + b c};
equations = MapThread[Row[{##}, "="] &, {expressions, expressions /. {a -> m, b -> n, c -> s, d -> 999}}];
(* I used 999 to exaggerate the non-alignment you'd see without using the Alignment option *)

Grid[Partition[equations, UpTo[4]]]

enter image description here

Grid[Partition[equations, UpTo[4]], Alignment -> "=", Spacings -> {3, 1}]

enter image description here

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard