Perhaps the title of my question is not fine (let me know).

I try to finish a document about the best practices when programming with TikZ. I remark in several answers that a lot of users like to use long path where nodes are created, edges are drawn (with edge- etc. The four next pictures shows the result that I want, then some mistakes with bad practices. If a rule could be given, what would it be? If you know of other ways to get the same kind of results, you can let me know.

Good results

enter image description here

If we look at the pgfmanual, specially the tutorial, a lot of codes look likes 1 but sometimes T. Tantau uses 3

Bad results

enter image description here

Code for the first example :

\usepackage{tikz,tkzexample,fullpage} % tkzexample from TL2011



\begin{tikzpicture} [every node/.style={blue,draw,circle}]
\node(b) at (2,1){b} ; 
\draw[red,->] (a)  to[out=90,in=180] (b);

I guess it's generally good practice to code as you would draw it by hand, which of course depends on context. What surely is wrong is cramming everything in as few semicolons as possible. Concerning your example pictures,

  1. Seems fine, one by one
  2. assigns [red,->] to the nodes (code-wise), but is actually a style for the edge, which is misleading.
  3. is weird in the sense that it divides the three operations (2 nodes, arrow) into pretty random units.
  4. is fine too, it draws the whole unit as one. (For larger graphs this may become a bit hard to read though, see "semicolons are free to write" above.) The best thing would be a healthy mix of 1. and 4., grouping subunits together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.