What is the simplest way to obtain the following tree like graph ?
- 13,315
-
1what you try so far? – Zarko Feb 15 '18 at 15:12
-
62877 reputation points without a MWE? Please look at tikz-cd package – CarLaTeX Feb 15 '18 at 15:13
-
Low connection so I can't really work with internet but you are both right ! – projetmbc Feb 15 '18 at 21:28
4 Answers
The TikZ graphs library can do this quite simply:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs}
\begin{document}
\begin{tikzpicture}
\graph[branch right, grow down]
{a[x=1] <- {{b <- {d[x=-1],e}}, {c <- {e,f[x=1]}}}};
\end{tikzpicture}
\end{document}
If you want the graph to be more compact, like your image, you can reduce the branch width. Since the node adjustments depend on that width too, it's best to use a macro like this:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs}
\newcommand*{\bw}{.5}
\begin{document}
\begin{tikzpicture}
\graph[branch right=\bw, grow down]
{a[x=\bw] <- {{b <- {d[x=-\bw],e}}, {c <- {e,f[x=\bw]}}}};
\end{tikzpicture}
\end{document}
- 218,180
-
Thanks. Is there a way to use a text difeernt from the name of the node ? I need to put the same texts at different places in the graph. – projetmbc Feb 16 '18 at 09:12
-
@projetmbc No, I don't think you can do that with this kind of syntax. – Alan Munn Feb 16 '18 at 13:14
Easy and simple too with a psmatrix environment:
\documentclass{article}
\usepackage{pst-node}
\usepackage{auto-pst-pdf} %% to compile with pdflatex --enable-write18 (MiKTeX) or pdflatex --shell-escape (TeX Live, MacTeX))
\begin{document}%
\begin{psmatrix}[rowsep=1cm, colsep=0.9cm]
& &[name=a] a \\
& [name=b] b & & [name=c] c \\
[name=d] d & & [name=e] e & & [name=f] f
\foreach \beg/\targ in {b/a, c/a, d/b, e/b, e/c, f/c}{\ncline[arrows=->, arrowinset=0.12, nodesep=3pt]{\beg}{\targ}}
\end{psmatrix}
\end{document}
- 271,350
Another alternative since the graph is very simple using tikz-cd.
\documentclass{article}
\usepackage{tikz-cd}
\usepackage{amsmath}
\begin{document}
\begin{tikzcd}
& & a & & \\
& b \arrow[ru] & & c \arrow[lu] & \\
d \arrow[ru] & & e \arrow[lu] \arrow[ru] & & f \arrow[lu]
\end{tikzcd}
\end{document}
For the your question you can see this link to modificate the type of the arrows: Is it possible to change the size of an arrowhead in TikZ/PGF?
Below new example. I have modificated the thick of one arrow.

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{arrows}
\usepackage{amsmath}
\begin{document}
\begin{tikzcd}
& & a & & \\
& b \arrow[-triangle 90,
line width=.8mm,ru] & & c \arrow[lu] & \\
d \arrow[ru] & & e \arrow[lu] \arrow[ru] & & f \arrow[lu]
\end{tikzcd}
\end{document}
- 54,118
A hurried attempt with MetaPost and its boxes package, included in a LuaLaTeX program.
\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
input boxes;
def junction(suffix a, b) =
drawarrow a.c -- b.c cutbefore bpath.a cutafter bpath.b;
enddef;
h := 1.25cm; v := 1cm;
beginfig(1);
forsuffixes z = a, b, c, d, e, f: circleit.z(str z); endfor;
e.c = origin; f.c = (h, 0) = - d.c;
b.c = (-.5h, v); c.c = (.5h, v);
a.c = (0, 2v);
drawunboxed(a, b, c, d, e, f);
junction (b, a); junction(c, a);
junction(d, b); junction(e, b);
junction(e, c); junction(f, c);
endfig;
\end{mplibcode}
\end{document}
It could certainly have been more proficiently coded if I had used, for example, the metaobj package, but I don't know it well enough.
- 18,756
-
I congratulate you for your answer. I had not used MetaPost for at least ten years ago. +1 – Sebastiano Feb 19 '18 at 10:46





