# How to produce a graphic-algabric figure in Mathematica with proper alignment?

Given a symmetry $$S$$, we can block-diagonalize a Hamiltonian, i.e, $$S^\dagger H S = H_{\text{block}}$$. The following image demonstrates that. I wonder how one can combine equations and plots with proper alignment to make a "graphic-algebraic" equation in Mathematica?

Currently, I just make different elements (such as MatrixPlots and MaTeX [3rd party package] expressions) of the expression and write a

Print[MaTeX["S^{\\dagger}", FontSize -> 15], p1, MaTeX[" S \\quad = \\quad", FontSize -> 15], p2]


Unfortunately, this is not a Graphics object and can't be exported.

Code to reproduce the graphics (Uses [MaTeX][2])
fontsize = 9;
font = "Times";
SetOptions[{MatrixPlot}, {Frame -> True, FrameStyle -> Black,
LabelStyle -> {FontFamily -> "Times", FontSize -> fontsize, Black}}];
<< MaTeX

L = 6;
(*Hamiltonian*)

op1String = Table[If[i == j, sx, z], {i, 1, L}, {j, 1, L}];
rule = {sx -> \[Sigma][1], sy -> \[Sigma][2], sz -> \[Sigma][3], z -> \[Sigma][0]};
rule1 = {\[Sigma][1] -> PauliMatrix[1], \[Sigma][2] -> PauliMatrix[2], \[Sigma][3] -> PauliMatrix[3], \[Sigma][0] -> PauliMatrix[0]};
op1S = (op1String /. rule);
op1 = (Total@Apply[KroneckerProduct, op1S, 1]) /. rule1; (*hx Sx*)

op3String = Table[If[i == j || i + 1 == j, sz, z], {i, 1, L - 1}, {j, 1, L}];
op3S = (op3String /. rule);
op3 = (Total@Apply[KroneckerProduct, op3S, 1]) /. rule1; (*J Sz Sz*)

symmop = Apply[KroneckerProduct, Table[sx, L] /. rule] /. rule1;
J = 1.;
gx = 1.8;
H = J gx op1 + J op3;

{evals, evecs} = SortBy[Eigensystem[N@symmop]\[Transpose], First]\[Transpose];
Tmat = evecs\[Transpose];

p1 = MatrixPlot[H, ImageSize -> 150, Mesh -> {1, 1}, MeshStyle -> Directive[Opacity[0.4, Black], Dashed]];
p2 = MatrixPlot[Chop[Tmat\[ConjugateTranspose] . H . Tmat], ImageSize -> 150, Mesh -> {1, 1}, MeshStyle -> Directive[Opacity[0.4, Black], Dashed], Epilog -> {Text[Style[MaTeX["\\lambda_S = -1"], FontFamily -> font, FontSize -> fontsize], {15, 60}], Text[ Style[MaTeX["\\lambda_S = 1"], FontFamily -> font, FontSize -> fontsize], {47, 25}] }];
p3 = Print[MaTeX["S^{\\dagger}", FontSize -> 15], p1, MaTeX[" S \\quad = \\quad", FontSize -> 15], p2]


## 1 Answer

If you want to export them you can use the text as an FrameLabel (with the corrsponding rotation, using Rotate):

p1 = MatrixPlot[H, ImageSize -> 350, Mesh -> {1, 1}, MeshStyle -> Directive[Opacity[0.4, Black], Dashed], FrameLabel ->
Rotate[MaTeX["S^{\\dagger}", FontSize -> 15], -90 Degree]];
p2 = MatrixPlot[Chop[Tmat\[ConjugateTranspose] . H . Tmat], ImageSize -> 380, Mesh -> {1, 1}, MeshStyle -> Directive[Opacity[0.4, Black], Dashed], Epilog -> {Text[Style[MaTeX["\\lambda_S = -1"], FontFamily -> font, FontSize -> fontsize], {15, 60}],Text[Style[MaTeX["\\lambda_S = 1"], FontFamily -> font, FontSize -> fontsize], {47, 25}]}, FrameLabel ->Rotate[MaTeX[" S=\\quad", FontSize -> 15], -90 Degree]];


Combine them using GraphicsRow:

p3 = GraphicsRow[{p1, p2}]:
`

and export the p3. If you want to reduce the distance of "$$S=$$" to the MatrixPlot simply delete the $$quad$$ spacing.