Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Hwo to put start line in the corrner of a A node? How to force TikZ to draw C-level siblings to the right direction.

enter image description here

\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}
share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

Here's one possible solution, if you don't mind drawing some nodes twice:

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

enter image description here

share|improve this answer
    
Could You add some comment next to main lines, please –  Daniel Miliński Oct 31 '12 at 0:17
1  
@DanielMiliński yes, of course; it's dinner time for me here, so I will add some comments in a while. –  Gonzalo Medina Oct 31 '12 at 0:23
1  
@DanielMiliński answer updated; I added some comments to the code. –  Gonzalo Medina Oct 31 '12 at 1:34
    
Thank You @Gonzalo Medina. –  Daniel Miliński Oct 31 '12 at 10:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.