# Simple and intuitive tool for generating simple diagrams

I am looking for a simle and intuitive tool for generating simple diagrams to be included in tex document. The graph I want to convert into tex is given below:

Ideally, I would like to end up with tex code, but unfortunately I am at time shortage and need a tool with really low entry threshold. Thus, I would be satisfied with any other graphical tool which may help to generate something like this (favourably, with level adjusting assistant or something like this (Paint will not do the trick ;) )).

• For mz, the implest is pstricks , and more specifically the pst-node module and its \psmatrix environment, as it has a latex-like syntax, and is comparatively well documented. – Bernard May 20 '15 at 14:41
• For that simple matrix-like diagram I'd simply use xypic and its xymatrix command... – Bakuriu May 20 '15 at 16:32

Here's a solution in asymptote using recursion. Just change the first five lines of the code to modify the output. Make sure the number of initial values is a power of 2 or it will probably throw an error.

unitsize(1inch);
real xspacing = 0.5;
real yspacing = 0.5;
pair[] values = { (1,1), (7,9), (2,8), (8,6) };
string[] labels = { "$y_i$", "$d_2$", "$c_2$", "$d_1$", "$c_1$", "$d_0$", "$c_0$"};
// -------------------------------
real xstart = 0.0;
void drawTree(pair[] values, string[] labels, int level = 0)
{
for (int i = 0; i < values.length; ++i)
{
pair loc1 = (xstart + 2 * i * xspacing, -yspacing * level);
pair loc2 = (xstart + (2 * i + 1) * xspacing, loc1.y);
if (level == 0)
{
label(string(values[i].x), loc1);
label(string(values[i].y), loc2);
}
pair loc3 = (loc1 + loc2) / 2.0 - (0, yspacing);
label(string(values[i].y - values[i].x), loc3);
pair loc4 = loc3 - (0, yspacing);
label(string(values[i].y + values[i].x), loc4);
draw(subpath(loc1--loc3, 0.15, 0.85), 0.3+dashed, Arrow);
draw(subpath(loc2--loc3, 0.15, 0.85), 0.3+dashed, Arrow);
draw(subpath(loc1--loc4, 0.07, 0.93), 0.3+black, Arrow);
draw(subpath(loc2--loc4, 0.07, 0.93), 0.3+black, Arrow);
}
if (level == 0)
{
real x = 2 * values.length * xspacing;
for (int i = 0; i < labels.length; ++i)
{
label(labels[i], (x, -i * yspacing));
}
}
if (values.length < 2) { return; }
pair[] newvalues;
for (int i = 0; i < values.length; i += 2)
{
newvalues.push((values[i].x + values[i].y, values[i+1].x + values[i+1].y));
}
xstart += xspacing / 2.0;
xspacing *= 2.0;
drawTree(newvalues, labels, level + 2);
}
drawTree(values, labels);

• Hi @James! In fact, I like your solution the most. I like the recursion code concept and the fact you have caught the "mathematical idea" behind the tree. – Marta Karas May 20 '15 at 18:41
• I have just realised that I am not perfectly sure how to use the piece of code you have supplied. I believe it is tex code (I was not aware I can perform loops and Arrays there) but I am not sure if I should include it between \begin{document} ... \end{document} clauses and if any additional packages should be supplied. – Marta Karas May 20 '15 at 19:02
• You need to compile it with Asymptote - the executable is called asy and (by default) it produces a PDF that you can include in your TeX source with \includegraphics – Thruston May 20 '15 at 19:15
• Thank you! I work under Ubuntu and I quickly compiled it in Texmaker. The only think to change in default Texmaker environment was a build way which I set as "Asymptote" (see pic). The "View PDF" was unavailable, but the PDF was created as a result of compilation (in the asy file firectory). – Marta Karas May 20 '15 at 19:30

My first choice would be pgfplots and tikz. It lets you draw right in Latex.

You can try something like this:

\documentclass[a4paper]{article}

\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw [->] (12,4)node[above]{24} -- (8,0)node[below]{42};
\draw [->] (4,4)node[above]{18} -- (8,0);
\node at (17,0)[right]{$c_0$};
\draw [->,dashed] (12,4) -- (8,2);
\draw [->,dashed] (4,4) -- (8,2);
\node at (17,2) [right]{$d_0$};
\node at(17,4) [right]{$c_1$};
\end{tikzpicture}
\end{document}

I just started on the image you postet. The result will look like this:

Hope this gets you on track.

• Welcome to the site. Perhaps editing your answer to include a graphic of the result would improve the quality of your answer. – Steven B. Segletes May 20 '15 at 14:44
• Hi @Ben! Thank you for your answer (+1). I wish I coould mark everyone's correct answer as answer and assign points to them. I really appreciate your inpact. – Marta Karas May 20 '15 at 18:33

I also suggest Tikz, but more specifically the Tikz trees. Probably you could automatise this but I can't think of a way so the solution is manual. I was going to provide a small sample for you to complete, but I had already finished it on my own, so here it is.

Basically the level distance is 2cm but the middle child is shifted down of 1cm so it's midway and the nodes on the side have a level distance of 1cm so they align properly.

The empty arrow tip is done thanks to the arrows.meta library. You can see more tips in the chapter "16.5 Reference: Arrow Tips", page 203, of the Tikz Manual (v 3.0.0).

## Code

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\usetikzlibrary{arrows.meta,positioning}

\tikzset{
kit/.style={dashed,<-,>={Kite[open]}},
}

\begin{document}

\begin{tikzpicture}[%
level distance=2cm,
level 1/.style={sibling distance=3cm},
level 2/.style={sibling distance=1.5cm},
level 3/.style={sibling distance=8mm},
rightn/.style={level distance=1cm},
<-,>={Latex},
no edge/.style={
edge from parent/.style={draw=none}}]

\node (root) {42} [grow=up]
child{node (24) {24}
child{node (14r) {14}
child{node (6b) {6}}
child[no edge]{node[yshift=-1cm] (2m) {-2}}
child{node (8r) {8}}
}
child[no edge]{node[yshift=-1cm] (4) {4}}
child{node (10) {10}
child{node (8l) {8}}
child[no edge]{node[yshift=-1cm] (6c) {6}}
child{node (21) {2}}
}}
child[no edge]{node[yshift=-1cm] (6) {6}}
child{node (18) {18}
child{node (16) {16}
child{node (9) {9}}
child[no edge]{node[yshift=-1cm] (2b) {2}}
child{node (7) {7}}
}
child[no edge]{node[yshift=-1cm] (14l) {14}}
child{node (2) {2}
child{node (1r) {1}}
child[no edge]{node[yshift=-1cm] (0) {0}}
child{node (1l) {1}}
}
};

\node[right=6cm of root,level distance=1cm] {$c_0$} [grow=up]
child[no edge,rightn]{node {$d_0$}
child[no edge,rightn]{node {$c_1$}
child[no edge,rightn]{node {$d_1$}
child[no edge,rightn]{node {$c_2$}
child[no edge,rightn]{node {$d_2$}
child[no edge,rightn]{node {$y_i$}}
}}}}};

\draw[kit] (6) edge (18) edge (24);
\draw[kit] (14l) edge (16) edge (2);
\draw[kit] (4) edge (14r) edge (10);
\draw (0) edge (1r) edge (1l);
\draw (2b) edge (7) edge (9);
\draw (6c) edge (21) edge (8l);
\draw (2m) edge (8r) edge (6b);
\end{tikzpicture}
\end{document}
• Thank you @Alenanno for your inpact, especially for mentioning the Tikz trees! – Marta Karas May 20 '15 at 18:39

Starting with Ben's tikzpicture module, and turning it into a macro

\blivet[supress top #]{top-left #}{top-right #}{width}

has allowed me a start on it. More automation remains to be done. The height of the blivets are defined with \def\blivetheight{3}.

\documentclass[a4paper]{article}
\usepackage{pgfplots,stackengine}
\setstackEOL{\\}\setstackgap{S}{-5pt}
\usepackage{tikz}
\def\blivetheight{3}
\newcommand\blivet[4][\relax]{%
\ifx\relax#1%
\def\topleft{#2}\def\topright{#3}%
\else
\def\topleft{}\def\topright{}%
\fi
\makebox[#4cm]{\begin{tikzpicture}
\draw [->] (#4,\blivetheight)node[above]{\topright} --
(#4/2,0)node[below]{\the\numexpr#2+#3\relax};
\draw [->] (0,\blivetheight)node[above]{\topleft} -- (#4/2,0);
\draw [->,dashed] (#4,\blivetheight) -- (#4/2,\blivetheight/2)%
node[below]{\the\numexpr#3-#2\relax};
\draw [->,dashed] (0,\blivetheight) -- (#4/2,\blivetheight/2);
\end{tikzpicture}
}}
\newcommand\gap[1]{\unskip\hspace{#1cm}\ignorespaces}
\begin{document}
\Shortstack{
\blivet{1}{1}{1.5}\gap{1.5}\blivet{7}{9}{1.5}\gap{1.5}
\blivet{2}{8}{1.5}\gap{1.5}\blivet{8}{6}{1.5}\\
\blivet[x]{2}{16}{3}\gap{3}\blivet[x]{10}{14}{3}\\
\blivet[x]{18}{24}{6}