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}
\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz-network}
\begin{filecontents}{vertices.csv}
id, x, y ,label
0, -1.25, 4.5, C
1, 3.5, 4.5, C++
2, 3.5, 2.5, HTML
3, -2.75, 2.5, JavaScript
4, 1.25, 5, Python
5, 1.25, 1.75, CSS
6, 3.75, 6, Shell
7, -2.25, 5.75, Objective-C
8, 1.75, -0.5, PHP
9, 5, 0, Java
10, 5.25, 3.5, Makefile
11, -1.75, 0, Ruby
\end{filecontents}
\begin{filecontents}{edges.csv}
u, v, lw
0, 3, 1
0, 2, 2
2, 1, 1
3, 1, 5
11, 5, 1
11, 3, 10
11, 0, 1
8, 0, 1
7, 0, 1
4, 5, 8
0, 4, 1
4, 1, 1
6, 10, 1
10, 9, 3
9, 2, 1
2, 10, 1
8, 5, 1
8, 2, 1
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\Vertices[size=0, style={inner sep=0pt}]{vertices.csv}
\Edges[color=lightgray]{edges.csv}
\end{tikzpicture}
\end{document}
Best Answer
I think your problem should be handled by using
controls
operation.Here is a solution:
Output:
You can easily move the points as your need in the line accordingly.
\draw (-.32,-.2) .. controls(-2.1,1.5) and (5.4,2) .. (3.45,-.8);
where starting point is(-.32,-.2)
and end point is(3.45,-.8)
. This points(-2.1,1.5) and (5.4,2)
controls the shape of the curved line.