1
$\begingroup$

I'd like to be able to display matrices in the usual written MatrixForm in a table alongside text (or anything that isn't a matrix). Here is an example:

Clear[a, b, c, α, β, γ]; 
g = {{a^2, a*b*Cos[γ], a*c*Cos[β]}, {b*a*Cos[γ], b^2, b*c*Cos[α]}, {c*a*Cos[β], c*b*Cos[α], c^2}}; MatrixForm[g]
Clear[a, b, c, α, β, γ]; 
c = b = a; γ = β = α = 90*(Pi/180); g1…cubic = g; 
Clear[a, b, c, α, β, γ]; 
b = a; γ = β = α = 90*(Pi/180); g2…tetragonal = g; 
Clear[a, b, c, α, β, γ]; 
γ = β = α = 90*(Pi/180); g3…orthorhombic = g; 
Clear[a, b, c, α, β, γ]; 
b = a; β = α = 90*(Pi/180); γ = 120*(Pi/180); g4…hexagonal = g; 
Clear[a, b, c, α, β, γ]; 
γ = α = 90*(Pi/180); g5…monoclinic = g; 
Clear[a, b, c, α, β, γ]; 
c = b = a; γ = β = α; g6…rhombohedral = g; 
Clear[a, b, c, α, β, γ]; 
g7…triclinic = g; 
crystalsystemnames = {"Cubic", "Tetragonal", "Orthorhombic", "Hexagonal", "Monoclinic", "Rhombohedral", "Triclinic"}; 
metrictensors = Partition[{g1…cubic, g2…tetragonal, g3…orthorhombic, g4…hexagonal, g5…monoclinic, g6…rhombohedral, g7…triclinic}, 
    1]; 
data = MapThread[Append, {metrictensors, crystalsystemnames}]; 
MatrixForm[data, TableHeadings -> {None, {"Metric Tensor"}}]

This nearly produces the desired result, but the matrices within the table aren't displayed in Matrix Form:

enter image description here

This sounds like an easy fix, by just using MatrixForm earlier.

MatrixForm[metrictensors]

enter image description here

However, combining these methods doesn't work. This produces a MapThread error:

data = MapThread[Append, {MatrixForm[metrictensors], crystalsystemnames}]

I can display the matrices horizontally after which MapThread no longer computes:

Apply[MatrixForm, metrictensors, {1}]

ref/MatrixForm and ref/TableForm don't seem to have a combination example. Is there a way to do this?

$\endgroup$
1
  • 3
    $\begingroup$ A simple approach is to use TraditionalForm, e.g., MatrixForm[data, TableHeadings -> {None, {"Metric Tensor"}}] //TraditionalForm $\endgroup$
    – Carl Woll
    Sep 18 at 0:58
3
$\begingroup$
crystalsystemnames = {"Cubic", "Tetragonal", "Orthorhombic", 
   "Hexagonal", "Monoclinic", "Rhombohedral", "Triclinic"};

metrictensors = Partition[{g1, g2, g3, g4, g5, g6, g7}, 1];

data = MapThread[Append, {metrictensors, crystalsystemnames}];

MatrixForm[MapAt[MatrixForm, data, {All, 1}], TableHeadings -> {None, {"Metric Tensor"}}]

enter image description here

Alternatively,

data2 = MapThread[Append[{MatrixForm @ #}, #2] &, 
 {{g1, g2, g3, g4, g5, g6, g7}, crystalsystemnames}];

MatrixForm[data2, TableHeadings -> {None, {"Metric Tensor"}}]
same picture

Note: I replaced gi...stuff with gi in your code.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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