# How to make frame in matrix? [duplicate]

I want to draw :

I have tried to make this by the following command :

\documentclass[11pt,twoside,openright]{book}
\usepackage{geometry,tikz,amsmath}

\begin{document}

$$J_5=\left(\begin{array}{ccc} \lambda & 1 & 0\\ 0 & \lambda & 0\\ 0 & 0 & \frame{\lambda} \end{array}\right)$$

\end{document}


But this gives :

How can I do so ?

-

## marked as duplicate by Werner, diabonas, Claudio Fiandrino, mafp, Marco DanielApr 26 '13 at 18:03

Since the "what you want" picture is not there, I can only guess. Do you want a \fbox instead of a \frame – Steven B. Segletes Apr 26 '13 at 16:10
I want to make the matrix shown in the first picture.How can I use \fbox.Plese give an example with array. – Md Kutubuddin Sardar Apr 26 '13 at 16:12
Sorry to bother you, but I just noticed that even though you have up-voted answers, you still haven't accepted any of the answers to your questions (up-voting and accepting are two different actions). Please consider revisiting your questions and accepting, for each of them, the answer that you consider best solved your problem. In case of doubt, please see How do you accept an answer?. – Gonzalo Medina Apr 26 '13 at 16:23
– Papiro Apr 26 '13 at 16:31
I had in mind literally replacing the \frame with a \fbox. That will frame a single entry with a border that frame did not provide, but is not directly usable when multi-element blocks of the array are to be framed. – Steven B. Segletes Apr 26 '13 at 16:33

Since you are loading tikz, I assume a tikz solution is fine.

It makes use of two tikz libraries: matrix for the matrix (the syntax is very close to the usual syntax for tabulars, arrays or matrices, with a lot of optional parameters to tweak the final output), and fit to draw rectangles around sets of nodes.

\documentclass[11pt,twoside,openright]{book}
\usepackage{geometry,tikz,amsmath}

\usetikzlibrary{fit,matrix}

\begin{document}

\begin{equation*}
J_{5}=
\tikz[baseline=(M.west)]{%
\node[matrix of math nodes,matrix anchor=west,left delimiter=(,right delimiter=),ampersand replacement=\&] (M) {%
\lambda \& 1 \& 0 \\
0 \& \lambda \& 0 \\
0 \& 0 \& \lambda \\
};
\node[draw,fit=(M-1-1)(M-2-2),inner sep=-1pt] {};
\node[draw,fit=(M-3-3),inner sep=-1pt] {};
}
\end{equation*}

\end{document}


-

A TikZ-free possibility:

\documentclass[11pt,twoside,openright]{book}
\usepackage{amsmath}

\begin{document}

$J_5= \left( \begin{array}{|cc|c@{}c|} \cline{1-2} \lambda & 1 & & \multicolumn{1}{c}{0} \\ 0 & \multicolumn{1}{c|}{\lambda} & & \multicolumn{1}{c}{0} \\ \cline{1-2}\cline{4-4} \multicolumn{1}{c}{0} & \multicolumn{1}{c}{0} & & \multicolumn{1}{|c|}{\lambda} \\ \cline{4-4} \end{array} \right)$

\end{document}


-
+1 for a solution that doesn't require too many packages and that should work on any latex install. The drawbacks appear when you notice that you have accidentally swapped the big and small rectangles, though. ;) – T. Verron Apr 26 '13 at 16:24
@T.Verron hehe! Fixed. – Gonzalo Medina Apr 26 '13 at 16:31