节点角落处的起始线

节点角落处的起始线

如何将起始线放在 A 节点的角落?如何强制 TikZ 将 C 级兄弟节点绘制到正确的方向。

在此处输入图片描述

\documentclass{beamer}%
\mode<presentation>%
{
\usetheme{Madrid}%
\setbeamercovered{transparent}
}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{%
 arrows,%
 shapes.misc,%
 shapes.arrows,%
 positioning,% wg. " of "
 scopes,%
 decorations.pathmorphing,%
 shadows,%
 trees
}

\usepackage{amsmath}
\usepackage{tgheros}
\renewcommand*\familydefault{\sfdefault} 

\title[Example]%
{\textbf{How to ?}} %
\subtitle{}%
\author[]%
{Foo Bar}%
\institute[of Beamer]%
{
%
}
\date[\today]%
{}%

\subject{Talks}%

\definecolor{niebieski}{HTML}{aac9cb}
\definecolor{szary}{HTML}{7a7a7a}
\definecolor{morski}{HTML}{6bc1c5}


\tikzstyle{kwadrat1}=[rectangle, rounded corners=2pt, thin, black,top color=niebieski!30, bottom color=niebieski, draw=szary, text= black, minimum width=2.5cm, minimum height=0.6cm, text width = 2.5cm, text badly centered, inner ysep=2pt, ]

\tikzstyle{kwadrat2}=[rectangle, rounded corners=2pt, thin, black,top color=morski!30, bottom color=morski, draw=szary, text= black, minimum width=2.5cm, minimum height=0.6cm, text width = 2.5cm, text badly centered, inner ysep=2pt, ]

\tikzstyle{kwadrat3}=[rectangle, rounded corners=2pt, thin, black,top color=morski!30, bottom color=morski, draw=szary, text= black, minimum width=2.5cm, minimum height=0.6cm, text width = 2.5cm, text badly centered, inner ysep=2pt, ]

\begin{document}
\begin{frame}
\begin{tikzpicture}[%
  grow via three points={one child at (0.5,-0.7) and
  two children at (0.5,-0.7) and (0.5,-1.4)},
  edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}]
    \node [kwadrat1] {A}
       child { node [kwadrat2] {B}}     
       child { node[kwadrat2] {B}}
       child { node [kwadrat2] {B}}
       child { node [kwadrat2] {B}
          child { node [kwadrat3] {C}}
          child { node [kwadrat3] {C}}
          child { node [kwadrat3] {C}}
};
\end{tikzpicture}

\end{frame}
\end{document}

答案1

如果您不介意绘制某些节点两次,这里有一个可能的解决方案:

\documentclass{beamer}%
\mode<presentation>%
{
\usetheme{Madrid}%
\setbeamercovered{transparent}
}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{%
 calc,
 arrows,%
 shapes.misc,%
 shapes.arrows,%
 positioning,% wg. " of "
 scopes,%
 decorations.pathmorphing,%
 shadows,%
 trees
}

\usepackage{amsmath}
\usepackage{tgheros}
\renewcommand*\familydefault{\sfdefault} 

\title[Example]%
{\textbf{How to ?}} %
\subtitle{}%
\author[]%
{Foo Bar}%
\institute[of Beamer]%
{
%
}
\date[\today]%
{}%

\subject{Talks}%

\definecolor{niebieski}{HTML}{aac9cb}
\definecolor{szary}{HTML}{7a7a7a}
\definecolor{morski}{HTML}{6bc1c5}


\tikzstyle{kwadrat1}=[rectangle, rounded corners=2pt, thin, black,top color=niebieski!30, bottom color=niebieski, draw=szary, text= black, minimum width=2.5cm, minimum height=0.6cm, text width = 2.5cm, text badly centered, inner ysep=2pt, ]

\tikzstyle{kwadrat2}=[rectangle, rounded corners=2pt, thin, black,top color=morski!30, bottom color=morski, draw=szary, text= black, minimum width=2.5cm, minimum height=0.6cm, text width = 2.5cm, text badly centered, inner ysep=2pt, ]

\tikzstyle{kwadrat3}=[rectangle, rounded corners=2pt, thin, black,top color=morski!30, bottom color=morski, draw=szary, text= black, minimum width=2.5cm, minimum height=0.6cm, text width = 2.5cm, text badly centered, inner ysep=2pt, ]

\begin{document}
\begin{frame}
\begin{tikzpicture}[remember picture]

% the nodes labeled "A" and "B"
\node [kwadrat3] (a) at (0,0) {A};
\node [kwadrat2,below of = a,xshift=1cm] (b1) {B};
\node [kwadrat2,below of = b1,yshift=-1cm] (b2) {B};
\node [kwadrat2,below of = b2] (b3) {B};

% lines from "A" to each "B" node
\foreach \value in {1,2,3}
  \draw (a.195) |- (b\value.west);

% here we complete the drawing using trees
\begin{scope}[
  grow=right,
  level distance=2cm,
  level 1/.style={sibling distance=8mm},
  edge from parent path={(\tikzparentnode.east) -- +(10pt,0) |- (\tikzchildnode.west)}
]
% a tree with root on the upper "B" node (the root node (b1) was drawn before)
\node [kwadrat2]  at (b1) {B}
  child { node [kwadrat1,anchor=west] {C}}
  child { node [kwadrat1,anchor=west] {C}}
  child { node [kwadrat1,anchor=west] {C}}
  child { node [kwadrat1,anchor=west] {C}
};
% a tree with root on the lower "B" node (the root node (b3) was drawn before)
\node [kwadrat2]  at (b3) {B}
  child { node [kwadrat1,anchor=west] {C}};
\end{scope}
\end{tikzpicture}

\end{frame}
\end{document}

在此处输入图片描述

相关内容