I'm trying to align 2 groups of TikZ nodes but cannot figure out how to do this. I tried wrapping each group with \tikz{...}
but that didn't work (probably because of \tikz inside tikzpicture environment. Currently, I am using \matrix
but it aligns the nodes horizontally at the left (and I would like center) and doesn't use equal spacing between lines (or maybe, it does, but I would like it to change to a minimum spacing?)
Anyway, I have a feeling that my goal could be accomplished with \matrix
but I am open to other approaches to group nodes, too. For example, I haven't fully understood the {scope}
environment.
Here is my MWE illustrating the problem (I'd be also happy to hear if the MWE could be made more minimal, i.e., my tikz coding could be improved):
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}
% some style definitions:
\newcommand\scriptsize{\fontsize{7pt}{7pt}\selectfont} % because of 'minimal' documentclass
% settings for lexemes
\tikzset{font=\scriptsize}
\tikzset{mynode/.style = {rectangle,minimum width=#1,draw=black!70}}
\tikzset{mynode/.default = 2mm}
% macro for drawing multiple lexemes next to each other:
\newcommand{\lexemes}[1]{%
\node (A) [mynode] {};
\xdef\lastx{A}
\foreach \x/\lbl/\d in {#1} {
\node (\x) [mynode,label=center:\lbl,right=\d of \lastx] {};
\xdef\lastx{\x}
}
}
\begin{document}
\begin{tikzpicture}[node distance=0.08 and 0.05]
\matrix [anchor=west] at (0,3) {% no labels, so rows very tight
\lexemes{C//} \\
\lexemes{C//,D//2mm,F//} \\
};
\matrix [anchor=west] at (0,2) {% label in upper row, so less tight
\lexemes{B/1/,C//} \\
\lexemes{C//,D//2mm,F//} \\
};
\matrix [anchor=west] at (0,1) {% labels in both rows, so this should be the constant row sep?
\lexemes{B/1/,C//} \\
\lexemes{B/3/,C//,D//2mm,F//} \\
};
\end{tikzpicture}
\end{document}
which produces the following result:
Now I would like to accomplish 2 things:
- Center the first and second row of each pair/matrix.
- Have an equal vertical separation between the first and second row of each matrix independent of the node label used. I would measure between the edges of the rectangles.
scope
: its purpose is to locally set TikZ options. That's it. So for example, you could have ascope
setting, say,shift = {(1,0)}
to move everything right one unit, but it is (I think) much harder to arrange purely through options that the center of a scope is at a particular place.