4

This is my first TikZ diagram. I want to get the Figure like this

enter image description here

I use this code

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}
\tikzstyle{line} = [draw, -latex']
\begin{tikzpicture}
\node [draw,rounded corners, fill=blue!20] at (2,1) (Start) {Some Text};
\node [draw,rounded corners, fill=blue!20] at (0,0) (Block1) {Text Text};
\node [draw,rounded corners, fill=blue!20] at (4,0) (Block2) {Text};
\node [draw,rounded corners, fill=blue!20] at (6,0) (Block3) {Text Text Text};
\node[text width=3cm] at (0,-1.5) {some text spanning three lines with automatic line breaks\\
Another line of text};
\path [line] (Start) -| (Block1);
\path [line] (Start) -| (Block2);
\path [line] (Start) -| (Block3);
\end{tikzpicture}
\end{document}
  • Placement of node and related text below nodes.
  • Equal distance between text below nodes.
  • Make this diagram at Center of the page.

Edit: After getting the answer, I am wondering if I want the diagram as enter image description here

1
  • 1
    only omit middle node in answer's MWE and eventually redefine node distance, for example to node distance = 12mm and 0mm. Of course, you need to define the branch coordinate, see addendum to my answer.
    – Zarko
    Commented Aug 28, 2016 at 15:14

2 Answers 2

3

Since my answer to a later question by Diaa Abidou apparently answered this one possibly better, I am repeating that answer here for completeness. For a full explanation of the code, please see the details I provided there.

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[edges]{forest}
\usepackage{calc}
\usetikzlibrary{arrows.meta}
\forestset{%
  declare dimen register={gap},
  gap'=20mm,
  declare dimen register={lbox width},
  lbox width=(\textwidth-2*\forestregister{gap})/3,
  rbox/.style = {draw=blue!80!black, fill=blue!20, rounded corners},
  lbox/.style = {align/.wrap pgfmath arg={@{}p{##1 pt}@{}}{(lbox_width)}},
}
\begin{document}
\begin{forest}
  forked edges,
  for tree={%
    font = \sffamily,
    edge = {draw, -{Latex}},
  },
  where n children=0{%
    lbox,
    no edge,
  }{%
    rbox,
  }
  [Some Text, name=Start, l sep+=5pt
    [Text Text, name=Block1
      [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
      ]
    ]
    [Text, name=Block2
      [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
      ]
    ]
    [Text Text Text, name=Block3
      [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
      ]
    ]
  ]
\end{forest}
\end{document}

aligned nodes in Forest tree

EDIT

In response to a query asking how to reduce the distance between the terminus nodes and their parents, I would change the value of l for those nodes. However, we need to delay this until after the tree is packed in order to override Forest's calculations.

For example,

  where n children=0{%
    lbox,
    no edge,
    before computing xy={%
      l'-=10pt,
    },
  }{%
    rbox,
  }

produces

closer fit

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[edges]{forest}
\usepackage{calc}
\usetikzlibrary{arrows.meta}
\forestset{%
  declare dimen register={gap},
  gap'=20mm,
  declare dimen register={lbox width},
  lbox width=(\textwidth-2*\forestregister{gap})/3,
  rbox/.style = {draw=blue!80!black, fill=blue!20, rounded corners},
  lbox/.style = {align/.wrap pgfmath arg={@{}p{##1 pt}@{}}{(lbox_width)}},
}
\begin{document}
\begin{forest}
  forked edges,
  for tree={%
    font = \sffamily,
    edge = {draw, -{Latex}},
  },
  where n children=0{%
    lbox,
    no edge,
    before computing xy={%
      l'-=10pt,
    },
  }{%
    rbox,
  }
  [Some Text, name=Start, l sep+=5pt
    [Text Text, name=Block1
      [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
      ]
    ]
    [Text, name=Block2
      [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
      ]
    ]
    [Text Text Text, name=Block3
      [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
      ]
    ]
  ]
\end{forest}
\end{document}
3

Try:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\pagestyle{empty}

\begin{figure}
    \centering
    \begin{tikzpicture}[
         font = \sffamily,
line/.style = {draw, -Latex},
  rbox/.style = {draw=blue!80!black, fill=blue!20, 
               rounded corners, inner sep=2mm,
               node distance = 12mm and 18mm},
lbox/.style = {text width=32mm, inner sep=0pt,
               node distance = 2mm}
                        ]
\node (Start)   [rbox] {Some Text};
\node (Block1)  [rbox,below  left=of Start] {Text Text};
\node (Block2)  [rbox,below=of Start]       {Text};
\node (Block3)  [rbox,below right=of Start] {Text Text Text};
\node [lbox,below=of Block1] {some text spanning three lines 
                              with automatic line breaks.

                              Another line of text};
\node [lbox,below=of Block2] {some text spanning three lines
                              with automatic line breaks};
\node [lbox,below=of Block3] {some text spanning three lines
                              with automatic line breaks.};
\path [line] (Start) -- coordinate (a) (Block2);
\path [line] (a) -| (Block1);
\path [line] (a) -| (Block3);
    \end{tikzpicture}
\caption{my figure}
    \label{fig-1}
\end{figure}
\end{document}

enter image description here

I assume, that image is in document placed in float figure. Inside it you can center it with \centering. If this is not a case, then you can use

\begin{center}
< your tikz image >
\end{center}

In above MWE I defined styles rbox for rounded nodes and lbox for nodes below rounded boxes. For their positioning I use relative positioning from library positioning.

Addendum: In case of image as show in edited question, you need to do some small changes:

  • define coordinate (a) on the new way: \draw (Start.south) -- ++ (0,-6mm) coordinate (a);
  • redefine node distance in rbox node style to something like node distance = 12mm and 0mm
  • and, of course, delete block from code ...

enter image description here

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\pagestyle{empty}

\begin{figure}
    \centering
    \begin{tikzpicture}[
         font = \sffamily,
line/.style = {draw, -Latex},
  rbox/.style = {draw=blue!80!black, fill=blue!20,
               rounded corners, inner sep=2mm,
               node distance = 12mm and 0mm},
lbox/.style = {text width=32mm, inner sep=0pt,
               node distance = 2mm}
                        ]
\node (Start)   [rbox] {Some Text};
\node (Block1)  [rbox,below  left=of Start] {Text Text};
\node (Block3)  [rbox,below right=of Start] {Text Text Text};
\node [lbox,below=of Block1] {some text spanning three lines
                              with automatic line breaks.

                              Another line of text};
\node [lbox,below=of Block3] {some text spanning three lines
                              with automatic line breaks.};
\draw        (Start.south) -- ++ (0,-6mm) coordinate (a);
\path [line] (a) -| (Block1);
\path [line] (a) -| (Block3);
    \end{tikzpicture}
\caption{my figure}
    \label{fig-1}
\end{figure}
\end{document}
5
  • I am sorry, but could you tell me how to parameterize the lbox width? For example, I need to define the spacing between the text nodes, then latex will automatically calculate each text node width based on the page geometry.
    – Diaa
    Commented Aug 28, 2016 at 13:55
  • @Zarko, Nicely explained. I am wondering if I need only two boxes instead of three, then how do I change it? \child is not working here, maybe, I don't know how to use it with proper parameter.
    – Mithun
    Commented Aug 28, 2016 at 14:12
  • This flowchart isn't draw with tree, so in it child is not employed. If you like to have image design on such a way, then is worth to consider forest packages (with it I'm still very familiar). The width of lbox is deined with text width and it is set near value as you have in your MWE. It can be relatively determined in adance: 1/3 \trextwidt - 2/3 desired gap between them. To this width you can adopted node distance of rbox by trial :-). Some experience in drawing is very helpful in this.
    – Zarko
    Commented Aug 28, 2016 at 14:57
  • @Torbjørn T., I wrote answer immediately after my lunch when I have more blood in stomach than in brain :-). Thank you very much for correcting my spelling and laguage errors.
    – Zarko
    Commented Aug 28, 2016 at 15:01
  • @Zarko Now, it is clear about the lbox width. Anyway, I added one new figure. Is it possible for you to provide the MWE?
    – Mithun
    Commented Aug 28, 2016 at 15:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .