How to copy a defined node and put it somewhere we want?
Time for a pic
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri}
\tikzset{
man/.pic={
\begin{scope}[scale=#1,every node/.style={scale=0.8*#1}]
\node[circle,fill,minimum size=5mm] (head) {};
\node[rounded corners=2pt,minimum height=1.3cm,minimum width=0.4cm,fill,
below = 1pt of head] (body) {};
\draw[line width=1mm,round cap-round cap] ([shift={(2pt,-1pt)}]body.north east)
--++(-90:6mm);
\draw[line width=1mm,round cap-round cap] ([shift={(-2pt,-1pt)}]body.north
west)--++(-90:6mm);
\draw[thick,white,-round cap] (body.south) --++(90:5.5mm);
\end{scope}
}
}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\pic (a) at (0,0) {man={1.3}};
\pic[above right = 2cm and 2cm of abody] (b) {man={.9}};
\pic[below right = 1cm and 2cm of abody] (c) {man={.9}};
\draw[-latex,shorten >=1em] ([xshift=3em]abody.west) -- (bbody);
\draw[-latex,shorten >=1em] ([xshift=3em]abody.west) -- (cbody);
\end{tikzpicture}
\end{frame}
\end{document}
I would define a \newcommand
with an optional argument for the scaling.
The command is \human[#1]{#2}{3}
, where
#1
is the optional argument. If you don't define it (not writing the[]
), then the scale is 1.#2
is the node's name. I usedA, B, C
.#3
is the position. It's done as any other node, like(0,0)
or(5,0)
.
About the tikz library: you can write one and add all the options there. Also, you should switch to arrows.meta
(redefining the shape with the new line caps).
Output
Code
\documentclass{beamer}
\usepackage{lmodern} % I added this because it was complaining about fonts
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.multipart,arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri}
\newcommand{\human}[3][1]{
\node[scale=#1] (#2) at (#3) {
\begin{tikzpicture}
\node[circle,fill,minimum size=5mm] (head) {};
\node[rounded corners=2pt,minimum height=1.3cm,minimum width=0.4cm,fill,below = 1pt of head] (body) {};
\draw[line width=1mm,round cap-round cap] ([shift={(2pt,-1pt)}]body.north east) --++(-90:6mm);
\draw[line width=1mm,round cap-round cap] ([shift={(-2pt,-1pt)}]body.north west)--++(-90:6mm);
\draw[thick,white,-round cap] (body.south) --++(90:5.5mm);
\end{tikzpicture}};
}
\begin{document}
\begin{frame}
\begin{tikzpicture}[->]
\human{A}{0,0} % scaling not defined
\human[2]{B}{3,-2} % double the size, double the fun!
\human[.5]{C}{3,2} % meh, a bit smaller.
\draw (A.east) -- (B.west);
\draw (A.east) -- (C.west);
\end{tikzpicture}
\end{frame}
\end{document}