First, I must say I have very limited knowledge about PGF/TikZ. Most things I do are blind copy-pastes of examples I find on the Internet with lots of trial-and-error and googling around.

After spending 4 hours on drawing the simple diagram below (and many other hours on previous diagrams), I could not help to wonder how much time an experienced TikZ user would need to draw it. Had I used some click-and-drag tool, it would definitely take less than 30 minutes.

I understand that TikZ has quite a learning curve, much like LaTeX itself and other tools like the vi editor, shell scripting, sed, awk, etc. You have to study a lot to actually figure out how things work and how to express what you want (just like learning a programming language), but the sacrifice pays off later, because you can accomplish tasks much faster than with regular "friendly" tools. However, I am not so sure this holds for TikZ, at least for simple stuff like Computer Science diagrams.

Hence, my question is: Would it pay off for me to learn and understand all principles and techniques of PGF/TikZ? Would you, as an expert TikZ user, draw a simple diagram like the one below faster than a regular click-and-drag user?

For diagrams that are a little simpler than this, you can easily get away with using the simpler GraphViz. In the simplest cases its syntax is dead simple: digraph G { "a" -> "c" -> "d"; "b" -> "c" }. Save in test.dot and then run dot test.dot -Tsvg -o test.svg.
–
badpApr 20 '12 at 6:25

6 Answers
6

I took one look at that diagram and thought, "Absolutely! Use TikZ.". I then thought of trying to typeset that diagram and seeing how long it took me - I would estimate about a 1/4hr to get something fairly close and then probably another 10 minutes to tweak things to how I wanted them (assuming that I didn't encounter either any hidden difficulties or any interesting behaviour - which would send me off on a tangent while I found out about it).

But then I decided that that wouldn't be helpful. In my "scratch" directory where I try out answers for this site, I have 502 tex files of which 306 match usepackage{tikz}. So I'm a little TikZ-obsessed! And so a straightforward diagram like that really shouldn't take me much time, otherwise I've been wasting a heck of a lot of time learning TikZ.

Rather, I'm going to explain why I use TikZ instead of a graphical package such as Inkscape. I think my reasoning is actually why I use a programming system rather than a graphical system, so would equally apply to PSTricks or other such.

Precision I'm a bit fanatical about getting stuff in the actual right place, not just what looks okay. Your diagram would look not so polished if the Maps didn't line up exactly - it might not be obvious why, but looking at it one would have a feeling of it not being quite right. It's easier to program precision than drag-and-drop it.

Repetition There's a lot that's the same in the diagram. Lots of pieces have the same style, the same layout. Again, it's easier to program these than drag-and-drop them. I expect that programs like Inkscape have lots of shortcuts for "apply the same style to all of these", but I'd also imagine that it's easy to miss out one aspect, or include one aspect too many.

Variation I'm never happy with how things turn out the first time. I frequently want to change little things until I'm happy with them. Being able to change just one thing and have a whole lot depend on that one change makes this much easier. So defining a style and changing that, or basing a sub-diagram at a particular coordinate, makes it easier to vary things until I'm happy.

Repetition I do a lot of diagrams, but not so many that I'm a graphical designer. Every time that I do a new diagram there's a certain amount of "I've done something like this before, how did I do it?" with subsequent cut-and-pasting. When I use a graphical system then all of the "How did I do it?" information is lost. I can cut-and-paste actual objects, but it's rarely the objects that I want to copy - it's the "how did I get that particular effect" that I want to copy. When programming a diagram, all of this is laid out in an easily copy-able form.

For me, this last one is the reason TikZ fits so well into my workflow. It's the same with TeX itself. Every so often I find myself sitting in front of OpenOffice (or worse) and thinking, "How did I get the footer to stay on the bottom last time? Yet again it's floating in the middle of the page!". Then I have to remember the exact sequence of menus and options to do it. With TeX then I look back at the old document where this happened, find the \def\footerlocation{bottom}, and copy it over. That is the real time-saver for me.

In conclusion, if you've only one or a small number of diagrams to do then the time saved/time spent lines may not cross for you. But if it's something that you'll do a lot, consider time learning to program your diagrams time well spent.

As this question is proving so popular, I thought I'd add a little more. Specifically, examples. A little while ago, I uploaded all the pictures I'd generated using TikZ for this site to Picassa (at least, I think they all use TikZ. Certainly most of them do.). You can see them at this link: https://plus.google.com/photos/110765980098077923527/albums/5659314316046158689?banner=pwa. A particular picture, which isn't there, which I think demonstrates where something like TikZ is essential is the following:

@StephanLehmke But that would spoil the (appalling) pun ...
–
Loop SpaceApr 19 '12 at 10:50

Thank you for the excellent answer, Andrew! (nice pun btw) Now let me ask you a small follow-up (ok maybe two). The advantages you described apply to "diagram programming" in general. Besides the TeX integration, is there any reason why TikZ is most productive in particular? Also, are the concepts of diagram programming common to all such tools, to the point where a TikZ user could rapidly switch to another one if need be?
–
Caetano SauerApr 19 '12 at 11:15

1

@CaetanoSauer (I will confess to merely repeating a pun I learnt elsewhere). To your follow-ups: 1. Because it's what I know and I'm a one-trick-pony. 2. No idea. I have no intention of finding out! Seriously. I'm the sort of person who would rather figure out how to get TeX to output Markdown than write in Markdown. So I will use TikZ - because that's what I know - rather than use any other system if at all possible. Fortunately, I've yet to find a circumstance in which I couldn't use TikZ to achieve what I wanted.
–
Loop SpaceApr 19 '12 at 11:41

5

Another argument for TikZ is that it provides a human-readable, self-descriptive textual representation of your diagram, making it very well-suited to version control.
–
Will VousdenApr 19 '12 at 14:18

Andrew stated some very good reasons to use TikZ for such a diagram and similar material. I want to make a counterargument that there are a number of reasons to use other tools, such as Inkscape, Adobe Illustrator, online collaboration tools (Lucidchart and others) or any of the large number of illustration/drawing software packages.

The main reasons to avoid TikZ or similar 'graphics programming' languages are

Precision/productivity tradeoff

While alignment of elements, the exact same dimensions and font sizes are really what every designer should aim for it often does not matter so much in the end. I did a fair amount of CAD so I love when everything is aligned absolutely perfectly my colleagues often can't distinguish between some 'quick hack' and a perfectly aligned figure. The quick version, as you stated, takes 30 minutes, a precise version can take several hours.

Interoperability

Nobody outside of the small TeX-community has ever heard of TiKZ. So if you want to give your diagram to somebody and they want to modify anything you have to do it yourself. This is also true for the other direction: if I find some nice design I can copy&paste it easily into a graphics software and in the case of a vector format take it apart, modify and play with it. Even the well written examples from Andrew here take me several minutes to read and understand how he achieved certain tricks, let alone use them myself.

Interactive design

Often with only a vague idea of how it might look 'right' I push and pull things around in a diagram, modify the linewidth, angle of curves or try some fancy effect and the most often used key combination is CTRL+Z to undo the last operation. To go through a compile cycle every time really slows you down a lot if you do not know beforehand how it should look like.

Learning curve

This is something that is hard to admit. I do not like to read manuals, almost all of my colleagues never consult any manual. Now TikZ comes with a well written and beautiful manual. Still, without it you can do absolutely nothing in TikZ. I recently started doing some small stuff in Adobe Illustrator and it also took me a little while to figure out the basics but I feel reasonably productive with it, and I only had to consult the manual for more exotic things or using the builtin Javascript language to automate certain tasks.

One advantage of TikZ that can be invaluable: try with any other software to create a diagram like yours with changing datasets, i.e. a flexible number of elements, labels and numbers. It is painful and can hardly be automated.

Really nice answer! However, regarding the interoperability: You can just give the PDF of your TikZ image to someone else to modify. Inkscape or Adobe Illustrator (or, I guess, most vector drawing programs?) can easily open and edit PDF drawings.
–
JakeApr 19 '12 at 15:51

2

Let me add one more expansion of (2) that applies even if you are in a community of tex users. None of my collaborators have working tikz installations as part of their latex distributions, and are unwilling to fix this. Most of them are happy using inkscape, but are afraid of my tikz diagrams. This means that if I start making diagrams in tikz, I become the designated diagram person on the project.
–
Sam LisiApr 19 '12 at 22:53

What I want here it's to get something flexible because it's a big graph and I think it would be very useful to scale the result. I want to adapt the dimensions and to modify the style easily.

First we need to analyse your example. We can see seven groups of nodes. The main node is Group. The nodes are linked from the left side to the right side and we can see three wrappers in gray.

The first node is easy to draw

\node[main] (shuffle) {Group};

I named this node (shuffle) and I attributed a style named main main/.style={draw,fill=yellow,inner sep=.5em}. I give the value .5em to inner sep because it's more aesthetics when we change the size of the font.

The most important groups of nodes now are Reducer and Mapper. The method is the same for these groups. First we need to decide the distance between (shuffle) and Reducer. I took 48 ex near of 8cm, the distance depends of the size of the font.

update I would like to scale so I made some modifications. It's possible to use (fit) if we use x=...and y=... to scale the picture but in this case I need to use values without units. I write 8 instead of 48 ex etc.

To create the node I used relative coordinate ($(shuffle)+(8,0)$) and I named the node R0,R1+ and R1-. It's easy to understand above + below -.

More complex is the first group S, because we need to use a table inside the nodes, we need to place correctly this table. I used also the relative coordinates and I decide to place the group at 9 ex before the group M. As you can see, the nodes are aligned are have the same width. I decided to use a multipart node. The code is repetitive so I created a macro \tabins

Some remarks : I try to get the same graph, so I needed to make some good choices. To place correctly the table I used [baseline=(Tab.base)it's always the same name for each table but the objects inside this table are on the same baseline that $k_i$.
It's possible to use an array here so I don't give other explanations about this macro because inside the code is relative to TeX and not to TikZ.
Important is the style S/.style={anchor=east} why this ? It's to align all the node to the right !

For the last nodes, problem are very similar and it's more easy.

Now, I need to draw the wrappers, there are a lot of possibilities to draw the wrappers and I don't know exactly what is the best method (It's a future question). I chose a simple method :

Conclusion : 10 minutes to write the code and to get something correct, then some difficulties : the table inside the first column problem with the size and the position but it's a tex's problem not really tikz's problem. The other problem is about the wrapper because, I want to get something useful for my next pictures. Another problem not for me but for a beginner is to understand why (fit) doesn't work with scale ( some answers on this site explains the reason ).

Very nice. I will be having my LaTeX students come to this answer to see the analysis process to get a diagram.
–
R. SchumacherApr 20 '12 at 16:25

Great example! I would like to add it to the TeXample TikZ gallery, I just thought of possible improvements: a Parentheses/.style={execute at begin node=\Big(,execute at end node=\Big)} for inheriting by S, V, P, there's just danger for the \tabins node(parts) which would inherit, but could be a scope instead of a tikzpicture (?) or their style resets the specific outer execution style... using such an effective style saving typing and giving consistency could might be even more to learn.
–
Stefan Kottwitz♦Feb 27 '14 at 9:31

I just wanted to add another novice voice to the answers. I'm not an expert!

Separation of code and data

One big advantage is the separation between code and data. Suppose that you wanted to add another "mapper" or "reducer" to your drawing. Then, with Tikz, you have it so that the drawing is generated by something akin to a function call whose parameters are the values you've written out. This can let you try a lot of variations quickly and effortlessly. (This is a very convincing demo of Tikz for others, in my experience.)

Exact representation

Suppose that you're making a diagram in which some elements have to be exact at positions. I don't know what your click-and-drag software is capable of, but Tikz definitely does that.

Version control

If you're already using version control (backup that lets you see differences with old versions) then because Tikz is text-based, changes that you make to your diagrams are available in version control.

Comments

I don't know how you add explanatory comments to a diagram, but you can embed them right in the tikz code.

Community

Tikz is not easy to learn and there's a lot to it, but we are so lucky to have the tex.stackexchange community who answer our questions. After you've given your problem a really good effort, then I've found this community to be really solid at answering questions.

Diagram generation

Tikz is really powerful. It has mathematical evaluation, loops, and some recursion to help you generate complicated diagrams from relatively little code. (If you need real function calls and lambdas and so on, then you probably have to go to something like Python + matplotlib. One day we will hopefully have Turing-complete Tikz…)

Anyway, like I said, I'm no expert, but my experience has shown Tikz to be really useful in illustrating my work.

Another potential benefit is that TikZ, as with other software discussed on this site, has lower demands on computing hardware when compared with graphical tools.
–
masApr 25 '12 at 8:38

The separation of code and data is an important point. I often set up my axes etc. as I like and then keep my data in a separate file written straight out from Mathematica. When I want to plot a different data set the only part of the code that needs to change is the \input{} that points to the file containing the data.
–
UbiquitousAug 13 '13 at 12:55

I'm going to answer as a longtime user of PStricks. Everything I have to say applies to TikZ as well, but the learning curve for PStricks is longer and steeper than the learning curve for TikZ. (I have done a few TikZ things, but I already know PStricks, and while TikZ is better, it is not enough better to get me to switch.)

Would it pay off for me to learn and understand all principles and techniques of PGF/TikZ?

Probably not. Focus on coordinates, nodes, and paths and you will be able to make a lot of useful drawings.

Would you, as an expert TikZ user, draw a simple diagram like the one below faster than a regular click-and-drag user?

I don't know how fast regular users are. But, I hate "What you see is all you get". I might get an OK diagram quickly, but when I have to get the diagram right, I need to be able to program it. And when I have a group of diagrams that go through multiple revisions, I really benefit from the programmability of TikZ and PStricks.

There's a larger question here, which is what to do about diagrams. Here's what I do:

If I need an adequate diagram quickly, I try to get dot to draw it for me.

If that doesn't work, usually the quickest solution is to scribble something by hand and use a scan or photograph.

If the drawing has to be right, I will almost always use a program to create it. Usually PStricks, sometimes TikZ, sometimes something more specialized.

You may find it useful to know about ktikz and qtikz, which are respectively KDE and QT editors for TikZ diagrams. Perhaps they offer the best of both worlds?

I'm not an expert. I haven't learned all of TikZ. However, when I do produce documents, I do the graphics in TikZ. (For other situations I pen it in hand or use computer drawing software - mostly hand however)

Aspects such as precision, reusability and configurability has already been mentioned, but what I like to benefit from is automation. For example, in one project I several data sets that needed to be plotted. Since TikZ code is just text I was able to automate the generation of these graphics.