2

I'm trying to draw a curly brace to the right of some nodes. It is currently appearing to the left of a completely different node.

Here is my code:

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc,decorations.pathreplacing}
\begin{document}
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{brace} = [decorate]
\tikzstyle{bracenode} = [midway, right=2pt, rotate=90, anchor=north]

\begin{tikzpicture}[node distance = 3cm, auto]
    \node [block, label=left:1st Stroke] (recognise) {Recognise};
    \node [block, right of=recognise] (anchor) {Anchor};
    \node [block, right of=anchor] (store) {Store};   
    \node [text width=5em, below of=recognise, node distance = 3cm, label=left:2nd Stroke] (recognise2) {};
    \node [block, right of=recognise2] (group2) {Group};
    \node [block, right of=group2] (store2) {Store};

    \path [line] (recognise) -- (anchor);
    \path [line] (anchor) -- (store);
    \path [line, dashed] (store) to [out=270,in=90] (group2);
    \path [line] (group2) -- (store2);

    \draw[brace, decoration={brace}] let \p1=(store.north), \p2=(store2.south) in
        ($(2, \y1)$) -- ($(2, \y2)$) node[bracenode] {1st Annotation};
\end{tikzpicture}
\end{document}

The picture I get is:

Incorrectly positioned brace

What am I doing wrong? I thought using the .south and .north notation would position to the correct node.

1
  • You're placing the top and bottom of your bracket at x=2 which is not sensitive to the location of the nodes at all. It is easier to place the bracket relative to the nodes in question.
    – cfr
    Apr 27, 2016 at 2:18

1 Answer 1

2

I would do something like this:

\draw [brace] (store.north east) ++(5pt,0) coordinate (s) -- (store2.south east -| s)  node [bracenode] {1st Annotation};

which produces

adjusted curly bracket

Complete code (updated to avoid deprecated syntax and to remove unneeded library):

\documentclass[border=10pt,tikz,multi]{standalone}
\usetikzlibrary{arrows.meta,positioning,decorations.pathreplacing}
\begin{document}
\tikzset{% \tikzstyle is deprecated
  block/.style={rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em},
  line/.style={draw, -LaTeX},
  brace/.style={decorate, decoration={brace}},
  bracenode/.style={midway, right=2pt, rotate=90, anchor=north},
}
\begin{tikzpicture}[node distance = 2cm, auto]
  \node [block, label=left:1st Stroke] (recognise) {Recognise};
  \node [block, right=of recognise] (anchor) {Anchor};
  \node [block, right=of anchor] (store) {Store};
  \node [text width=5em, below=of recognise, node distance = 3cm, label=left:2nd Stroke] (recognise2) {};
  \node [block, right=of recognise2] (group2) {Group};
  \node [block, right=of group2] (store2) {Store};

  \path [line] (recognise) -- (anchor);
  \path [line] (anchor) -- (store);
  \path [line, dashed] (store) to [out=270,in=90] (group2);
  \path [line] (group2) -- (store2);

  \draw [brace] (store.north east) ++(5pt,0) coordinate (s) -- (store2.south east -| s)  node [bracenode] {1st Annotation};
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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