7

Is it possible to show block C as a single block rather than having 3 blocks?

enter image description here

\documentclass[landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[margin=1in]{geometry}
\usepackage{tikz-qtree}
\usetikzlibrary{shadows,trees}
\begin{document}
\tikzset{font=\small,
edge from parent fork down,
level distance=1.75cm,
every node/.style=
    {top color=white,
    bottom color=blue!25,
    rectangle,rounded corners,
    minimum height=8mm,
    draw=blue!75,
    very thick,
    drop shadow,
    align=center,
    text depth = 0pt
    },
edge from parent/.style=
    {draw=blue!50,
    thick
    }}

\centering


\begin{tikzpicture}
\Tree [.A
        [.{B}
            [.{C} ]
] 
        [.{D}
            [.{C} ]            
 ] 
 [.{C}
]
        [.{E}
]
]
\end{tikzpicture}


\end{document}
6
  • I don't understand your question; in the diagram there are three blocks labelled "C". Which one is causing you problems? What do you mean with "having three blocks"? Can you please explain in a little more detail? Mar 16, 2013 at 14:10
  • C is a child of A, B and D. As it is only one child, I would like to show it as a single block C, rather than having 3 blocks as seen in the chart.
    – Reza
    Mar 16, 2013 at 14:14
  • The graph you're specifying isn't a tree, since there are multiple paths from the root A to node C. You may need some other tikz primitives to draw it (I don't know tikz.) Mar 16, 2013 at 14:38
  • You're right Ethan.
    – Reza
    Mar 16, 2013 at 14:44
  • Have you considered using Graphviz? In particular, look at the dot component of Graphviz. See this question for embedding it in a LaTeX document.
    – Anthony
    Mar 16, 2013 at 17:39

1 Answer 1

7

Since the required object will no longer be a tree (it has cycles), then it could be better to draw it without tikz-qtree; the following code shows some possibilities:

\documentclass[landscape]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows}

\begin{document}

\tikzset{font=\small,
every node/.style=
    {top color=white,
    bottom color=blue!25,
    rectangle,rounded corners,
    minimum height=8mm,
    draw=blue!75,
    very thick,
    drop shadow,
    align=center,
    text depth = 0pt
    },
myedge/.style=
    {draw=blue!50,
    thick
    }}

\begin{tikzpicture}
\node (a) {A};
\node[below=of a] (d) {D};
\node[right=of d] (e) {E};
\node[left=of d] (b) {B};
\node[below=of b] (c) {C};
\foreach \pare/\chil in {a/b,a/d,a/e,b/c,d/c} 
  \draw[myedge] (\pare.south) -- (\chil.north);
\draw[myedge] (a.south) -- (c.north);
\begin{scope}[xshift=5.5cm]
\node (a) {A};
\node[below=of a] (d) {D};
\node[right=of d] (e) {E};
\node[left=of d] (b) {B};
\node[below=of b] (c) {C};
\foreach \pare/\chil in {a/b,a/d,a/e,b/c,d/c} 
  \draw[myedge] (\pare.south) -- (\chil.north);
\draw[myedge] (a.south) .. controls (-3.5cm,-1.5cm) .. (c.north);
\end{scope}
\begin{scope}[xshift=8cm]
\node (a) {A};
\coordinate[below=of a] (aux); 
\node[right=of aux] (b) {B};
\node[right=of b] (d) {D};
\node[right=of d] (e) {E};
\node[below=of aux] (c) {C};
\foreach \pare/\chil in {a/b,a/d,a/e,b/c,d/c} 
  \draw[myedge] (\pare.south) -- (\chil.north);
\draw[myedge] (a) -- (c);
\end{scope}
\end{tikzpicture}

\end{document}

enter image description here

If you want to keep the tikz-qtree syntax and style, then you could do something like this:

\documentclass[landscape]{article}
\usepackage{tikz-qtree}
\usetikzlibrary{shadows,trees,calc}

\begin{document}
\tikzset{font=\small,
edge from parent fork down,
level distance=1.75cm,
every node/.style=
    {top color=white,
    bottom color=blue!25,
    rectangle,rounded corners,
    minimum height=8mm,
    draw=blue!75,
    very thick,
    drop shadow,
    align=center,
    text depth = 0pt
    },
edge from parent/.style=
    {draw=blue!50,
    thick
    }}

\begin{tikzpicture}
\Tree [.\node (a) {A};
        [.{B}
            [.\node (c) {C}; ]
] 
        [.\node (d) {D}; 
 ] 
        [.{E}
]
]
\draw[edge from parent] let \p1=(d.south), \p2=(c.north) in 
  (d.south) |- ( $ (d.south) + (0,0.5*\y2-0.5*\y1) $ ) -| (c.north);
\draw[edge from parent] let \p1=(a.south), \p2=(d.north) in 
  (a.south) -- ++(0,0.5*\y2-0.5*\y1) -- ++(-1.3,0) |- ( $ (c.north) - (0,0.5*\y2-0.5*\y1) $ ) -- (c.north);
\end{tikzpicture}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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