# Matrix with rows and columns labeled with equations

I want to label the rows and columns with quantum states as $\ket{n_1l_1m_1}$. To save space I tried to rotate these states by using

\rotatebox{80}{\ket{n_1l_1m_1}}

but this is not possible - how can I rotate math equations?

To make it more clear I want to replace the H (and also the Y and D) in the image by 90 degree rotatet quantum ket states

• What you want is not very clear. Could you post a sketch? Oct 1, 2020 at 22:15
• Maybe I can solve ma problem when I know how to rotate math equations? Oct 1, 2020 at 22:26
• as for any box, reenter math \rotatebox{80}{$\ket{n_1l_1m_1}$} Oct 1, 2020 at 22:37
• if you tried, you would have seen thats not working Oct 2, 2020 at 9:22

With nicematrix:

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$\begin{pNiceMatrix}[first-row,first-col,code-for-first-row=\rotate] & |n_1l_1m_1\rangle& |n_1l_1m_1\rangle& |n_1l_1m_1\rangle\\ |n_1l_1m_1\rangle & 0.8 & 0.2 & 0 \\ |n_1l_1m_1\rangle& 0.3 & 0.4 & 0.3 \\ |n_1l_1m_1\rangle& 0.2 & 0.1 & 0.7 \end{pNiceMatrix}$

\end{document}


By default, Overleaf uses an old version of nicematrix. However, you can provide it the newest version of nicematrix.sty. Go here. At the top of the page, you have the latest version of nicematrix. It's the revision 56256. You do a right click on download and you save the file under the name nicematrix.sty. Put that file next to your file in your Overleaf project (buttom import next to new file).

• Undefined control sequence. is the error Oct 2, 2020 at 9:27
• Maybe you don't have the latest version of nicematrix. You should update your TeX installation. Oct 2, 2020 at 10:50
• I am using overleaf Oct 2, 2020 at 11:42
• I have edited my answer. Oct 2, 2020 at 14:34
• @F.Pantigny While you are at it: What about giving \rotate an option to set an angle for the rotation? I'm asking something and have no clue, whether it would be more or less easy to implement. So maybe you better ignore this comment. Oct 2, 2020 at 16:32

Another alternative could be using blkarray with a combination of braket packages to define the command \ket and the graphicx package to use the rotation of \ket{n_1l_1m_1} with the macro \def\rotbra#1{\rotatebox{90}{$#1$}}.

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{blkarray}
\usepackage{braket}
\usepackage{graphicx}
\def\rotbra#1{\rotatebox{90}{$#1$}}

\begin{document}

$\begin{blockarray}{cccc} & \rotbra{\ket{n_1l_1m_1}} & \rotbra{\ket{n_1l_1m_1}} & \rotbra{\ket{n_1l_1m_1}}\\ \begin{block}{c(ccc)} \ket{n_1l_1m_1} & .8 & .2 & 0 &\\ \ket{n_1l_1m_1} & .3 & .4 & .3 &\\ \ket{n_1l_1m_1} & .2 & .1 & .7 &\\ \end{block} \end{blockarray}$
\end{document}


This is the output of the code: