[Tex/LaTex] how to use fbox in align mode

boxesmath-mode

I'm trying to highlight the diagonal elements of a matrix by using fbox but I failed. I've searched for the problem, some ppl suggest using tikz. I don't want to use it, so I decided to use fbox{}. Every time I do the following

\documentclass[a4paper, 12pt]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\begin{document}
\begin{align}
   \begin{bmatrix}
       \sigma_{xx} & \sigma_{yx}        \\
       \sigma_{xy} & \fbox{\sigma_{yy}} \\
   \end{bmatrix}
\end{align}
\end{document}

it throws an error !Argument of \align has an extra}
if I remove \sigma_{}, it works. Any suggestions?

Best Answer

\fbox sets its argument in text mode, and \sigma as well as the subscript requires math mode. So, use \fbox{$\sigma_{yy}$} or the \boxed version supplied by amsmath:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[\begin{bmatrix}
  \boxed{\sigma_{xx}} & \sigma_{yx}          \\
  \sigma_{xy}         & \fbox{$\sigma_{yy}$}
\end{bmatrix}\]
\end{document}

Also, there's no need for align here, and I'd rather use an equation (if you want it numbered) or \[...\] if not.