Alignment of grid rows and columns

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

2025-12-11_192519.png

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]]]

testA.bmp (44.5 KB)

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

testB.bmp (69.3 KB)