2

I've got the following TikZ picture:

\begin{tikzpicture}[node distance=2cm, scale=0.7, transform shape]
\node (start) [func-entry] {Config.getText(\textbf{key})};
\node (dec1) [decision, below of=start] {\textbf{key} in\\ \emph{localized \_labels?}};
\node (dec2) [decision, right of=dec1, node distance=4cm] {\textbf{key} in\\ \emph{default \_language \_labels?}};
\node (stop) [stop, right of=dec2, node distance=4cm] {Return \textbf{key}};
\node (stop2) [stop, below of=dec1, node distance=2.6cm, xshift=2cm] {Return its value};

\draw [arrow] (start) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=south] {No} (dec2);
\draw [arrow] (dec2) -- node[anchor=south] {No} (stop);
\draw [arrow] (dec1) |- node[anchor=east] {Yes} (stop2);
\draw [arrow] (dec2) |- node[anchor=west] {Yes} (stop2);

\end{tikzpicture}

which looks like this with my concrete node definitions: Result

How do I add a label, like localized_labels = /some/file/path/here to the top or bottom of the picture without affecting the layout of the current nodes? I want the label to be included IN the picture (e.g. just doing it outside the tikzpicture is not ideal). I've tried drawing a node with [draw=none] at (0,0), but it draws on top of the existing nodes. What I want to do is to "shift" the current group of nodes down and then add the label in the top, but without affecting alignment of current nodes.

2

1 Answer 1

2

Three suggestions:

  • You could add it relative to another node, for example

    \node [above=of dec2] {Whatever text you wanted};
    

    This requires \usetikzlibrary{positioning}.

  • You could place it relative to the current bounding box:

     \node [above=of current bounding box.north] {Whatever text you wanted};
    

    With this method you have to place the above line at the very end of the tikzpicture.

  • You could specify the position. I think (0,0) is the default position for a node without coordinates, so your start node is probably in (0,0). Hence, you could do

     \node at (2,1) {Whatever text you wanted};
    

    to place it two units to the right, and one unit above, the start node.

3
  • It works, but I would rather not couple the text to the alignment of the nodes below. Is there a way to avoid this? E.g. just placing text in (0.0) left-aligned while "pushing" the below nodes down 1 or 2 cm to make room for it?
    – johnrl
    Commented Jan 7, 2014 at 9:30
  • @johnrl I added two more suggestions to my answer. Commented Jan 7, 2014 at 9:48
  • @johnrl Were any of my suggestions sufficient? Commented Jan 10, 2014 at 23:35

You must log in to answer this question.

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