# TikZ pyramid hierarchy colour

I have a TikZ pyramid hierarchy, however I was wondering whether there was a way of filling the different tiers with colours. My current code is:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}
\coordinate (A) at (-5,0) {};
\coordinate (B) at ( 5,0) {};
\coordinate (C) at (0,7) {};
\draw[name path=AC] (A) -- (C);
\draw[name path=BC] (B) -- (C);
\foreach \y/\A in {0/Non-League, 1.5/League Two,2.5/ League One,3.5/Championship,4.5/Premier League} {
\path[name path=horiz] (A|-0,\y) -- (B|-0,\y);
\draw[name intersections={of=AC and horiz,by=P},
name intersections={of=BC and horiz,by=Q}] (P) -- (Q)
node[midway,above] {\A};
}
\end{tikzpicture}
\end{document}


You have two ways of doing the fill, but actually there is a much simpler way to draw your pyramid. We basically define a triangle that clips all the filled rectangles we position. Plus an extra fill for the last element of your foreach.

The first way includes a list of colors in an array. We add a count to your foreach and use that to select the colors. Since the array has an automatic numerical index 0,1,2,3,..., we used the count for that.

The second way instead uses the count to draw a gradation, thanks to the evaluate option, multiplying the count by a certain number. Now, if you have 10 rectangles, it's best to do count*10 so each rectangle is

color1!0!color2
color1!10!color2
color1!20!color2
color1!30!color2


And so on. But you can select any number, as long as you're happy with the result. For this last solution you can also use a single color of course, color!## which is short for color!##!white so that the higher the number, the more it's mixed with white.

## Code

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections,backgrounds}
\begin{document}

% List of colors
\begin{tikzpicture}
\def\colorlist{{"cyan", "red", "orange", "yellow", "green", "gray", "blue", "violet"}}

\foreach \y/\A [count=\xi starting from 0, evaluate=\y as \nexty using (\y+1.5, evaluate=\xi as \grad using int(\xi*15)] in {0/Non-League, 1.5/League Two,2.5/ League One,3.5/Championship,4.5/Premier League} {%
\pgfmathsetmacro\myfill{\colorlist[\xi]}
\begin{scope}[on background layer]
\clip[preaction={draw}] (-5,0) -- (5,0) -- (0,7) -- cycle;
\fill[\myfill] (-5,\y) rectangle (5,\nexty);
\fill[\myfill] (-5,4.5) rectangle (5,7);
\end{scope}
\node at (0,\y+.3) {\A};
}
\end{tikzpicture}

\begin{tikzpicture}[xshift=5cm]
\foreach \y/\A [count=\xi starting from 0, evaluate=\y as \nexty using (\y+1.5, evaluate=\xi as \grad using int(\xi*15)] in {0/Non-League, 1.5/League Two,2.5/ League One,3.5/Championship,4.5/Premier League} {%
\begin{scope}[on background layer]
\clip[preaction={draw}] (-5,0) -- (5,0) -- (0,7) -- cycle;
\end{scope}
\node at (0,\y+.3) {\A};
}
\end{tikzpicture}
\end{document}

• @DanielRawlings In case you didn't know, if the answer solved your problem, consider ticking it as the accepted answer by clicking on the √ near the top left. – Alenanno Feb 18 '16 at 16:32

Using simple triangle paths, we can fill the paths with predetermined colors or with gradients as a function of the counter \i of the loop below. x and y can be changed for best appearance.

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

\begin{tikzpicture}[x=2.5cm,y=2cm]
\coordinate (A) at (-3,-1) {};
\coordinate (B) at (3,-1) {};
\coordinate (C) at (0,5) {};
\foreach \A/\col [count=\i] in {Non-League/green, League Two/cyan,League One/yellow,Championship/blue,Premier\\League/orange}
\draw[fill=\col] (C)--([shift={(-.5*\i,1*\i)}]B)--node[above,align=center] {\A}([shift={(.5*\i,1*\i)}]A)--cycle;
\end{tikzpicture}

\end{document}


\foreach \A/\col [count=\i,evaluate=\i as \j using 10*\i] in {Non-League, League Two,League One,Championship,Premier\\League}