2

I have drawn the below image in latex. I have used 4 different *.png files to construct 4 different shapes (mobiles, tv's, base stations, relays) in the image. I need to add a legend of this 4 shapes using the *.png files. My latex code for the image, *.png files are added at the end.

enter image description here

The code for the same goes below

\documentclass[tikz,border=5mm]{standalone}
\usepackage{ellipsis}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,shapes.geometric}
\begin{document}
\def\xelip{15}
\def\yelip{3}
\begin{tikzpicture}%[every path/.append style={thick}]
\coordinate (center) at (0,0);
\coordinate (c1) at ($(-10,10)+(center)$);
\coordinate (c2) at ($(10,10)+(center)$);
\coordinate (c3) at ($(0,-10)+(center)$);

%################# DRAWING ELLIPSES ###############################

  \def\firstellipse{(c1) ellipse [x radius=18, y radius=15, rotate=150]}
    \def\secondellipse{(c2) ellipse [x radius=18, y radius=15, rotate=30]}
    \def\thirdellipse{(c3) ellipse [x radius=18, y radius=15, rotate=90]}
    \def\boundingbox{(-25,-25) rectangle (25,25)}

    % fill ellipses
    \fill[yellow!10!white] \firstellipse \secondellipse \thirdellipse;

    % fill intersections
    % intersection of second and third
    \begin{scope}
        \clip \boundingbox \firstellipse;
        \clip \secondellipse;
        \fill[red!10] \thirdellipse;
    \end{scope}
    % intersection of first and third
    \begin{scope}
        \clip \boundingbox \secondellipse;
        \clip \firstellipse;
        \fill[red!10] \thirdellipse;
    \end{scope}
    % intersection of first and second
    \begin{scope}
        \clip \boundingbox \thirdellipse;
        \clip \firstellipse;
        \fill[red!10] \secondellipse;
    \end{scope}
    % intersection of first, second and third
    \begin{scope}
        \clip \firstellipse;
        \clip \secondellipse;
        \clip \thirdellipse;
        \fill[red!20] \boundingbox;
    \end{scope}

    % outline of ellipses
    \draw \firstellipse \secondellipse \thirdellipse;
%####################################################################    

%####################  BASE STATIONS
\node (bs1) at ($(c1)+(-3,3)$) {\includegraphics[scale=.6]{bs.png}};
\node (bs2) at ($(c2)+(2,2)$) {\includegraphics[scale=.6]{bs.png}};
\node (bs3) at ($(c3)+(0,-2)$) {\includegraphics[scale=.6]{bs.png}};

%#################### RELAY STATIONS
\node (r1)  at ($(bs1.west)+(-5,5)$) {\includegraphics[scale=.14]{relay.png}};
\node (r2)  at ($(center)+(2,5)$) {\includegraphics[scale=.14]{relay.png}};
\node (r3)  at ($(r2.north)+(-1,6)$)  {\includegraphics[scale=.14]{relay.png}}; 

%##################### MOBILE STATIONS
\node (mp1) at (center) {\includegraphics[scale=.016]{mobile.png}};
\node (mp2) at (center) {\includegraphics[scale=.016]{mobile.png}};
\node (mp3) at ($(r1.north)+(-4,4)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp4) at ($(mp1.west)+(-5,-4)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp5) at ($(bs3.west)+(-8,-6)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp6) at ($(bs3.south)+(-7,4)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp8) at ($(bs3.east)+(3,3)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp9) at ($(bs2.east)+(4,8)$) {\includegraphics[scale=.016]{mobile.png}};

\node (mp7) at ($(r3.west)+(-2,-2)$) {\includegraphics[scale=.016]{mobile.png}};


%################### TV STATIONS
\node (tv1) at ($(bs1)+(-4,-9)$) {\includegraphics[scale=.6]{tv.png}};
\node (tv2) at ($(bs1)+(-8,-4)$) {\includegraphics[scale=.6]{tv.png}};
\node (tv3) at ($(bs3.east)+(5,9)$) {\includegraphics[scale=.6]{tv.png}};
\end{tikzpicture}
\end{document}

The *.png files used to make this diagram are given at the end of this question.

enter image description here enter image description here enter image description here enter image description here

2
  • Why can't you just add a node containing the legend? I don't understand the problem.
    – cfr
    Feb 22, 2015 at 16:36
  • Can you please demonstrate what you meant?. My tikz skills are amateurish. Feb 22, 2015 at 16:42

1 Answer 1

6

You can use a TikZ \node to place the legend at the desired location; for example (you can easily control the location and attributes for the elements in the legend):

\documentclass[tikz,border=5mm]{standalone}
\usepackage{ellipsis}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,shapes.geometric}
\begin{document}
\def\xelip{15}
\def\yelip{3}
\begin{tikzpicture}%[every path/.append style={thick}]
\coordinate (center) at (0,0);
\coordinate (c1) at ($(-10,10)+(center)$);
\coordinate (c2) at ($(10,10)+(center)$);
\coordinate (c3) at ($(0,-10)+(center)$);

%################# DRAWING ELLIPSES ###############################

  \def\firstellipse{(c1) ellipse [x radius=18, y radius=15, rotate=150]}
    \def\secondellipse{(c2) ellipse [x radius=18, y radius=15, rotate=30]}
    \def\thirdellipse{(c3) ellipse [x radius=18, y radius=15, rotate=90]}
    \def\boundingbox{(-25,-25) rectangle (25,25)}

    % fill ellipses
    \fill[yellow!10!white] \firstellipse \secondellipse \thirdellipse;

    % fill intersections
    % intersection of second and third
    \begin{scope}
        \clip \boundingbox \firstellipse;
        \clip \secondellipse;
        \fill[red!10] \thirdellipse;
    \end{scope}
    % intersection of first and third
    \begin{scope}
        \clip \boundingbox \secondellipse;
        \clip \firstellipse;
        \fill[red!10] \thirdellipse;
    \end{scope}
    % intersection of first and second
    \begin{scope}
        \clip \boundingbox \thirdellipse;
        \clip \firstellipse;
        \fill[red!10] \secondellipse;
    \end{scope}
    % intersection of first, second and third
    \begin{scope}
        \clip \firstellipse;
        \clip \secondellipse;
        \clip \thirdellipse;
        \fill[red!20] \boundingbox;
    \end{scope}

    % outline of ellipses
    \draw \firstellipse \secondellipse \thirdellipse;
%####################################################################    

%####################  BASE STATIONS
\node (bs1) at ($(c1)+(-3,3)$) {\includegraphics[scale=.6]{bs.png}};
\node (bs2) at ($(c2)+(2,2)$) {\includegraphics[scale=.6]{bs.png}};
\node (bs3) at ($(c3)+(0,-2)$) {\includegraphics[scale=.6]{bs.png}};

%#################### RELAY STATIONS
\node (r1)  at ($(bs1.west)+(-5,5)$) {\includegraphics[scale=.14]{relay.png}};
\node (r2)  at ($(center)+(2,5)$) {\includegraphics[scale=.14]{relay.png}};
\node (r3)  at ($(r2.north)+(-1,6)$)  {\includegraphics[scale=.14]{relay.png}}; 

%##################### MOBILE STATIONS
\node (mp1) at (center) {\includegraphics[scale=.016]{mobile.png}};
\node (mp2) at (center) {\includegraphics[scale=.016]{mobile.png}};
\node (mp3) at ($(r1.north)+(-4,4)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp4) at ($(mp1.west)+(-5,-4)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp5) at ($(bs3.west)+(-8,-6)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp6) at ($(bs3.south)+(-7,4)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp8) at ($(bs3.east)+(3,3)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp9) at ($(bs2.east)+(4,8)$) {\includegraphics[scale=.016]{mobile.png}};

\node (mp7) at ($(r3.west)+(-2,-2)$) {\includegraphics[scale=.016]{mobile.png}};


%################### TV STATIONS
\node (tv1) at ($(bs1)+(-4,-9)$) {\includegraphics[scale=.6]{tv.png}};
\node (tv2) at ($(bs1)+(-8,-4)$) {\includegraphics[scale=.6]{tv.png}};
\node (tv3) at ($(bs3.east)+(5,9)$) {\includegraphics[scale=.6]{tv.png}};

\node[anchor=south,scale=2] 
at ([xshift=-6cm,yshift=15cm]current bounding box.south east)
{
\begin{tabular}{|cl|}
\hline
\includegraphics[width=10pt]{mobile.png} & \Huge Mobile \\
\includegraphics[width=15pt]{tv} & \Huge TV \\
\includegraphics[width=15pt]{relay.png} & \Huge Relay \\
\includegraphics[width=15pt]{bs.png} & \Huge Base station \\
\hline
\end{tabular}
};
\end{tikzpicture}
\end{document}

enter image description here

Update

As required in a comment, the legend should describe the meaning of the colors used; I defined a \ColorBox command for this:

\documentclass[tikz,border=5mm]{standalone}
\usepackage{ellipsis}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,shapes.geometric}

\newcommand\ColorBox[2][1em]{%
\frame{\textcolor{#2}{\rule{#1}{#1}}}%
}
\begin{document}
\def\xelip{15}
\def\yelip{3}
\begin{tikzpicture}%[every path/.append style={thick}]
\coordinate (center) at (0,0);
\coordinate (c1) at ($(-10,10)+(center)$);
\coordinate (c2) at ($(10,10)+(center)$);
\coordinate (c3) at ($(0,-10)+(center)$);

%################# DRAWING ELLIPSES ###############################

  \def\firstellipse{(c1) ellipse [x radius=18, y radius=15, rotate=150]}
    \def\secondellipse{(c2) ellipse [x radius=18, y radius=15, rotate=30]}
    \def\thirdellipse{(c3) ellipse [x radius=18, y radius=15, rotate=90]}
    \def\boundingbox{(-25,-25) rectangle (25,25)}

    % fill ellipses
    \fill[yellow!10!white] \firstellipse \secondellipse \thirdellipse;

    % fill intersections
    % intersection of second and third
    \begin{scope}
        \clip \boundingbox \firstellipse;
        \clip \secondellipse;
        \fill[red!10] \thirdellipse;
    \end{scope}
    % intersection of first and third
    \begin{scope}
        \clip \boundingbox \secondellipse;
        \clip \firstellipse;
        \fill[red!10] \thirdellipse;
    \end{scope}
    % intersection of first and second
    \begin{scope}
        \clip \boundingbox \thirdellipse;
        \clip \firstellipse;
        \fill[red!10] \secondellipse;
    \end{scope}
    % intersection of first, second and third
    \begin{scope}
        \clip \firstellipse;
        \clip \secondellipse;
        \clip \thirdellipse;
        \fill[red!20] \boundingbox;
    \end{scope}

    % outline of ellipses
    \draw \firstellipse \secondellipse \thirdellipse;
%####################################################################    

%####################  BASE STATIONS
\node (bs1) at ($(c1)+(-3,3)$) {\includegraphics[scale=.6]{bs.png}};
\node (bs2) at ($(c2)+(2,2)$) {\includegraphics[scale=.6]{bs.png}};
\node (bs3) at ($(c3)+(0,-2)$) {\includegraphics[scale=.6]{bs.png}};

%#################### RELAY STATIONS
\node (r1)  at ($(bs1.west)+(-5,5)$) {\includegraphics[scale=.14]{relay.png}};
\node (r2)  at ($(center)+(2,5)$) {\includegraphics[scale=.14]{relay.png}};
\node (r3)  at ($(r2.north)+(-1,6)$)  {\includegraphics[scale=.14]{relay.png}}; 

%##################### MOBILE STATIONS
\node (mp1) at (center) {\includegraphics[scale=.016]{mobile.png}};
\node (mp2) at (center) {\includegraphics[scale=.016]{mobile.png}};
\node (mp3) at ($(r1.north)+(-4,4)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp4) at ($(mp1.west)+(-5,-4)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp5) at ($(bs3.west)+(-8,-6)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp6) at ($(bs3.south)+(-7,4)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp8) at ($(bs3.east)+(3,3)$) {\includegraphics[scale=.016]{mobile.png}};
\node (mp9) at ($(bs2.east)+(4,8)$) {\includegraphics[scale=.016]{mobile.png}};

\node (mp7) at ($(r3.west)+(-2,-2)$) {\includegraphics[scale=.016]{mobile.png}};


%################### TV STATIONS
\node (tv1) at ($(bs1)+(-4,-9)$) {\includegraphics[scale=.6]{tv.png}};
\node (tv2) at ($(bs1)+(-8,-4)$) {\includegraphics[scale=.6]{tv.png}};
\node (tv3) at ($(bs3.east)+(5,9)$) {\includegraphics[scale=.6]{tv.png}};

\node[anchor=south,scale=1.5] 
at ([xshift=-6cm,yshift=15cm]current bounding box.south west)
{
\renewcommand\arraystretch{1.3}
\begin{tabular}{|cp{8cm}|}
\hline
\ColorBox{yellow!10!white} & \LARGE Some description for this color \\
\ColorBox{red!10} & \LARGE Some description for this color \\
\ColorBox{red!20} & \LARGE Some description for this color \\
\hline
\end{tabular}
};
\end{tikzpicture}
\end{document}

enter image description here

A zoomed-in image of the description:

enter image description here

5
  • Thanks +1, how do I add some spacing between table entries? Feb 22, 2015 at 17:42
  • @dineshdileep Instead of ` \\ ` to change lines use \\[40pt] (change 40pt to the desired value). Feb 22, 2015 at 17:48
  • I tried to add a legend of colors used in this figure on south-west of border using your code. My attempt was to draw a rectangular color box and then the corresponding name which fails miserably. My code went something like {\filldraw[yellow] (0,0) rectange (1pt,1pt)} & Cellular Range Feb 22, 2015 at 19:03
  • Can you help me with that? Feb 22, 2015 at 19:04
  • @dineshdileep Sure! Please see my updated answer. Is it something like that what you had in mind? Feb 22, 2015 at 19:31

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.