如何增加节点的背景颜色来输入文本

如何增加节点的背景颜色来输入文本

显然我需要为右侧文本添加背景颜色。代码来自 Tantau 手册,第 45 页。这对我来说是个谜。保存文本的节点出了什么问题?如有任何答案,我将不胜感激。抱歉,我的英语水平很差。另外,我无法以简单的方式发布代码(每行手动添加 4 个空格?)如果能在此看到代码的结果,那就太好了。

\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{setspace}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}

\begin{document}

\begin{tikzpicture}%
[%node distance=5mm,
 text height=1.0em,
 text depth=.25em,
 every node/.style={%
    %rectangle,draw=black,
    inner sep=0pt},%
 %information text/.style={rounded corners,fill=red!10,inner sep=1em}
]
   %\draw[help lines, use as bounding box] (-7,-3) grid (7,3);

   \node (advbo)  {Adverbiale Bestimmung};
   %\node (po)                       {Pronomen};
   \node (po)    [left =.9mm of advbo]                   {Pronomen};
   \node (vo)    [left =.9mm of po]  {Verb};
   \node (advo)  [left =.9mm of vo]  {Adverb};
   %\node (advbo) [right=.5mm of po] {Adverbiale Bestimmung};

   \node (s) [below= of advo] {Schnell};
   \node (li) [below= of vo] {lief}; 
   \node (e1) [below= of po] {er};
   \node (h) [below= of advbo] {hin,};

   %\node (la) [below= of s] {langsam};
   \node (la) [below=.3mm of s] {langsam};
   \node (k) [below=.3mm of li] {kam};
   \node (e2) [below=.3mm of e1] {er};
   \node (z) [below=.3mm of h] {zur"uck.};

   \node (advu) [below= of la] {Adverb};
   \node (vu) [below= of k] {Verb};
   \node (pu) [below= of e2] {Pronomen};
   \node (advbu) [below= of z] {Adverbiale Bestimmung};

   \draw[->,>=stealth', very thick, red, opacity=.5] (advo)  to (s);
   \draw[->,>=stealth', very thick, red, opacity=.5] (advu)  to (la);

   \draw[->,>=stealth', very thick, red, opacity=.5] (vo)    to (li);
   \draw[->,>=stealth', very thick, red, opacity=.5] (vu)    to (k);

   \draw[->,>=stealth', very thick, red, opacity=.5] (po)    to (e1);
   \draw[->,>=stealth', very thick, red, opacity=.5] (pu)    to (e2);

   \draw[->,>=stealth', very thick, red, opacity=.5] (advbo) to (h);
   \draw[->,>=stealth', very thick, red, opacity=.5] (advbu) to (z);

   \draw[xshift=2.75cm,yshift=-.75cm]
      %node[right,text width=4cm,information text]
      node[right,text width=4cm,rounded corners,fill=red!10,inner sep=1em]
      {
         Parallelisierte Satzkonstruktionen ergeben, wenn man sie    untereinanderstellt, immer parallele Verbindungslinien.
      };
\end{tikzpicture}

\end{document}

答案1

问题来自options中定义的text height和。这样,它们适用于所有节点,而右侧文本是,因此其垂直大小由这些值定义。text depthtikzpicturenode

如果不使用text heighttext depth,则所有其他节点都不会对齐,因此抑制它们并不方便。

由于我不知道如何将forget先前的值text height/depth应用于所有小节点都定义的特定节点,因此我能提供的最佳解决方案是将这些参数应用于其中scope。并在其外部声明正确的文本节点。

\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{setspace}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}

\begin{document}

\begin{tikzpicture}%
[%node distance=5mm,
% text height=1.0em,
% text depth=.25em,
 every node/.style={%
    %rectangle,draw=black,
    inner sep=0pt},%
 %information text/.style={rounded corners,fill=red!10,inner sep=1em}
]
   %\draw[help lines, use as bounding box] (-7,-3) grid (7,3);

\begin{scope}[text height=1.0em, text depth=.25em]
   \node (advbo)  {Adverbiale Bestimmung};
   %\node (po)                       {Pronomen};
   \node (po)    [left =.9mm of advbo]                   {Pronomen};
   \node (vo)    [left =.9mm of po]  {Verb};
   \node (advo)  [left =.9mm of vo]  {Adverb};
   %\node (advbo) [right=.5mm of po] {Adverbiale Bestimmung};

   \node (s) [below= of advo] {Schnell};
   \node (li) [below= of vo] {lief}; 
   \node (e1) [below= of po] {er};
   \node (h) [below= of advbo] {hin,};

   %\node (la) [below= of s] {langsam};
   \node (la) [below=.3mm of s] {langsam};
   \node (k) [below=.3mm of li] {kam};
   \node (e2) [below=.3mm of e1] {er};
   \node (z) [below=.3mm of h] {zur"uck.};

   \node (advu) [below= of la] {Adverb};
   \node (vu) [below= of k] {Verb};
   \node (pu) [below= of e2] {Pronomen};
   \node (advbu) [below= of z] {Adverbiale Bestimmung};
\end{scope}

   \draw[->,>=stealth', very thick, red, opacity=.5] (advo)  to (s);
   \draw[->,>=stealth', very thick, red, opacity=.5] (advu)  to (la);

   \draw[->,>=stealth', very thick, red, opacity=.5] (vo)    to (li);
   \draw[->,>=stealth', very thick, red, opacity=.5] (vu)    to (k);

   \draw[->,>=stealth', very thick, red, opacity=.5] (po)    to (e1);
   \draw[->,>=stealth', very thick, red, opacity=.5] (pu)    to (e2);

   \draw[->,>=stealth', very thick, red, opacity=.5] (advbo) to (h);
   \draw[->,>=stealth', very thick, red, opacity=.5] (advbu) to (z);

   \draw[xshift=2.75cm,yshift=-1.8cm]
      %node[right,text width=4cm,information text]
      node[right,text width=4cm, rounded corners,fill=red!10,inner sep=1em]
      {
         Parallelisierte Satzkonstruktionen ergeben, wenn man sie    untereinanderstellt, immer parallele Verbindungslinien.
      };
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容