# Is there any way to get something like pmatrix with customizable grid lines between cells? [duplicate]

In the document I have to describe a series of transformations, made with a matrix. Each transformation works only on 2x2 or 1x1 block, so I want to visually select this block in the matrix like this:

I can type the matrix using the pmatrix environment, but I don't know, how to draw the rectangle. What is the best way to achieve this?

## marked as duplicate by Werner, egreg, Svend Tveskæg, mafp, Martin SchröderFeb 12 '14 at 22:16

• Perhaps the following is helpful/sufficient/duplicate: Highlight elements in the matrix – Werner Feb 12 '14 at 20:32
• @Werner, the link you provided was indeed very helpful. I managed to edit the code, provided in the question you linked to do what I wanted. For the sake of reference I wrote thus obtained code in the answer below. Thank you. – fiktor Feb 12 '14 at 21:44

My question was indeed close to duplicate as was hinted by @Werner . For the sake of reference I provide the code, which draws what I wanted. The code was created after analyzing the answer, linked by @Werner.

\begin{tikzpicture}[baseline=(current bounding box.center)]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m)
{
\!1 & 0 & 0\!\!\! \\ \!0 & {P_\theta \otimes P} & 0\!\!\! \\ \!0 & 0 & 0\!\!\! \\
};
\draw (m-1-1.north west) -- (m-1-3.north west) -- (m-3-3.north west) -- (m-3-1.north west) -- (m-1-1.north west);
\end{tikzpicture}


The following code should be included in the preamble.

\usepackage{tikz}
\usetikzlibrary{arrows,matrix,positioning}


This gives the following.