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.

I am trying to build a block diagram with some control flow using TikZ. The blocks in the diagram should be aligned like the vertices of a hexagon. Also the \centering macro is not working for me. Please give me suggestions to center the entire picture and improve the alignment among the blocks.

\documentclass{article}
\usepackage{amsmath}
\usepackage{biblatex}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{tikz}
\usepackage{varwidth}
\usetikzlibrary{shapes.multipart, arrows}
\tikzstyle{nodest} = [draw, rounded corners, very thick]

\begin{document}

\centering
    \begin{tikzpicture} [node distance=5cm, auto, >=latex']
        \node (inputnode)[nodest, align=center, rectangle split, rectangle split draw splits=false] {
            \textbf{Input}
            \nodepart{two}
                $(A, 506, 90)$\\
                $(B, 590, 86)$\\
                $(A, 590, 70)$
            \nodepart{three}
                $(C, 506, 23)$\\
                $(C, 590, 45)$\\
                $(B, 506, 67)$
        };

        \node [below of=inputnode] {\begin{varwidth}{15em}\Large{partitions of input tuples are sent to mappers}\end{varwidth}};

        \draw[thick] (inputnode.text split west) -- (inputnode.text split east);
        \draw[dashed] (inputnode.second split west) -- (inputnode.second split east);

        \node (map1node)[nodest, rectangle split, rectangle split draw splits=false, right of=inputnode, yshift=2.5cm] {
            \textbf{Mapper 1}
            \nodepart{two} $key = 506, value = (A, 90)$
            \nodepart{three} $key = 590, value = (B, 86)$
            \nodepart{four} $key = 590, value = (A, 70)$
        };
        \draw[->, thick] (inputnode.two east) -- (map1node);

        \node (map2node)[nodest, rectangle split, rectangle split draw splits=false, below of=map1node] {
            \textbf{Mapper 2}
            \nodepart{two} $key = 506, value = (C, 23)$
            \nodepart{three} $key = 590, value = (C, 45)$
            \nodepart{four} $key = 506, value = (B, 67)$
        };
        \draw[->, thick] (inputnode.three east) -- (map2node);

        \node [below of=map2node] {\begin{varwidth}{15em}\Large{Mappers}\end{varwidth}};

        \node (reduce1node) [nodest, rectangle split, rectangle split parts=5, rectangle split draw splits=false, right of=map1node, xshift=2cm] {
            \textbf{Reducer 1}
            \nodepart{two} $key = 506$
            \nodepart{three} $(A, 90)$
            \nodepart{four} $(C, 23)$
            \nodepart{five} $(B, 67)$
        };
        \draw[->, dashed] (map1node.two east) -- (reduce1node.three west);
        \draw[->, dashed] (map2node.two east) -- (reduce1node.four west);
        \draw[->, dashed] (map2node.four east) -- (reduce1node.five west);

        \node (reduce2node) [nodest, rectangle split, rectangle split parts=5, rectangle split draw splits=false, right of=map2node, xshift=2cm] {
            \textbf{Reducer 2}
            \nodepart{two} $key = 590$
            \nodepart{three} $(B, 86)$
            \nodepart{four} $(A, 70)$
            \nodepart{five} $(C, 45)$
        };
        \draw[->, dashed] (map1node.three east) -- (reduce2node.three west);
        \draw[->, dashed] (map1node.four east) -- (reduce2node.four west);
        \draw[->, dashed] (map2node.three east) -- (reduce2node.five west);

        \node [below of=reduce2node] {\begin{varwidth}{15em}\Large{Reducers}\end{varwidth}};
    \end{tikzpicture}

\end{document}
share|improve this question
    
Welcome to TeX.sx! A tip: You can use backticks ` to mark your inline code as I did in my edit. As well, we usually don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  tohecz Sep 26 '12 at 9:42
    
At first glance, you should put the centering environment outside the tikzpicture to centre the picture on the page. –  Loop Space Sep 26 '12 at 9:49
    
(See minimal working example (MWE) for more on what constitutes a MWE and why it's useful.) –  Loop Space Sep 26 '12 at 9:49
    
I have edited it to a complete minimal document. Appreciate the suggestions. –  nomind Sep 26 '12 at 16:01

1 Answer 1

up vote 5 down vote accepted

You can precisely put them on the vertices of an hexagon with a hexagon node. I've drawn it but you can always remove the draw option.

\documentclass{article}
\usepackage{amsmath}
\usepackage{biblatex}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{tikz}
\usepackage{varwidth}
\usetikzlibrary{shapes.multipart,shapes.geometric, arrows}
\tikzstyle{nodest} = [draw, rounded corners, very thick]

\begin{document}
{
\centering
    \begin{tikzpicture} [node distance=5cm, auto, >=latex']
    \node[regular polygon,regular polygon sides=6,minimum height=10 cm,draw] (hexag) {};
        \node (inputnode)[nodest, align=center, rectangle split, rectangle split draw splits=false] at (hexag.corner 3){
            \textbf{Input}
            \nodepart{two}
                $(A, 506, 90)$\\
                $(B, 590, 86)$\\
                $(A, 590, 70)$
            \nodepart{three}
                $(C, 506, 23)$\\
                $(C, 590, 45)$\\
                $(B, 506, 67)$
        };

        %\node at (hexag.corner 4) {\begin{varwidth}{15em}\Large{partitions of input tuples are sent to mappers}\end{varwidth}};

        \draw[thick] (inputnode.text split west) -- (inputnode.text split east);
        \draw[dashed] (inputnode.second split west) -- (inputnode.second split east);

        \node (map1node)[nodest, rectangle split, rectangle split draw splits=false] at (hexag.corner 2){
            \textbf{Mapper 1}
            \nodepart{two} $key = 506, value = (A, 90)$
            \nodepart{three} $key = 590, value = (B, 86)$
            \nodepart{four} $key = 590, value = (A, 70)$
        };
        \draw[->, thick] (inputnode.two east) -- (map1node);

        \node (map2node)[nodest, rectangle split, rectangle split draw splits=false]  at (hexag.corner 4){
            \textbf{Mapper 2}
            \nodepart{two} $key = 506, value = (C, 23)$
            \nodepart{three} $key = 590, value = (C, 45)$
            \nodepart{four} $key = 506, value = (B, 67)$
        };
        \draw[->, thick] (inputnode.three east) -- (map2node);

        \node [below of=map2node] {\begin{varwidth}{15em}\Large{Mappers}\end{varwidth}};

        \node (reduce1node) [nodest, rectangle split, rectangle split parts=5, rectangle split draw splits=false] at (hexag.corner 1) {
            \textbf{Reducer 1}
            \nodepart{two} $key = 506$
            \nodepart{three} $(A, 90)$
            \nodepart{four} $(C, 23)$
            \nodepart{five} $(B, 67)$
        };
        \draw[->, dashed] (map1node.two east) -- (reduce1node.three west);
        \draw[->, dashed] (map2node.two east) -- (reduce1node.four west);
        \draw[->, dashed] (map2node.four east) -- (reduce1node.five west);

        \node (reduce2node) [nodest, rectangle split, rectangle split parts=5, rectangle split draw splits=false]  at (hexag.corner 5){
            \textbf{Reducer 2}
            \nodepart{two} $key = 590$
            \nodepart{three} $(B, 86)$
            \nodepart{four} $(A, 70)$
            \nodepart{five} $(C, 45)$
        };
        \draw[->, dashed] (map1node.three east) -- (reduce2node.three west);
        \draw[->, dashed] (map1node.four east) -- (reduce2node.four west);
        \draw[->, dashed] (map2node.three east) -- (reduce2node.five west);

        \node [below of=reduce2node] {\begin{varwidth}{15em}\Large{Reducers}\end{varwidth}};
    \end{tikzpicture}
}
\end{document}

enter image description here

I didn't know what to do with one of nodes so it's missing.

share|improve this answer

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.