# TikZ: lineto to a just created node

Often, when drawing diagrams with TikZ, I’d like link nodes by edges just as I draw them. But when doing it the naive way, e.g.

\draw (0,0) node {A} -- (1,0) node {B};


the line intersects with the node labels. I get the desired result by drawing the edge after the nodes:

\path (0,0) node (A) {A} (1,0) node (B) {B};
\draw (A) -- (B);


But for that, I have to hand out names to the nodes. Is it possible to obtain that result in one \draw command, without using names? Preferably a solution less involved than the chain library.

-
Using \draw (0,0) node [fill=white] {A} -- (1,0) node [fill=white] {B}; removes the intersection problem, but I don't know if the output is exactly the same as your second example. –  Corentin Sep 5 '12 at 13:27
I’d consider that a work-around, and I am looking for a solution that gives the same result – but thanks for the suggestion. –  Joachim Breitner Sep 5 '12 at 13:34

You can use the append after command key which works inside a path command.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw node (a) {A} node[append after command={(a)--(b)}] (b) at (1,0) {B};
\end{tikzpicture}
\end{document}


And please post full MWEs as I have provided in the answer so that anybody can copy-paste your code and try out a possible solution

-
Interesting, but still requires naming the nodes. Are there maybe explicit node names available for “current” and “previous” nodes? –  Joachim Breitner Sep 5 '12 at 13:33
@JoachimBreitner There are but they are more laborous than naming your nodes such as \tikzlastnodeetc. What is your context? –  percusse Sep 5 '12 at 13:38
With context, you mean use case? It is still developing, but a long chain of manually placed nodes is a close approximation. –  Joachim Breitner Sep 5 '12 at 13:40
@JoachimBreitner Then use the join styles. See the manual for the chains library. –  percusse Sep 5 '12 at 13:40