[Tex/LaTex] coordinate along decorated path

pgf-decorationstikz-pgf

I'm using the brace decoration from the TikZ decorations.pathreplacing library to draw a brace around some nodes.
Now I would like to connect the tip of the brace to another path (use case: labelling terms in an equation).
First, I used the LaTeX command \overbrace, but realised it would be difficult to connect a tikz-path to the tip.
It should be easier using the TikZ decoration brace.
However, if I place node[midway] along the path, the node is placed midway along the unaltered path, not midway along the decorated path.
Below is code along with the undesired output.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\node (spam) at (1, 1) {Spam};
\node (eggs) at (4, 1) {Eggs};
\draw[decoration={brace,amplitude=5mm}, decorate] (spam.north) -- (eggs.north) coordinate[midway] (mid);
\draw (mid) -- ++(0,1);
\end{tikzpicture}
\end{document}

Second path not connected properly

Of course, in the present example, I could simply replace the second \draw-command by \draw (mid) ++(0,5mm) -- ++(0,1);.
But I would like something more stable that I don't need to tweak by hand, and maybe even work for arbitrary decorated paths.

So, my question is:

  • How do I place a coordinate at some point along a decorated path?

UPDATE 2012-12-17: To show the use case, I add a picture of the solution here.

enter image description here

Best Answer

This is a funny one! :)

You can accomplish this by realizing that the decoration is a path in itself.

What you just then need to do is access that path!

You can do this by applying a postaction on the path and decorate it again!

But as the decoration is in a separate key directory you need to explicitly tell to use /tikz/postaction. You can then access any coordinate however you wish, i choose to use the decoration library markings.

So here it is:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepgflibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
  \node (spam) at (1, 1) {Spam};
  \node (eggs) at (4, 1) {Eggs};
  \node (bacon) at (4, 3) {Bacon};
  \draw[decoration={brace,amplitude=5mm}, decorate] (spam.north) -- (eggs.north) coordinate[midway] (mid);
  \draw (mid) -- ++(0,1);
  \draw[decoration={brace,amplitude=5mm,
      /tikz/postaction={
          decoration={
              markings,
              mark=at position 0.45 with \coordinate (Mb);,
              mark=at position 0.5 with \coordinate (M);,
              mark=at position 0.55 with \coordinate (Ma);
          },decorate
      }
  },decorate] (spam.north) -- (bacon.north);
  \draw[red] (Mb) circle (2pt);
  \draw[blue] (M) circle (2pt);
  \draw[green] (Ma) circle (2pt);
\end{tikzpicture}
\end{document}

An the output becomes: output of tex