2

If one were to write a large piece of text and wanted to include a diagram like the two shown below, what is the easiest and simplest way to do so with LaTeX? By "simple" and "easy" I mean - if possible - without using any additional packages or - again: if possible - at least without using large and powerful (but also slowing down) packages like TikZ and PGF (or derivatives like smartdiagram, etc.).

Still, it would be nice if one could use both lines as well as dotted lines or other kinds of lines like: - - - - -

Of course I would also be interested in how to do it with Tikz, but if it is possible to avoid all those magical tools, then I'd prefer a non-tikz-solution. Or, should you tell me that using tikz won'T slow donw the compiling process, then I'd be happy to use tikz.

diagram1 diagram2

2
  • 3
    If it's just labels and lines, and you want it to be fast then use the picture environment. (en.wikibooks.org/wiki/LaTeX/Picture)
    – Thruston
    Jun 7, 2014 at 14:16
  • It seems your diagrams are not too simple after all. The readability and "symbolic" means of description of TikZ make the code much easier to maintain and modify/reuse. The slowdown won't be noticeable if you do not have many pictures; you can always resort to using its external library to precompile the pictures once for all...
    – Bordaigorl
    Jun 12, 2014 at 14:06

1 Answer 1

3

Although TikZ might indeed be "magical" as you say, I think it is quite easy to understand and harness to your desires. Diagrams like the ones you have will not increase the compiling time, so I think TikZ is your best choice, also if you want to customize the line styles, which TikZ makes very easy. So here is the code for the first diagram you have:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\node (a) at (0,0) {A};
\node (b) at (2,.7) {B};
\node (c) at (2,-.7) {C};
\node (d) at (4,1.1) {D};
\node (e) at (4,.3) {E};
\node (f) at (4,-.7) {F};
\node (g) at (6,-.3) {G};
\node (h) at (6,-1.1) {H};
\foreach \x\y in {a/b,a/c,b/d,b/e,c/f,f/g,f/h}{
  \draw[line width=1pt] (\x)--(\y);
}
\end{tikzpicture}

\end{document}

The commands are pretty self-explanatory, \node puts a node where you tell it to, and \draw draws a line between two points. All the positions are given in Cartesian coordinates. I used a \foreach loop to draw the lines between the nodes (which are named with lowercase letters). Options for commands are put in square braces [...] like for \draw[line width=1pt], which says that the width of line to be drawn is 1pt thick. To make the lines dashed, use \draw[dashed], or for more variety, \draw[densely dashed] or \draw[loosely dashed]. Also, to only make some of the lines dashed (instead of them all being the same by the \foreach loop), just take out (say) a/b from the curly-bracketed list in the \foreach line, and make a new line with \draw[dashed] (a)--(b);. This is the result of the code above:

enter image description here

The second diagram has the same ideas, so I won't repeat all of it. The only things that change are that you have arrow tips and one of the lines is curved. All of that is easily taken care of in TikZ. So here is the code for the part that has the curved line:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\node (gamma) at (0,0) {$\gamma$};
\node (z) at (-1.5,-4) {Z};
\node (w) at (-.5,-2) {W};
\node (j) at (.5,-2) {J};
\draw[->,>=latex] (gamma)--(w);
\draw[->,>=latex] (gamma)--(j);
\draw[->,>=latex] (gamma) to [bend right=10] (z);
\end{tikzpicture}

\end{document}

Note that now the \draw command has options ->, which means draw an arrow tip at the end of the line, and >=latex, which means the arrow tip is of the style latex (there are tons of different arrow tip styles). Options for commands are separated by a comma ,. Also, the line that bends has an option in the middle of the directive (also note that (a)--(b) may be replaced with (a) to (b), but the latter is needed when you add options like bending), and that can be changed to bend left, and the angle (in this case 10) can also be changed to make it curve more. Here is the result:

enter image description here

I think all this stuff is pretty simple, no? Compiling these pictures will not slow down the whole process, and now you have a powerful tool at your disposal.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .