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.

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 :

\documentclass[11pt]{scrartcl}   
\usepackage{tikz,tkzexample,fullpage} % tkzexample from TL2011
\usetikzlibrary{arrows}

\colorlet{graphicbackground}{blue!10}
\colorlet{codebackground}{red!10}

\begin{document}
\parindent=0pt
\thispagestyle{empty}

\begin{enumerate}
\item  
\begin{tkzexample}[width=3cm]
\begin{tikzpicture} [every node/.style={blue,draw,circle}]
\node(a){a};
\node(b) at (2,1){b} ; 
\draw[red,->] (a)  to[out=90,in=180] (b);
\end{tikzpicture} 
\end{tkzexample}   
\end{document}
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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.
share|improve this answer
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.