# How can I draw a tree like this?

I want to draw the following tree in a question. But, I don't want to upload a picture. Can anyone tell me how to do it using MathJax?

• Why don't you want to upload a picutre? I don't believe it's possible to replicate this with MathJax... – Najib Idrissi Apr 20 '16 at 10:19
• See How could I add a graph to a post at MSE? and some other questions on meta tagged (images). – Martin Sleziak Apr 20 '16 at 11:28
• As far as I know, diagonal lines are not possible with any graph-drawing environment (namely amscd) available for use on the website. – pjs36 Apr 20 '16 at 12:46
• It would be nice if TikZ were supported by MathJax, but it's not. Uploading a picture may be your only option. – Cheerful Parsnip Apr 20 '16 at 13:26
• Som older questions related to TikZ: meta.math.stackexchange.com/questions/9545/… and meta.math.stackexchange.com/questions/3190/… – Martin Sleziak Apr 20 '16 at 13:29
• Hmm... Seems like it's the only way. Sad. Anyways, thank you for the input. – SinTan1729 Apr 20 '16 at 15:43
• You can find an image of (probably) that tree in this answer of mine. Feel free to use it if you wish/need. – Massimo Ortolano Apr 30 '16 at 19:54

It can be done in MathJax, but it is painful and a complete hack. Here is one way:

\require{enclose}
\def\uline#1#2{\enclose{updiagonalstrike}{\phantom{\Rule{#1em}{#2em}{0em}}}}
\def\dline#1#2{\enclose{downdiagonalstrike}{\phantom{\Rule{#1em}{#2em}{0em}}}}
%
\def\place#1#2#3{\smash{\rlap{\hskip{#1em}\raise{#2em}{#3}}}}
%
\hskip 1em
%
\place{0}{12}{\bullet}
\place{2}{0}{\bullet}
\place{4}{4}{\bullet}
\place{6}{0}{\bullet}
\place{8}{8}{\bullet}
\place{10}{0}{\bullet}
\place{12}{4}{\bullet}
\place{14}{0}{\bullet}
\place{16}{12}{\bullet}
%
\place{.3}{4.4}{\dline{3.6}{7.6}}
\place{2.3}{.5}{\uline{1.6}{3.6}}
\place{4.3}{.4}{\dline{1.6}{3.6}}
\place{4.3}{4.4}{\uline{3.6}{3.7}}
\place{8.3}{4.4}{\dline{3.6}{3.6}}
\place{10.3}{.5}{\uline{1.6}{3.6}}
\place{12.3}{.4}{\dline{1.6}{3.6}}
\place{12.2}{4.4}{\uline{3.7}{7.6}}
%
\place{-1}{12.5}{\frac01}
\place{1}{-.5}{\frac13}
\place{2.75}{4}{\frac12}
\place{6.5}{-.5}{\frac23}
\place{7.75}{9.5}{\frac11}
\place{9}{-.5}{\frac32}
\place{12.75}{4}{\frac21}
\place{14.5}{-.5}{\frac31}
\place{16.5}{12.5}{\frac10}
%
\hskip18em\Rule{0em}{14em}{1.5em}


which produces

$$\require{enclose} \def\uline#1#2{\enclose{updiagonalstrike}{\phantom{\Rule{#1em}{#2em}{0em}}}} \def\dline#1#2{\enclose{downdiagonalstrike}{\phantom{\Rule{#1em}{#2em}{0em}}}} % \def\place#1#2#3{\smash{\rlap{\hskip{#1em}\raise{#2em}{#3}}}} % \hskip 1em % \place{0}{12}{\bullet} \place{2}{0}{\bullet} \place{4}{4}{\bullet} \place{6}{0}{\bullet} \place{8}{8}{\bullet} \place{10}{0}{\bullet} \place{12}{4}{\bullet} \place{14}{0}{\bullet} \place{16}{12}{\bullet} % \place{.3}{4.4}{\dline{3.6}{7.6}} \place{2.3}{.5}{\uline{1.6}{3.6}} \place{4.3}{.4}{\dline{1.6}{3.6}} \place{4.3}{4.4}{\uline{3.6}{3.7}} \place{8.3}{4.4}{\dline{3.6}{3.6}} \place{10.3}{.5}{\uline{1.6}{3.6}} \place{12.3}{.4}{\dline{1.6}{3.6}} \place{12.2}{4.4}{\uline{3.7}{7.6}} % \place{-1}{12.5}{\frac01} \place{1}{-.5}{\frac13} \place{2.75}{4}{\frac12} \place{6.5}{-.5}{\frac23} \place{7.75}{9.5}{\frac11} \place{9}{-.5}{\frac32} \place{12.75}{4}{\frac21} \place{14.5}{-.5}{\frac31} \place{16.5}{12.5}{\frac10} % \hskip18em\Rule{0em}{14em}{1.5em}$$

It allows you to define an abstract grid on which you place the items you want (bullets for dots, fractions, and diagonal lines created using the enclose package). I also use \hskip and \Rule to define the size of the complete diagram, and an \hskip at the front to compensate for the use of -1 for the left-most labels.

Anyway, you can make these kinds of diagrams with some effort.

• I'd like to mention this doesn't work on the iOS app – KoA Apr 22 '16 at 5:28
• The numbers after place, for example \place{2}{0} are relative coordinates with respect to previous position? Or are they absolute coordinates? – Martin Sleziak Apr 22 '16 at 7:54
• @shieldbug1 And I can confirm that it does not render correctly on the mobile version of the site, using iOS's Safari (but switching to the "full site" in Safari still, it does work). Very interesting answer, either way! – pjs36 Apr 22 '16 at 12:29
• @MartinSleziak, they are absolute with respect to the lower left-hand corner of the graph. – Davide Cervone Apr 22 '16 at 13:10
• Thx for this great hack. $+1$ The diagram flooted on the code out of the screen though. – GNUSupporter 8964民主女神 地下教會 Dec 4 '18 at 5:05
• Here's what it looks like on an Android phone; viz., a ZTE Blade V8. – Shaun Dec 9 '18 at 2:13
• Here's what it looks like on the same phone but using the desktop site. – Shaun Dec 9 '18 at 2:15