TikZ 中水平支撑位于另一个支撑 + 节点上方

TikZ 中水平支撑位于另一个支撑 + 节点上方

在下面的 MWE 中,我在从句上方放置了一个括号that he knowsSubordinate clause括号上方有一个节点。现在我想在整个句子(主句)上方放置一个括号,括号上方有一个节点Main clause。如何将其放置在已经绘制的括号 + 节点上方?取消注释下面注释的代码时,新的括号将与已经存在的括号位于同一水平线上。

\documentclass{article}
\usepackage{tikz}
    \usetikzlibrary{decorations.pathreplacing}

\begin{document}

\tikz[baseline, remember picture] \node[inner sep = 0pt, anchor = base] (mainclause) {She said}; 
\tikz[baseline, remember picture] \node[inner sep = 0pt, anchor = base] (subclause) {that he knows}; 
    \begin{tikzpicture}[remember picture, overlay]
        \draw[decorate, decoration = brace] (subclause.north west) -- (subclause.north east)
            node [midway, above] {\footnotesize{Subordinate clause}};
%       \draw[decorate, decoration = brace] (mainclause.north west) -- (subclause.north east)
%           node [midway, above] {\footnotesize{Main clause}};
    \end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

如果您将包含文本的节点标记Subordinate clause为类似subclauselabel,那么您可以使用该intersections库来找到通过您选择的节点锚点的垂直线的交点(例如,垂直于mainclause.north west和水平于subclauselabel.north.west)。

\documentclass{article}
\usepackage{tikz}
    \usetikzlibrary{decorations.pathreplacing,intersections}

\begin{document}
\tikz[baseline, remember picture] \node[inner sep = 0pt, anchor = base] (mainclause) {She said}; 
\tikz[baseline, remember picture] \node[inner sep = 0pt, anchor = base] (subclause) {that he knows}; 
    \begin{tikzpicture}[remember picture, overlay]
        \draw[decorate, decoration ={brace,raise=1pt}] (subclause.north west) -- (subclause.north east)
            node (subclauselabel) [midway, above=1pt] {\footnotesize{Subordinate clause}};
       \draw[decorate, decoration = brace] (mainclause.north west |- subclauselabel.north west) -- (subclauselabel.north east)
           node [midway, above] {\footnotesize{Main clause}};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

我从来不喜欢用remember picture技巧overlay/临时方案/变通方法来获得这些效果。所以,我坚持使用text effects along path装饰...

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations.text,decorations.pathreplacing}
\tikzset{%
  text as nodes/.style args={#1}{
    decoration={text effects along path, 
      text={#1},
      text effects/.cd, 
        path from text, text along path,
        group letters, word count=\w,
        every word/.style={name=word-\w, inner ysep=0.125ex},
    },
    decorate,
    insert path={(0,0)}
  },
}
\begin{document}
\begin{tikzpicture}
% Create a sequence of nodes named word-1 to word-5
\path [text as nodes={She said that he knows}];

% Use the implicit perpendicular coordinate system:
\draw [decoration=brace, decorate] (word-3.west |- 0,0.5) -- (word-5.east |- 0,0.5)
   node [midway, above=.25ex, font=\footnotesize] {Subordinate clause};

\draw [decoration=brace, decorate] (word-1.west |- 0,1) -- (word-5.east |- 0,1)
    node [midway, above=.25ex, font=\footnotesize] {Main clause};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

您可以使用 Tikz 来实现这一点,方法是将其添加calc到库列表中并修改 Y 轴的括号坐标(您可以使用任何距离方法:厘米、点等)。下面是单个坐标的示例:

($(mainclause.north west) + (0,12pt)$)

在此处输入图片描述

\documentclass[margin=60pt]{standalone}

\usepackage{tikz}
    \usetikzlibrary{decorations.pathreplacing, calc}

\begin{document}

\tikz[baseline, remember picture] \node[inner sep = 0pt, anchor = base] (mainclause) {She said}; 
\tikz[baseline, remember picture] \node[inner sep = 0pt, anchor = base] (subclause) {that he knows}; 
    \begin{tikzpicture}[remember picture, overlay]
      \draw[decorate, decoration = brace,above=2pt] (subclause.north west) -- (subclause.north east)
            node [midway, above=2pt] {\scriptsize{Subordinate clause}};
      \draw[decorate, decoration = brace] ($(mainclause.north west) + (0,12pt)$) -- ($(subclause.north east) + (0,12pt)$)
          node [midway, above, above=2pt] {\scriptsize{Main clause}};
    \end{tikzpicture}

\end{document}

答案4

为什么要使用 Tikz?你可以用一个简单的公式获得结果:

\documentclass{article}
\usepackage{mathtools} % http://ctan.org/pkg/mathtools
\begin{document}
$\overbrace{\text{She said}\overbrace{\text{that he knows}}^{\text{Subordinate clause}}}^{\text{Main clause}}$ et coetera...
\end{document}

结果是:

结果

相关内容