I am using tikz to typeset a diagram in a latex document.
I have a grid of 'grid-diagrams', with each grid-diagram drawn as a separate tikz picture and then arranged into the grid as nodes.
I want to draw a circle node (which will eventually contain a label) in the bottom-right hand square of each grid-diagram.
I use exactly the same code for each grid-diagram, but the circle is drawn in a different place each time.
Am I doing something wrong, or is this a bug in tikz? In particular, is my approach of including sub-pictures allowed/standard/good practice?
See here for an image.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\begin{document}
\begin{tikzpicture}[scale=1, node distance = .5cm]
\node (a) at (0,0) {
\begin{tikzpicture}
\draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
\node at (1.25, -1.25) [fill=white, shape=circle, draw=black] {};
\end{tikzpicture}
};
\node[right=of a] (b) {
\begin{tikzpicture}
\draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
\node at (1.25, -1.25) [fill=white, shape=circle, draw=black] {};
\end{tikzpicture}
};
\node[below=of a] (c) {
\begin{tikzpicture}
\draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
\node at (1.25, -1.25) [fill=white, shape=circle, draw=black] {};
\end{tikzpicture}
};
\node[right=of b] (d){
\begin{tikzpicture}
\draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
\node at (1.2, -1.5) [fill=white, shape=circle, draw=black] {};
\end{tikzpicture}
};
\node[below=of b] (e){
\begin{tikzpicture}
\draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
\node at (1.25, -1.25) [fill=white, shape=circle, draw=black] {};
\end{tikzpicture}
};
\node[below = of c] (f) {
\begin{tikzpicture}
\draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
\node at (1.25, -1.25) [fill=white, shape=circle, draw=black] {};
\end{tikzpicture}
};
\end{tikzpicture}
\end{document}
I am not sure why the circles are not aligned in your example, but it may have to do with the relative positioning using of
.
I don't know if this is a best practice, but you can use foreach
to automate the grid construction:
\begin{document}
\begin{tikzpicture}[scale=1]
\foreach \x in {-0.01cm,2.99cm,5.99cm}
\foreach \y in {-0.01cm,2.99cm,5.99cm} {
\draw[step=.5cm,gray,thin] (\x,\y) grid +(1.52cm,1.52cm);
\draw[fill=white, draw=black] (\x,\y) +(1.255cm,0.25cm) circle (0.2cm);
}
\end{tikzpicture}
\end{document}