Tikz:花括号位置不正确

Tikz:花括号位置不正确

我正在尝试在某些节点的右侧绘制一个花括号。它目前出现在完全不同的节点的左侧。

这是我的代码:

\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}

我得到的图片是:

支架放置不正确

我做错了什么?我以为使用 .south 和 .north 符号可以定位到正确的节点。

答案1

我会做这样的事情:

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

产生

调整花括号

完整代码(已更新以避免使用弃用的语法并删除不需要的库):

\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}

相关内容