3

I use labels to place icons within my TikZ pictures:

\begin{tikzpicture}[
  switch/.style={label=center:{\includegraphics[width=1.5cm]{switch.png}}},
  cloud/.style={label=center:{\includegraphics[width=2.5cm]{cloud.png}}}
]
  \node[switch] (switch) {};
  \node[cloud, left of=switch] (internet) {Internet};
\end{tikzpicture}

By default the labels are placed over the node content, so the text "Internet" for instance cannot be seen, because the cloud is being drawn over it.

How can I place either the label underneath the node text, or vice versa the node text above the label?

2 Answers2

3

One solution:

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

\begin{tikzpicture}
  \node (switch) {\includegraphics[width=1.5cm]{example-image-A}};
  \node [label={center:Internet}, left of=switch] (internet){\includegraphics[width=2.5cm]{example-image-B}};
\end{tikzpicture}

\end{document}

enter image description here

Place the icons inside the node content and the text inside the label. Alternatively, modify the cloud node as this:

\node[cloud, left of=switch, label=center:Internet] (internet) {};

So, the code now becomes:

\begin{tikzpicture}[
  switch/.style={label=center:{\includegraphics[width=1.5cm]{example-image-A}}},
  cloud/.style={label=center:{\includegraphics[width=2.5cm]{example-image-B}}}
]
  \node[switch] (switch) {};
  \node[cloud, left of=switch, label=center:Internet] (internet) {};
\end{tikzpicture}
AboAmmar
  • 46,352
  • 4
  • 58
  • 127
  • I use styles, rather than placing the image directly since I am using the elements several times within one picture, but I just figured out by following your example, that a node can have several labels and the labels are placed in order. So that's a way to go. – Manuel Faux Oct 18 '15 at 19:36
  • Then, use the alternative definition as I mentioned. – AboAmmar Oct 18 '15 at 19:37
1

I don't have your switch.png and cloud.png images, but here is how to control the label position:

\node[cloud, left of=switch,label={[label distance=1cm]90:interent}] (internet) {};

You can adjust the distance by changing the 1cm and the angle by changing the 90.

jak123
  • 4,252
  • 5
  • 26
  • 49