I am trying to create a legend inside a tikzpicture
. The picture shows an accelerator and I would like to make a legend that will explain each part.
My code is
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\definecolor{tank}{RGB}{98,190,177}
\makeatletter
\pgfdeclareshape{slit}{
\savedanchor\centerpoint{\pgf@x=0cm\pgf@y=0cm}
\saveddimen\halfwidth{
\pgf@x=.25cm
\pgfmathsetlength\pgf@xa{.5*\pgfkeysvalueof{/pgf/minimum width}}
\ifdim\pgf@x<\pgf@xa\pgf@x=\pgf@xa\fi}
\saveddimen\halfheight{
\pgf@x=.25cm
\pgfmathsetlength\pgf@xa{.5*\pgfkeysvalueof{/pgf/minimum height}}
\ifdim\pgf@x<\pgf@xa\pgf@x=\pgf@xa\fi}
\anchor{center}\centerpoint
\anchor{north}{
\pgf@process\halfheight
\pgf@x=0cm
\pgf@y=.2cm\advance\pgf@y by\halfheight}
\anchorborder{\centerpoint}
\backgroundpath{
\draw[rounded corners=.1cm](-\halfwidth,-\halfheight)rectangle(\halfwidth,\halfheight);
\draw[rounded corners=.04cm](-.8*\halfwidth,-.4*\halfheight)rectangle(.8*\halfwidth,-.8*\halfheight)(-.8*\halfwidth,.4*\halfheight)rectangle(.8*\halfwidth,.8*\halfheight);}}
\pgfdeclareshape{quadrapole}{
\savedanchor\centerpoint{\pgf@x=0cm\pgf@y=0cm}
\saveddimen\halfwidth{
\pgf@x=.25cm
\pgfmathsetlength\pgf@xa{.5*\pgfkeysvalueof{/pgf/minimum width}}
\ifdim\pgf@x<\pgf@xa\pgf@x=\pgf@xa\fi}
\saveddimen\halfheight{
\pgf@x=.25cm
\pgfmathsetlength\pgf@xa{.5*\pgfkeysvalueof{/pgf/minimum height}}
\ifdim\pgf@x<\pgf@xa\pgf@x=\pgf@xa\fi}
\anchor{center}\centerpoint
\anchor{north}{
\pgf@process\halfheight
\pgf@x=0cm
\pgf@y=.2cm\advance\pgf@y by\halfheight}
\anchorborder{\centerpoint}
\backgroundpath{
\draw[rounded corners=.1cm,fill=white](-\halfwidth,-\halfheight)rectangle(\halfwidth,\halfheight);
\draw[rounded corners=.04cm,fill=red](-.8*\halfwidth,-.4*\halfheight)rectangle(.8*\halfwidth,-.8*\halfheight)(-.8*\halfwidth,-.2*\halfheight)rectangle(.8*\halfwidth,.2*\halfheight)(-.8*\halfwidth,.4*\halfheight)rectangle(.8*\halfwidth,.8*\halfheight);}}
\pgfdeclareshape{lens}{
\savedanchor\centerpoint{\pgf@x=0cm\pgf@y=0cm}
\saveddimen\halfwidth{
\pgf@x=.05cm
\pgfmathsetlength\pgf@xa{.5*\pgfkeysvalueof{/pgf/minimum width}}
\ifdim\pgf@x<\pgf@xa\pgf@x=\pgf@xa\fi}
\saveddimen\halfheight{
\pgf@x=.2cm
\pgfmathsetlength\pgf@xa{.5*\pgfkeysvalueof{/pgf/minimum height}}
\ifdim\pgf@x<\pgf@xa\pgf@x=\pgf@xa\fi}
\anchor{center}\centerpoint
\anchor{south}{
\pgf@process\halfheight
\pgf@x=0cm
\pgfmathsetlength\pgf@y{-1.5*\halfheight-.2cm}}
\anchorborder{\centerpoint}
\backgroundpath{
\draw[fill=white](0,-1.5*\halfheight)--(0,-\halfheight)(0,\halfheight)--(0,1.5*\halfheight)(-\halfwidth,-\halfheight)rectangle(\halfwidth,\halfheight);}}
\pgfdeclareshape{pump}{
\savedanchor\centerpoint{\pgf@x=0cm\pgf@y=0cm}
\saveddimen\halfwidth{
\pgf@x=.1cm
\pgfmathsetlength\pgf@xa{.5*\pgfkeysvalueof{/pgf/minimum width}}
\ifdim\pgf@x<\pgf@xa\pgf@x=\pgf@xa\fi}
\saveddimen\halfheight{
\pgf@x=.3cm
\pgfmathsetlength\pgf@xa{.5*\pgfkeysvalueof{/pgf/minimum height}}
\ifdim\pgf@x<\pgf@xa\pgf@x=\pgf@xa\fi}
\anchor{center}\centerpoint
\anchor{south}{
\pgf@process\halfheight
\pgf@process\halfwidth
\pgf@x=0cm
\pgfmathsetlength\pgf@y{-\halfheight-\halfwidth-.2cm}}
\anchorborder{\centerpoint}
\backgroundpath{
\draw[ultra thick](0,0)--(0,-\halfheight);
\draw[fill=white](0,-\halfheight)circle(\halfwidth);}}
\pgfdeclareshape{source}{
\savedanchor\centerpoint{\pgf@x=0cm\pgf@y=0cm}
\saveddimen\halfwidth{
\pgf@x=.3cm
\pgfmathsetlength\pgf@xa{.5*\pgfkeysvalueof{/pgf/minimum width}}
\ifdim\pgf@x<\pgf@xa\pgf@x=\pgf@xa\fi}
\saveddimen\halfheight{
\pgf@x=.1cm
\pgfmathsetlength\pgf@xa{.5*\pgfkeysvalueof{/pgf/minimum height}}
\ifdim\pgf@x<\pgf@xa\pgf@x=\pgf@xa\fi}
\anchor{center}\centerpoint
\anchor{north}{
\pgf@process\halfheight
\pgf@x=0cm
\pgf@y=.2cm\advance\pgf@y by\halfheight}
\anchor{south}{
\pgf@process\halfheight
\pgf@x=0cm
\pgf@y=-.2cm\advance\pgf@y by-\halfheight}
\backgroundpath{
\draw[fill=white](-\halfwidth,-\halfheight)rectangle(\halfwidth,\halfheight)(-.8*\halfwidth,-1.5*\halfheight)--(-.8*\halfwidth,1.5*\halfheight)(-.4*\halfwidth,-1.5*\halfheight)--(-.4*\halfwidth,1.5*\halfheight)(0,-1.5*\halfheight)--(0,1.5*\halfheight)(.4*\halfwidth,-1.5*\halfheight)--(.4*\halfwidth,1.5*\halfheight)(.8*\halfwidth,-1.5*\halfheight)--(.8*\halfwidth,1.5*\halfheight);}}
\tikzset{steers/.style={fill=white,draw,shape=rectangle,rounded corners=.1cm}}
\begin{tikzpicture}
% source PSU
\draw[step=.2cm](-10.4,2.1)grid(-6.6,3.3)(-6,2.7)node{1};
% slits
\path[slit,minimum height=.9cm,minimum width=.9cm](-6.5,0)node(sl){}(5.5,0)node{}(8,-2)node[rotate=90]{};
% pumps
\path[pump,minimum height=.8cm](-8-1.7320508*.6,.6)node[rotate=150]{}(-8-1.7320508*.6,-.6)node[rotate=30]{};
\path[pump,minimum height=1.3cm,minimum width=.4cm](-3.9,0)node(lo){}(2.3,0)node{}(6.6,0)node[rotate=180]{}(8,-3.1)node[rotate=270]{};
% Tubes
\draw[thick,double,double distance=.1cm](-9.7320508,-1)--(-8,0)--(-9.7320508,1);
\draw[thick,double,double distance=.2cm,rounded corners=.4cm](-8,0)-|(8,-5);
\draw[thick,double,double distance=.3cm,rounded corners=.4cm,line cap=rect](7.1,0)-|node[shift={(.2,.2)}]{11}(8,-.6);
% lines
\draw[thick,double,double distance=.1cm,line cap=rect,fill](8,-5.5)--+(-40:3.5)+(0,0)--+(-70:3.5)+(0,0)--+(-110:3.5)+(0,0)--+(-130:3.5)+(0,0)--+(-150:3.5)+(0,0)--+(-25:3.5);
\draw[fill=white](8,-5.5)+(-70:3.5)circle(.4)node[shift={(.5,.5)}]{13};
% quadrapoles
\path[quadrapole,minimum height=.9cm,minimum width=.9cm](3,0)node(re){}(8,-4.3)node[rotate=90]{};
% lenses
\path[lens](-8-1.7320508*.5,.5)node[rotate=-30]{}(-8-1.7320508*.5,-.5)node[rotate=30]{};
\path[lens,minimum height=.3cm,minimum width=.1cm](-7.3,0)node(le){}(-4.3,0)node{};
% sources
\path[source,minimum height=.4cm,minimum width=1.2cm](-9.7320508,1)node(source1)[rotate=-30]{}(-9.7320508,-1)node(source2)[rotate=30]{};
% steerers
\path(-5.3,0)node[steers](st){\phantom{(}}++(.1,.5)node{7}(4.2,0)node[steers]{\phantom{)}};
% tank
\draw[fill=tank](-1.8,1.3)--(-3.6,.7)--(-3.6,-.7)--(-1.8,-1.3)rectangle node[shift={(0,1.6)}]{9}(.1,1.3)--(1.9,.7)--(1.9,-.7)--(.1,-1.3);
% inflector
\draw[fill=white](-8,0)+(-.1,-.3)--+(-.1,.3)--+(-.3,.3)--+(-.4,.1)--+(-.4,-.1)--+(-.3,-.3)--+(0,-.3)--+(.1,-.1)--+(.1,.1)--+(-.1,.3)node[above]{4};
% switcher
\draw[fill=white](8,-5)+(-.5,-.6)--+(.5,-.6)..controls+(.3,-.4)and+(-.3,-.4)..+(-.5,-.6)--+(-.3,0)--+(.3,0)--+(.5,-.6)node[above right]{12};
% walls
\draw[line width=.17cm](3,-5.6)--(6.9,-5.6)arc[start angle=-180,end angle=0,
x radius=1.1cm,y radius=.9cm]--(10.7,-5.6)(8,-6.5)--(8,-10.5);
% left labels
\path(sl.north)node{6}(lo.south)node{8}(re.north)node{10}(le.south)node{5}(source1.north)node{2}(source2.south)node{3};
%Legend
\node[anchor=east] at (-9,-6) (leg1) {$1$. PSU};
\node[below=1mm of leg1] (leg2) {$2$. Sputter Source};
\node[right=6mm of leg1,anchor=west] (leg8) {$8$. Pumps};
\end{tikzpicture}
\end{document}
and my output is
I am trying to align the legend entries but I don't know how to do it! I've played around with anchors
but without any luck at all. Any ideas?