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}
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.
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 librarymarkings
.So here it is:
An the output becomes: