0

I have a graph with some nodes, which I want to repeat over multiple drawings. The placement of the nodes should be the same for every drawings, but I want to vary which edges are drawn, and which nodes are actually shown or hidden.

Currently I have something like

        \node (a) at (0,0) {$æA$};
        \node (b) at (2.5,0) {$æB$};
        \node (c) at (1,-2) {$æC$};
        \node (d) at (2.2,-2.5) {$æD$};

repeated in the beginning of every drawing. But if I want to change the layout, I have to update this code everywhere.

Now I could write a macro for this case. But I'm interested, whether I could make this a style to apply to the drawing.

1 Answer 1

3

I found the following solution. It does not define the coordinates, which would also be useful, but it provides the position via a style.

First define the style that sets the positions using at:

\tikzset{
  layout/.style={
    a/.style={at={(0,0)}},
    b/.style={at={(2.5,0)}},
    c/.style={at={(1,-2)}},
    d/.style={at={(2.2,-2.5)}}
  }
}

And then for each figure:

\begin{tikzpicture}[layout]{
  \node[a] (a) {A};
  \node[b] (b) {B};
  \node[c] (c) {C};
  \node[d] (d) {D};
}

If I want to hide a node, I change \node[a] (a) {}; to \coordinate[a] (a);.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .