Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

With minimal tikz knowledge, I try to create a node like shape, which has two filled circles in it. Here is my attempt, which suffers from these problems:

  • The appended path components seem to be covered by the main node.
  • Options passed to later path components are ignored.

MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,shapes.multipart}
\begin{document}
\tikzset{cell/.style={
  name=#1,
  draw,
  rectangle split,
  rectangle split parts=3,
  rectangle split horizontal=true,
    append after command={%
      coordinate (#1 one) at ($ (#1.east)!1/6!(#1.west)  $)
      coordinate (#1 two) at ($ (#1.east)!5/6!(#1.west)  $)
     [fill=red] (#1 one) circle (2pt)
     [fill=red] (#1 two) circle (2pt)
    },
}}

\begin{tikzpicture}
\node[cell=a,label=left:{missing circles}] at (0,-1) {};
\node[cell=b,above=1ex of a,label=left:{circles show, but not red}]  {} [draw];
\node[cell=c, above=1ex of b,label=left:{circle ignore style options}] {}  [fill=green];
\node[cell=d, above=1ex of c,label=left:{node hides circles},fill=blue!20] {}  [fill=green];
\end{tikzpicture}
\end{document}

The output of the above code

share|improve this question
1  
You might find some insights about these behaviours in How to modify nodes in TikZ to automatically add a line on their top? –  Claudio Fiandrino Jan 10 at 6:30

1 Answer 1

up vote 4 down vote accepted

This isn't a good way to define a new shape. Best is to define a proper new shape with \pgfdeclareshape. You can inherit various properties from a known shape. An alternative is to use the new (PGF-CVS) pic which is a simpler form of a shape and can be built from high-level TikZ commands rather than low-level PGF commands.

To illustrate this advice, let's examine why your code is producing what it does in each case. The keys are: order of drawing, and scoping. In particular:

  1. When a path has paths and nodes, the paths are rendered first and the nodes afterwards. Note that this is purely about rendering. They are computed as they occur on the path. It is just that the nodes are shipped off into a box which is put on top of the other path components.

  2. The stuff in the append after command is executed inside a group.

  3. Paths are treated uniformly with regard to drawing and filling. In particular, either all components are filled or none are filled, and all use the same colour. The actions and colours in place at the end of the path construction are those that will be used.

  4. Node paths are separate to the rest of the path and can be separately styled. The stuff in append after command is not part of the node, though, but part of the main path.

So:

  1. "Missing circles". The [fill=red] occurs inside a group and so isn't visible at the end of the path construction. It therefore has no effect. Even putting a fill command outside the group still means that the fill colour is not red as that is only set inside the group.

  2. "Show, but not red". As above, [fill=red] has no effect. But the [draw] sets the action to draw so they are drawn. As no colour is in effect, the default colour (black) is used.

  3. "Ignore style options". Same as the previous two. The [fill=green] is the only specification in effect by the end of the path.

  4. "Node hide circles". This is because nodes are rendered after the path, so they go on top.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.