I am definitely unfamiliar with both beamer
and tikz
(do not quite get what the \only
are supposed to do) but perhaps this could go in the direction you want:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcounter{count}
% helper macro:
\long\def\GobToSemiColon #1;{}
\newcommand\myPicture{
\begin{tikzpicture}
\begin{scope}[start chain = going below]
\ifnum\value{count}<1 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>3 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is between
1 and 3};
\ifnum\value{count}>-1 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is
negative};
\ifnum\value{count}<100 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>200 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only if counter is between
100 and 200};
\ifnum\value{count}<3 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>20 \expandafter\GobToSemiColon\fi
\node[draw, circle, on chain] {only when counter is in the range 3 to 20};
\end{scope}
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\only{\setcounter{count}{5}\myPicture}
\end{frame}
\end{document}
As is explained in How do I draw shapes inside a tikz node? pics
can be used for defining new objects. My main problem using pics is how to place where you want because they aren't nodes
and positioning them is not so easy.
Following code shows how to define EDFA
block.
EDFA/.pic={
\begin{scope}[scale=.5]
\draw (-1,0) coordinate (in) -- (-1,1) -- (1,0) coordinate (out) -- (-1,-1) -- cycle;
\node[anchor=north,inner sep=2pt] at (0,-1) {$1$};
\end{scope}
In this case, coordinate (-1,0) will act as west
anchor and 1,0
as east. Both point will have an special name for further reference. Every pic
is placed according its own origin (0,0)
. You can use Claudio's answer to Anchoring TiKZ pics for better positioning.
As your example was simple, I'd prefer to star with EDFA
and place Source
and Sink
after it.
\documentclass[]{article}
% tikz
\usepackage{tikz}
\usetikzlibrary{positioning} %relative positioning
\begin{document}
\tikzset{%
EDFA/.pic={
\begin{scope}[scale=.5]
\draw (-1,0) coordinate (in) -- (-1,1) -- (1,0) coordinate (out) -- (-1,-1) -- cycle;
\node[anchor=north,inner sep=2pt] at (0,-1) {$1$};
\end{scope}
}
}
\begin{tikzpicture}[
block/.style={draw},
]
\draw pic (edfa) {EDFA};
\node[block, left=of edfain] (source) {Source};
\node[block, right= of edfaout] (sink) {Sink};
\draw[->] (source) -- (edfain);
\draw[->] (edfaout) -- (sink);
\end{tikzpicture}
\end{document}
I understand that your components are more complex than EDFA
because for this particular case an isosceles triangle
node with a label
will do the work and it can be used as a node
and not as a pic
:
\documentclass[]{article}
% tikz
\usepackage{tikz}
\usetikzlibrary{positioning} %relative positioning
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
block/.style={draw},
edfa/.style={isosceles triangle, minimum width=1cm,
draw, anchor=west, isosceles triangle stretches,
minimum height=1cm, label=-80:#1}
]
\node[block] (source) {Source};
\node[edfa=1, right=of source] (edfa) {};
\node[block, right= of edfa] (sink) {Sink};
\draw[->] (source) -- (edfa);
\draw[->] (edfa) -- (sink);
\end{tikzpicture}
\end{document}
Best Answer
Your question is not entirely clear (see my comment below question). So far, I guess that you are after something like this: