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 create a flow chart going left-right where each stage has a header aligned with it, at a certain height above the chart. I am trying to use the Hydrogen Splitting Example (see the underlines titles), but that example uses fixed positioning, and I would ideally like to use a fixed vertical coordinate (perhaps based relative to my tallest column), and a relative horizontal one.

The below code doesn't work, but hopefully shows what I'm trying to do.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[node distance = 1mm, auto,
    box/.style={
        rectangle,
        draw,
        fill=blue!20, 
        text width=5em,
        text centered,
        rounded corners, 
        minimum height=4em
    }]  

    % First column
    \node [box]                  (b1)   {Box 1};
    \node [box, below=of b1]     (b2)   {Box 2};
    \node [box, below=of b2]     (b3)   {Box 3};

    % Second column
    \node [box, right=of b2, xshift=30mm]   (b4) {Box 4};

    % Labels at top
    \node [above=of b1, font=\large] (title1) {\underline{Column One}};
    \node [right=of title1, above=of b4, font=\large]{\underline{Column Two}};


\end{tikzpicture}
\end{document}

enter image description here

share|improve this question
    
I have used a similar idea to have labels at left side of the diagram. So same can be utilized to have orthogonal intersections of some coordinate and the column placement. You can see this answer for a longer explanation. –  percusse May 3 '12 at 13:02
add comment

1 Answer 1

up vote 9 down vote accepted

One option would be to use the implicit syntax ( <p> |- <q> ) (or ( <q> -| <p> )) to get (u,v), where u is the x-coordinate of <p> and v is the y-coordinate of <q>; in your case, you could use at (title1-|b4):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[node distance = 1mm and 30mm, auto,
    box/.style={
        rectangle,
        draw,
        fill=blue!20, 
        text width=5em,
        text centered,
        rounded corners, 
        minimum height=4em
    }]  

    % First column
    \node [box]                  (b1)   {Box 1};
    \node [box, below=of b1]     (b2)   {Box 2};
    \node [box, below=of b2]     (b3)   {Box 3};

    % Second column
    \node [box, right=of b2]   (b4) {Box 4};

    % Labels at top
    \node [above=of b1, font=\large] (title1) {\underline{Column One}};
    \node [font=\large,text centered] at (title1-|b4) {\underline{Column Two}};

\end{tikzpicture}
\end{document}

enter image description here

If more involved calculations are needed, the let construct (requires the calc library) can be used to get the other nodes coordinates (in this case, the y coordinate of (title1) and the x coordinate of (b4)) and use those coordinates to place the title:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[node distance = 1mm and 30mm, auto,
    box/.style={
        rectangle,
        draw,
        fill=blue!20, 
        text width=5em,
        text centered,
        rounded corners, 
        minimum height=4em
    }]  

    % First column
    \node [box]                  (b1)   {Box 1};
    \node [box, below=of b1]     (b2)   {Box 2};
    \node [box, below=of b2]     (b3)   {Box 3};

    % Second column
    \node [box, right=of b2]   (b4) {Box 4};

    % Labels at top
    \node [above=of b1, font=\large] (title1) {\underline{Column One}};
    \draw let \p1=(b4), \p2=(title1) in node [font=\large,text centered] at (\x1,\y2) {\underline{Column Two}};

\end{tikzpicture}
\end{document}
share|improve this answer
1  
@Jake: you're right; I'll add your suggestion to my answer as first option and will mention let as a second option. –  Gonzalo Medina May 3 '12 at 13:14
    
Great thanks, the (title1-|b4) notation works well. Just to be sure, am I right in interpreting that if ( <p> |- <q> ) and ( <q> -| <p> ) are the same, then the dash points towards the node you want the y-coordinate from, irrespective of the order? –  Chris May 3 '12 at 13:33
    
@Chris you're welcome and yes. –  Gonzalo Medina May 3 '12 at 13:37
3  
@Chris: You can get a better understanding of the |- syntax if you use it in a \draw command: Try \draw [red] (0,0) -| (1,1); \draw [blue] (0,0) |- (1,1); in a tikzpicture. –  Jake May 3 '12 at 13:40
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.