Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to create a formula or figure like this: boxed entries in matrices

I tried it simply with the pmatrix environment and the \boxed command, but the spacing looked horrible. I think it might be done with TikZ, but I don't know much about it.

Edit:

Here is what I got so far for the right-hand side:

\documentclass{article}

\usepackage{amsmath,amsthm,amsfonts,amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows,matrix,positioning}

\begin{document}
\begin{tikzpicture}
    \matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m)
    {
           A_1           & \phantom{A_1} & \phantom{A_1} & \\
           \phantom{A_1} & \phantom{A_1} &               & \\
           \phantom{A_1} &               & A_2           & \\
                         &               &               & A_2           & \phantom{A_3}\\
                         &               &               & \phantom{A_2} & A_3          \\
    };  
    \draw (m-1-1.north west) -- (m-1-2.north east) -- (m-2-2.south east) -- (m-2-1.south west) -- (m-1-1.north west);
    \draw (m-3-3.north west) -- (m-3-3.north east) -- (m-3-3.south east) -- (m-3-3.south west) -- (m-3-3.north west);
    \draw (m-4-4.north west) -- (m-4-4.north east) -- (m-4-4.south east) -- (m-4-4.south west) -- (m-4-4.north west);
    \draw (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
    \draw (m-5-5.north west) -- (m-5-5.north east) -- (m-5-5.south east) -- (m-5-5.south west) -- (m-5-5.north west);
    \draw (m-4-4.north west) -- (m-4-5.north east) -- (m-5-5.south east) -- (m-5-4.south west) -- (m-4-4.north west);
\end{tikzpicture}

\end{document}

enter image description here

What I hope to achieve is

  • square boxes,
  • $A_1$ centered in the $2\times 2$ box,
  • also the left-hand side and the $\subset$ sign in the middle.

Comment: I have no idea what I did wrong in the formatting of this question.

share|improve this question
4  
See Highlight elements in the matrix –  Werner Apr 3 '13 at 19:59
    
do you also have an idea how to center $A_1$ in a $2\times 2$ matrix? –  Peter Patzt Apr 3 '13 at 20:05
    
Yes, see Combine 4 cells in a table where you can use a combination of \multicolumn and \multirow. –  Werner Apr 3 '13 at 20:12
    
Welcome to TeX.sx! –  Peter Jansson Apr 3 '13 at 20:16
    
are you sure, that \multirow works in tikz? It throws Error: Undefined control sequence. @Peter Jansson: sorry for the discussion, but I'd like to make it work. –  Peter Patzt Apr 3 '13 at 20:22

2 Answers 2

up vote 7 down vote accepted

A TikZ solution:

\documentclass{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{matrix}

\begin{document}
\[
\begin{tikzpicture}[baseline=(current bounding box.center)]%
\matrix[matrix of math nodes,
inner sep=0,
nodes={draw,outer sep=0,inner sep=2pt},
every left delimiter/.style={xshift=1ex},%tighter delimiter spacing
every right delimiter/.style={xshift=-1ex},
left delimiter={(},right delimiter={)},
column sep=-\pgflinewidth,row sep=-\pgflinewidth] (r) {
|[inner sep=5mm]|A_1&&\\
&A_2&\\
&&A_3\\
};
\end{tikzpicture}
\subset
\begin{tikzpicture}[baseline=(current bounding box.center)]%
\matrix[matrix of math nodes,
inner sep=0,
nodes={draw,outer sep=0,inner sep=2pt},
every left delimiter/.style={xshift=1ex},%tighter delimiter spacing
every right delimiter/.style={xshift=-1ex},
left delimiter={(},right delimiter={)},
column sep=-\pgflinewidth,row sep=-\pgflinewidth] (l) {
|[inner sep=5mm]|A_1&&&\\
&A_2&&\\
&&A_2&\\
&&&A_3\\
};
\draw (l-2-2.north east) |- (l-1-1.north east) (l-2-2.south west) -| (l-1-1.south west)
      (l-3-3.north east) -| (l-4-4.north east) (l-3-3.south west) |- (l-4-4.south west);
\end{tikzpicture}
\]
\end{document}

enter image description here

share|improve this answer
    
WOW ... that looks awesome! Thanks a lot! –  Peter Patzt Apr 3 '13 at 20:54
    
@PeterPatzt My pleasure –  percusse Apr 3 '13 at 20:56

A TikZ-free solution, using the easybmat package:

\documentclass{article}
\usepackage{amsmath}
\usepackage{easybmat}

\begin{document}

\[ 
\left(
\begin{array}{c@{}c@{}c}
\begin{BMAT}{|ccc|}{|ccc|}
& & \\
& \mbox{\LARGE$A_1$} & \\
& &  
\end{BMAT} & & \\
&
\begin{BMAT}{|c|}{|c|}
A_2 
\end{BMAT} & \\
& &
\begin{BMAT}{|c|}{|c|}
A_3 
\end{BMAT}
\end{array}
\right)
\subset
\left(
\begin{array}{c@{}c@{}c}
\begin{BMAT}{|ccc|c|}{|ccc|c|}
& & & \\
& \mbox{\LARGE$A_1$} & & \\
& &  & \\
& & & A_2
\end{BMAT} & & \\
&
\begin{BMAT}{|c|c|}{|c|c|}
A_2 & \\
& A_3
\end{BMAT}
\end{array}
\right)
\]

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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