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.

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.

share|improve this question
    
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
add comment

1 Answer

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}

enter image description here

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

share|improve this answer
    
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
1  
@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
1  
@JoachimBreitner Then use the join styles. See the manual for the chains library. –  percusse Sep 5 '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.