[Tex/LaTex] multiple relative positioning in tikz

positioningtikz-pgf

How to align a node vertical align to one node, and horizontal align to another one?

For example, given below code

\documentclass{standalone}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{makecell}
\usetikzlibrary{arrows,shapes,automata,petri,positioning}
\tikzset{
    data/.style={
        ellipse,
        thick,
        draw=black,
        minimum size=6mm
    },
    process/.style={
        rectangle,
        thick,
        draw=black
    },
} 

\pagestyle{empty}
\begin{document}
    \begin{tikzpicture}[node distance=1 and 1,>=stealth',bend angle=45,auto]
        \node [data] (a) {a};

        \node [process,align=center] (b) [below= of a] {bbbbbbbbbbb}
            edge[pre] (a);

        \node [data,align=center] (c) [below= of b]{cc\\ccc\\ccccc}
            edge[pre]   (b);

        \node [process,align=center] (d) [below right= of c] {dddd\\ddddddd}
            edge[pre]   (c);

        \node [data]    (e)     [above right= of d] {e}
            edge[post]  (d);

        \node [process] (f) [above= of e]   {f}
            edge[post]  (e);

        \node [data]    (g)    [above= of f]   {g}
            edge[post]  (f);
    \end{tikzpicture}
\end{document}

Result: enter image description here

I want three nodes e, f, g will be vertical base/mid/center alignment, and (a, g), (bb, f) (ccc,e) will be horizontal base/mid/center alignment.

For example, above image is what I want. Note that the red line will not be displayed, it is represented for "base alignment line"

enter image description here

Thanks for your help.

Best Answer

You can use `orthogonal coordinates like:

\node [process] (f) at (b-|g) {f}

Code:

\documentclass{standalone}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{makecell}
\usetikzlibrary{arrows,shapes,automata,petri,positioning,calc}
\tikzset{
    data/.style={
        ellipse,
        thick,
        draw=black,
        minimum size=6mm
    },
    process/.style={
        rectangle,
        thick,
        draw=black
    },
}

\pagestyle{empty}
\begin{document}
    \begin{tikzpicture}[node distance=1 and 1,>=stealth',bend angle=45,auto]
        \node [data] (a) {a};
        \node [data]    (g)    [right = 4cm of a]   {g};
        \node [process,align=center] (b) [below= of a] {bbbbbbbbbbb}
            edge[pre] (a);
        \node [process] (f) at (b-|g) {f}
              edge[pre]  (g);

        \node [data,align=center] (c) [below= of b]{cc\\ccc\\ccccc}
            edge[pre]   (b);
        \node [data] (e) at (c-|f) {e}
              edge[pre]  (f);

        \node [process,align=center,anchor=center] (d) at ([yshift=-2cm]$(c.center)!0.5!(e.center)$)
           {dddd\\ddddddd}
            edge[pre]   (c) 
            edge[pre]   (e);     
    \end{tikzpicture}
\end{document}

enter image description here

With tikz matrix:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows,shapes,automata,petri}
\begin{document}
\tikzset{
    data/.style={
        ellipse,
        thick,
        draw=black,
        minimum size=6mm
    },
    process/.style={
        rectangle,
        thick,
        draw=black
    },
}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,nodes={align=center,anchor=center},%
                column sep=1cm,%
                row sep=1cm]
{
 |[data]|a                                  &  &  |[data]| g \\
 |[process]| bbbbbbbbbbb                    &  &  |[process]| f \\
 |[data,text width = 0.8cm]|cc  ccc ccccc   &  &  |[data]| e \\
            &  |[process,text width = 2cm]| dddd ddddd$d$ &    \\
  };
 \draw (m-1-1) edge[post] (m-2-1)
       (m-2-1) edge[post] (m-3-1)
       (m-3-1) edge[post] (m-4-2);
  \draw (m-1-3) edge[post] (m-2-3)
       (m-2-3) edge[post] (m-3-3)
       (m-3-3) edge[post] (m-4-2);
\end{tikzpicture}
\end{document}