Saturday, 8 June 2013

tikz matrix align/decorate cellpictures

I have a matrix of cell pictures, and want the first column to be right aligned and the second column to be left aligned. However I have trouble using the "nodes" key.
example
\documentclass{article}
\usepackage{tikz}
\usepackage[margin=0cm,nohead]{geometry}
\usepackage[active,tightpage]{preview}

\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{matrix}

\PreviewEnvironment{tikzpicture}
\begin{document}

 \begin{tikzpicture}[very thick]
    \matrix[matrix of nodes, column sep=3ex, row sep=2ex, nodes={draw}]{
            \draw (0,0) rectangle (-2.5,1) rectangle ++ (2.5,1) rectangle ++ (-2.5,1) rectangle ++ (2.5,1);
            \draw (2,2) rectangle ++ (2.5, 1) rectangle ++ (-2.5, 1);

            \draw[thin, gray] (0,0) -- (2,2)  (0,2) -- (2,3) (0,4) -- (2,4);   
        &
            \draw (0,0) rectangle (2.5,1) rectangle ++ (-2.5,1) rectangle ++ (2.5,1) rectangle ++ (-2.5,1);
            \draw (-2,2) rectangle ++ (-2.5, 1) rectangle ++ (2.5, 1);

            \draw[thin, gray] (0,0) -- (-2,2)  (0,2) -- (-2,3) (0,4) -- (-2,4);

            \begin{scope}[-latex, shorten >=5pt, shorten <=8pt]
                \draw (-2, 2.4) -- (0, 0.5);
                \draw (-2, 2.6) -- (0, 1.5);

                \draw (-2, 3.4) -- (0, 2.5);
                \draw (-2, 3.6) -- (0, 3.5);
            \end{scope}

            \node at (-1.25,1.95) [red]{\Huge\bfseries{?}};
            \node at (-1.25,3.32) [red]{\Huge\bfseries{?}};
        \\
    };
 \end{tikzpicture}
 \end{document}
With this example I would expect to see bounding boxes arround the cells, however it only modifies the nodes inside the cells. I would like the frames to see the changes I make, once I actually add column 1={anchor=east}, column 2={anschor=west}. Note that for shortness this example only has one row, however the actual matrix has several rows.
As a further perk I would like to add a label in the top left and bottom center of the cell. therefor it would be great to get those positions from the cell, since the actual cellpicture might be smaller.
This can be seen in this example from the tikz manual, page 204:
\begin{tikzpicture}[every node/.style={draw}]
\matrix [draw=red]
{
\node[left] {Hallo}; \fill[blue] (0,0) circle (2pt); \\
\node {X}; \fill[blue] (0,0) circle (2pt); \\
\node[right] {g}; \fill[blue] (0,0) circle (2pt); \\
};
\end{tikzpicture}
the border of the nodes is clearly smaller then the width of the column.

No comments:

Post a Comment