3

I am working on a Math Project involving football matches. I hope I can produce a tree diagram like this. Could anyone help me with the basic code? I feel producing this diagram requires tikz, which I am not good at. Thanks for your help! enter image description here

By the way, I do not need the text regarding the date and the place of the matches. Thanks again for your attention!

3

This is a forest solution which involves a little less typing than some other possibilities.

The basic idea is to see the diagram as a tree with an invisible root note on the far right. This has two children: the final and the detached third place match. To avoid affecting the main tree, the detached node is drawn after all of the other nodes are typeset and their positions set.

matchnode={<flag-1>}{<team-1>}{<score-1>}{<flag-2>}{<team-2>}{<score-3>} is a style used to define the tabular content for each match. Each <flag> should be the name of the image file containing the relevant <team>'s flag.

round name={<name>} is a style used to define the competition stages marked at the top. The title of the third place match is added directly to the relevant node, since this is a one off.

The colours are set as lineblue, fillblue and textblue. The overall appearance of all nodes is set using the footnode style which can be modified as desired. The general shape and thickness of the branches is set using forest's edge. If you want straight edges, for example, just say edge={ultra thick}, removing the rounded corners... specification.

\PassOptionsToPackage{dvipsnames,svgnames,x11names,rgb,table}{xcolor}
\documentclass[tikz,border=10pt]{standalone}
\usepackage{array,forest}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usetikzlibrary{positioning,shadows}
\colorlet{textblue}{blue!75!black}
\colorlet{lineblue}{blue}
\colorlet{fillblue}{blue!10}
\newlength\Tht
\settoheight{\Tht}{T}
\begin{document}
\arrayrulecolor{lineblue}
\begin{forest}
  /tikz/footnode/.style={
    font=\sffamily,
    text=textblue,
    draw=lineblue,
    inner color=fillblue!75,
    outer color=fillblue,
    drop shadow,
    rounded corners=1pt,
  },
  matchnode/.style n args=6{
    footnode,
    inner sep=0pt,
    content={\includegraphics[height=\Tht]{#1} \textcolor{textblue}{#2}&\textcolor{black}{#3}\\\hline\includegraphics[height=\Tht]{#4} \textcolor{textblue}{#5}&\textcolor{black}{#6}},
  },
  round name/.style={
    tikz={\node [above=of .center |- pen.north, anchor=mid, footnode, minimum height=4ex] {#1};}
  },
  match align/.style={
    align={l|c},
    parent anchor=west,
    child anchor=east,
    anchor=west,
  },
  for tree={
    edge path={
      \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(-10pt,0) |- (.child anchor)\forestoption{edge label};
    },
    l sep+=20pt,
    match align,
    grow=180,
    edge={ultra thick, rounded corners},
    footnode,
    tier/.wrap pgfmath arg={tier #1}{level()},
  },
  [, phantom,
    before drawing tree={
      append={[, match align, matchnode={example-image-a}{Team E}{0}{example-image-b}{Team M}{2}, typeset node, afterthought={\node [above=10pt of .north, anchor=south, footnode, minimum height=4ex] {Third place};}]},
    }
    [, matchnode={example-image-a}{Team A}{1}{example-image-b}{Team I}{0}, round name=Final
      [, matchnode={example-image-a}{Team A}{1}{example-image-b}{Team E}{0}, round name=Semi-Finals
        [, matchnode={example-image-a}{Team A}{1}{example-image-b}{Team C}{0}, round name=Quarter-Finals
          [, matchnode={example-image-a}{Team A}{1}{example-image-b}{Team B}{0}, name=pen, round name=Round of 16]
          [, matchnode={example-image-a}{Team C}{1}{example-image-b}{Team D}{0}]
        ]
        [, matchnode={example-image-a}{Team E}{2}{example-image-b}{Team G}{1}
          [, matchnode={example-image-a}{Team E}{1}{example-image-b}{Team F}{0}]
          [, matchnode={example-image-a}{Team G}{1}{example-image-b}{Team H}{0}]
        ]
      ]
      [, matchnode={example-image-a}{Team I}{1}{example-image-b}{Team M}{0}
        [, matchnode={example-image-a}{Team I}{1}{example-image-b}{Team K}{0}
          [, matchnode={example-image-a}{Team I}{0 (4)}{example-image-b}{Team J}{0 (2)}]
          [, matchnode={example-image-a}{Team K}{1}{example-image-b}{Team L}{0}]
        ]
        [, matchnode={example-image-a}{Team M}{1}{example-image-b}{Team O}{0}
          [, matchnode={example-image-a}{Team M}{1}{example-image-b}{Team N}{0}]
          [, matchnode={example-image-a}{Team O}{1}{example-image-b}{Team P}{0}]
        ]
      ]
    ]
  ]
\end{forest}

\end{document}

football world cup

EDIT

Here's another version which uses a freeware font to supply the flag symbols, and a colour series to randomly apply colours to them. Instead of specifying the image file of the relevant flag, the first and fourth arguments of the matchnode style now specify the relevant character from the freeware font.

This solution requires lualatex. Note that xelatex will NOT work. (And, of course, pdflatex, latex etc. won't either as the code requires fontspec.)

\PassOptionsToPackage{dvipsnames,svgnames,x11names,rgb,table}{xcolor}
\documentclass[tikz,border=10pt]{standalone}
\usepackage{array,forest}
\usepackage{fontspec}
\newfontfamily\fflag{Flags.ttf}
\usetikzlibrary{positioning,shadows}
\colorlet{textblue}{blue!75!black}
\colorlet{lineblue}{blue}
\colorlet{fillblue}{blue!10}
\newlength\Tht
\settoheight{\Tht}{T}
% xcolor manual: 34
\definecolorseries{colours}{hsb}{grad}[hsb]{.575,1,1}{.987,-.234,0}
\resetcolorseries[12]{colours}
\begin{document}
\arrayrulecolor{lineblue}
\begin{forest}
  /tikz/footnode/.style={
    font=\sffamily,
    text=textblue,
    draw=lineblue,
    inner color=fillblue!75,
    outer color=fillblue,
    drop shadow,
    rounded corners=1pt,
  },
  matchnode/.style n args=6{
    footnode,
    inner sep=0pt,
    content={\raisebox{-.25em}{\fflag\color{colours!!+}#1} \textcolor{textblue}{#2}&\textcolor{black}{#3}\\\hline\raisebox{-.25em}{\fflag\color{colours!!+}#4} \textcolor{textblue}{#5}&\textcolor{black}{#6}},
  },
  round name/.style={
    tikz={\node [above=of .center |- pen.north, anchor=mid, footnode, minimum height=4ex] {#1};}
  },
  match align/.style={
    align={l|c},
    parent anchor=west,
    child anchor=east,
    anchor=west,
  },
  for tree={
    edge path={
      \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(-10pt,0) |- (.child anchor)\forestoption{edge label};
    },
    l sep+=20pt,
    match align,
    grow=180,
    edge={ultra thick, rounded corners},
    footnode,
    tier/.wrap pgfmath arg={tier #1}{level()},
  },
  [, phantom,
    before drawing tree={
      append={[, match align, matchnode={E}{Team E}{0}{M}{Team M}{2}, typeset node, afterthought={\node [above=10pt of .north, anchor=south, footnode, minimum height=4ex] {Third place};}]},
    }
    [, matchnode={A}{Team A}{1}{I}{Team I}{0}, round name=Final
      [, matchnode={A}{Team A}{1}{E}{Team E}{0}, round name=Semi-Finals
        [, matchnode={A}{Team A}{1}{C}{Team C}{0}, round name=Quarter-Finals
          [, matchnode={A}{Team A}{1}{B}{Team B}{0}, name=pen, round name=Round of 16]
          [, matchnode={C}{Team C}{1}{D}{Team D}{0}]
        ]
        [, matchnode={E}{Team E}{2}{G}{Team G}{1}
          [, matchnode={E}{Team E}{1}{F}{Team F}{0}]
          [, matchnode={G}{Team G}{1}{H}{Team H}{0}]
        ]
      ]
      [, matchnode={I}{Team I}{1}{M}{Team M}{0}
        [, matchnode={I}{Team I}{1}{K}{Team K}{0}
          [, matchnode={I}{Team I}{0 (4)}{J}{Team J}{0 (2)}]
          [, matchnode={K}{Team K}{1}{L}{Team L}{0}]
        ]
        [, matchnode={M}{Team M}{1}{O}{Team O}{0}
          [, matchnode={M}{Team M}{1}{N}{Team N}{0}]
          [, matchnode={O}{Team O}{1}{P}{Team P}{0}]
        ]
      ]
    ]
  ]
\end{forest}

\end{document}

Font flag version with LuaLaTeX

The font I used is 'Flags' by Sunwalk and is available here.

5

By defining a basic block style and using nodes alignment, this is one possibility.

enter image description here

Code

\documentclass[border=15pt]{standalone}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{positioning,arrows,calc}
\tikzset{block/.style = {rectangle, draw,fill=blue!10,
text width=5cm, minimum height=0.5cm},
}
\begin{document}
\begin{tikzpicture}
\path (0,0) 
node[block,text centered](a){Round of 16} 
node[block,text centered,right=2cm of a](b){Quarter-finals}
node[block,text centered,right=2cm of b](c){Semi-finals}
node[block,text centered,right=2cm of c](d){Finals};

\node[block,below=0.5cm of a]  (r1){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r1]   (r2){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r2] (r3){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r3]   (r4){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r4] (r5){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r5]   (r6){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r6] (r7){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r7]   (r8){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r8] (r9){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r9]   (r10){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r10](r11){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r11]  (r12){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r12](r13){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r13]  (r14){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r14](r15){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r15]  (r16){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
%------------
\node[block,below=1.5cm of b] (q1){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of q1]  (q2){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};
\node[block,below=2.8cm of q2](q3){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of q3]  (q4){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};
\node[block,below=2.8cm of q4](q5){\includegraphics[scale=0.05]{example-image-a} Brasil\hfill1(2)};
\node[block,below=0cm of q5]  (q6){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};
\node[block,below=2.8cm of q6](q7){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of q7]  (q8){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};

%-------------semifinal
\node[block,below=3.6cm of c] (s1){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of s1]  (s2){\includegraphics[scale=0.05]{example-image-b}\, Germany\hfill1(2)};
\node[block,below=7.5cm of s2](s3){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of s3]  (s4){\includegraphics[scale=0.05]{example-image-b}\,Germany\hfill 1(2)};
%--------- final
\node[block,below=8cm of d] (f1){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of f1](f2){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};
\node[block,below=3cm of f2,text centered]{Third places};
\node[block,below=4cm of f2](t1){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of t1](t2){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};

%---- connecting lines

\foreach \i/\j/\k in {1/3/1,5/7/3,9/11/5,13/15/7}{
\draw[thick] (r\i.south east) -- +(1,0) |- (q\k.south west);
\draw[thick] (r\j.south east) -- +(1,0) |- (q\k.south west);
}

\foreach \i/\j/\k in {1/3/1,5/7/3}{
\draw[thick] (q\i.south east) -- +(1,0) |- (s\k.south west);
\draw[thick] (q\j.south east) -- +(1,0) |- (s\k.south west);
}
\foreach \i/\j/\k in {1/3/1}{
\draw[thick] (s\i.south east) -- +(1,0) |- (f\k.south west);
\draw[thick] (s\j.south east) -- +(1,0) |- (f\k.south west);
}

\def\box{1.5cm}
\foreach \i/\j in {1/2,3/4,5/6,7/8,9/10,11/12,13/14,15/16}{
\draw[thick] ([xshift=\box]r\i.north) -- ([xshift=\box]r\j.south);
}
\foreach \i/\j in {1/2,3/4,5/6,7/8}{
\draw[thick] ([xshift=\box]q\i.north) -- ([xshift=\box]q\j.south);
}
\foreach \i/\j in {1/2,3/4}{
\draw[thick] ([xshift=\box]s\i.north) -- ([xshift=\box]s\j.south);
}
\foreach \i/\j in {1/2}{
\draw[thick] ([xshift=\box]f\i.north) -- ([xshift=\box]f\j.south);
}
\draw[thick] ([xshift=\box]t1.north) -- ([xshift=\box]t2.south);
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.