# a divided rectangle in tikz

I am trying to draw the following using tikz, but I don't even know where and how to begin. Any assistance would be much appreciated.

-
You should start by looking at the examples at the beginning of the TikZ/pgf manual. These should give you enough clues to start out. You'll learn a lot more that way than you will just copy/pasting Altermundus' code. – Seamus Jul 13 '12 at 14:34
Did that before posting -- as I always do, and try to post at least a partial solution I came up with. This time, I was stumped, hence the more general question. I don't also cut-and-paste the code, but study it to understand what is going on and why and what can be generalized for future use. – ozsu Jul 13 '12 at 16:01
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count. This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). – N3buchadnezzar Jul 14 '12 at 17:16

Update It's possible to calculate the position of the nodes directly with \n with

 \foreach \n in {1,...,4}{%
\node [draw,circle,ultra thick,red,num,
minimum width=1.5 cm,fill=white] at
({2+4*mod(\n+1,2)},{2+(3-\n)*(4-\n)*(4*\n-2)/3}) {\n};


I didn't try to find something perhaps more simpler.

 \documentclass[11pt]{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[num/.style={font=\Huge\bfseries\ttfamily}]
\draw[ultra thick,red] (0,0) rectangle (8,8)
(4,0) -- (4,8)
(0,4) -- (8,4);
\draw [gray,thick] (2,0) -- (2,8)
(6,0) -- (6,8)
(0,2) -- (8,2)
(0,6) -- (8,6);
\foreach \n/\x/\y in {1/2/6,2/6/6,3/2/2,4/6/2}{%
\node [draw,circle,ultra thick,red,num,
minimum width=1.5 cm,fill=white] at (\x,\y) { \n};
\node[num] at (\n*2-1,8.5) {\n};
\node[num] at (-0.5,9-\n*2) {\n};
}
\node[num] at (-0.5,8){R};
\node[num] at (0.5,8.5){S} ;
\end{tikzpicture}
\end{document}


Another possibility like N3buchadnezzar wrote in a comment is to use grid, the code is reduced and with the update the code is only this :

 \documentclass[11pt]{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[num/.style={font=\Huge\bfseries\ttfamily}]
\draw [gray,thick,step=2cm] (0,0) grid (8,8);
\draw[ultra thick,red,step=4cm] (0,0) grid (8,8);
\foreach \n in {1,...,4}{%
\node [draw,circle,ultra thick,red,num,
minimum width=1.5 cm,fill=white] at
({2+4*mod(\n+1,2)},{2+(3-\n)*(4-\n)*(4*\n-2)/3}) { \n};
\node[num] at (\n*2-1,8.5) {\n};
\node[num] at (-0.5,9-\n*2) {\n};}
\node[num] at (-0.5,8){R};
\node[num] at (0.5,8.5){S} ;
\end{tikzpicture}
\end{document}

-
Thank you -- much appreciated. I learn a great deal at this site. – ozsu Jul 13 '12 at 14:09
Why not use \draw Grid ? and nice solution, mine is similar. – N3buchadnezzar Jul 13 '12 at 14:41
It will be interesting to know if you want to scale the picture or to adapt the size. The method to reach the result can be different. – Alain Matthes Jul 13 '12 at 14:44
@N3buchadnezzar Yes it's possible but not necessary. It was to avoid some superpositions (overlays) but If you want to use grid then we can use two grids. The use of layers like Claudio is interesting. – Alain Matthes Jul 13 '12 at 14:54

Here is an approach that takes care of shading both rectangles and circles since in the reference picture they seem to be shaded.

\documentclass[a4paper]{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\foreach \pos [count=\i] in {{(0,0)},{(2,0)},{(0,-2)},{(2,-2)}}{%
\node[draw=red,thick,minimum size=2cm] (z\i) at \pos {};
\node[top color=white, bottom color=gray!15,draw=red,thick,circle,minimum size=3pt]at \pos {\i};
}

\begin{pgfonlayer}{background}
\foreach \x in {1,...,4}{
\shade[top color=white, bottom color=gray!15] (z\x.north west)--(z\x.north)--(z\x.center)--(z\x.west);
\shade[top color=white, bottom color=gray!15] (z\x.north)--(z\x.north east)--(z\x.east)--(z\x.center);
\shade[top color=white, bottom color=gray!15] (z\x.south west)--(z\x.south)--(z\x.center)--(z\x.west);
\shade[top color=white, bottom color=gray!15] (z\x.south)--(z\x.south east)--(z\x.east)--(z\x.center);
% connection lines
\draw[thin,gray](z\x.north)--(z\x.south);
\draw[thin,gray](z\x.west)--(z\x.east);
}
\end{pgfonlayer}

% annotations
\foreach \c [count=\i] in {-0.5,0.5,1.5,2.5}{
\node at (\c,1.25){\i};
}
\node at (-0.75,1.25){S};

\foreach \c [count=\i] in {0.5,-0.5,-1.5,-2.5}{
\node at (-1.25,\c){\i};
}
\node at (-1.25,0.9){R};
\end{tikzpicture}

\end{document}


Result:

-