Skip to main content
added 1297 characters in body
Source Link
Eric S
  • 165
  • 1
  • 10

Update I now have this code, is there a tex-ninja way to get rid of the helper coordinates?


\documentclass[]{standalone}

% tikz
\usepackage{tikz}
\usetikzlibrary{positioning} %relative positioning

\begin{document}

\tikzset{%
    EDFA/.pic={
        \begin{scope}[scale=.5, shift={(1,0)}]
        \draw (-1,0) coordinate (-in) --  (-1,1) -- (1,0) coordinate (-out) --  (-1,-1) -- cycle;
        \node[anchor=north,inner sep=2pt] at (0,-1) {EDFA};
        \end{scope}
    },
    Coupler/.pic={
        \begin{scope}[scale=.5, shift={(1,-1)}]
        \draw (-1,1) coordinate (-in1) to[out=0,in=180] (0,0) to[out=0,in=180] (1,1) coordinate (-out1);
        \draw (-1,-1) coordinate (-in2) to[out=0,in=180] (0,0) to[out=0,in=180] (1,-1) coordinate (-out2);
        \end{scope}
    }
}

\begin{tikzpicture}[
block/.style={draw},
]


\node[block] (source) {Source};

\path coordinate[right=of source] (helper a);
\draw (helper a) pic (edfa) {EDFA};

\path coordinate[right=of edfa-out] (helper b);
\draw (helper b) pic (coupler) {Coupler};


\node[block, right= of coupler-out1] (sink) {Sink};

\draw[->] (source) -- (edfa-in);
\draw (edfa-out) -- (coupler-in1);
\draw[->] (coupler-out1) -- (sink);

\end{tikzpicture}

\end{document}

Update I now have this code, is there a tex-ninja way to get rid of the helper coordinates?


\documentclass[]{standalone}

% tikz
\usepackage{tikz}
\usetikzlibrary{positioning} %relative positioning

\begin{document}

\tikzset{%
    EDFA/.pic={
        \begin{scope}[scale=.5, shift={(1,0)}]
        \draw (-1,0) coordinate (-in) --  (-1,1) -- (1,0) coordinate (-out) --  (-1,-1) -- cycle;
        \node[anchor=north,inner sep=2pt] at (0,-1) {EDFA};
        \end{scope}
    },
    Coupler/.pic={
        \begin{scope}[scale=.5, shift={(1,-1)}]
        \draw (-1,1) coordinate (-in1) to[out=0,in=180] (0,0) to[out=0,in=180] (1,1) coordinate (-out1);
        \draw (-1,-1) coordinate (-in2) to[out=0,in=180] (0,0) to[out=0,in=180] (1,-1) coordinate (-out2);
        \end{scope}
    }
}

\begin{tikzpicture}[
block/.style={draw},
]


\node[block] (source) {Source};

\path coordinate[right=of source] (helper a);
\draw (helper a) pic (edfa) {EDFA};

\path coordinate[right=of edfa-out] (helper b);
\draw (helper b) pic (coupler) {Coupler};


\node[block, right= of coupler-out1] (sink) {Sink};

\draw[->] (source) -- (edfa-in);
\draw (edfa-out) -- (coupler-in1);
\draw[->] (coupler-out1) -- (sink);

\end{tikzpicture}

\end{document}

Tweeted twitter.com/StackTeX/status/697528875635576832
added 102 characters in body
Source Link
Ignasi
  • 139.8k
  • 12
  • 273
  • 533

In my diagram I have a few components I reuse a lot, thus making "macros" in tikz for them. The current code I have is using nested tikzpicture environments and is not exactly working as expected. Do you have any suggestions how to improve this?

I found other questions, but none seem to help me?

My code


\documentclass[]{article}

% tikz
\usepackage{tikz}
\usetikzlibrary{positioning} %relative positioning
\usetikzlibrary{fit} %box around multiople nodes
\usetikzlibrary{calc} %complex positioning
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}[
block/.style={draw},
container/.style={inner sep=0,},
]

\def\EDFA{
\begin{tikzpicture}[scale=0.25]
\draw (-1,1) --  (1,0) --  (-1,-1) -- (-1,1);
\node[anchor=north,inner sep=2pt] at (0,-1) {$1$};
\end{tikzpicture}
}


\node[block] (source) {Source};

\node[container,right= of source] (edfa) {\EDFA};

\node[block, right= of edfa] (sink) {Sink};

\draw[->] (source) -- (edfa);
\draw[->] (edfa) -- (sink);

\end{tikzpicture}

\end{document}

\documentclass[]{article}

% tikz
\usepackage{tikz}
\usetikzlibrary{positioning} %relative positioning
\usetikzlibrary{fit} %box around multiople nodes
\usetikzlibrary{calc} %complex positioning
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}[
block/.style={draw},
container/.style={inner sep=0,},
]

\def\EDFA{
\begin{tikzpicture}[scale=0.25]
\draw (-1,1) --  (1,0) --  (-1,-1) -- (-1,1);
\node[anchor=north,inner sep=2pt] at (0,-1) {$1$};
\end{tikzpicture}
}


\node[block] (source) {Source};

\node[container,right= of source] (edfa) {\EDFA};

\node[block, right= of edfa] (sink) {Sink};

\draw[->] (source) -- (edfa);
\draw[->] (edfa) -- (sink);

\end{tikzpicture}

\end{document}

In my diagram I have a few components I reuse a lot, thus making "macros" in tikz for them. The current code I have is using nested tikzpicture environments and is not exactly working as expected. Do you have any suggestions how to improve this?

I found other questions, but none seem to help me?

My code


\documentclass[]{article}

% tikz
\usepackage{tikz}
\usetikzlibrary{positioning} %relative positioning
\usetikzlibrary{fit} %box around multiople nodes
\usetikzlibrary{calc} %complex positioning
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}[
block/.style={draw},
container/.style={inner sep=0,},
]

\def\EDFA{
\begin{tikzpicture}[scale=0.25]
\draw (-1,1) --  (1,0) --  (-1,-1) -- (-1,1);
\node[anchor=north,inner sep=2pt] at (0,-1) {$1$};
\end{tikzpicture}
}


\node[block] (source) {Source};

\node[container,right= of source] (edfa) {\EDFA};

\node[block, right= of edfa] (sink) {Sink};

\draw[->] (source) -- (edfa);
\draw[->] (edfa) -- (sink);

\end{tikzpicture}

\end{document}

In my diagram I have a few components I reuse a lot, thus making "macros" in tikz for them. The current code I have is using nested tikzpicture environments and is not exactly working as expected. Do you have any suggestions how to improve this?

I found other questions, but none seem to help me?

My code

\documentclass[]{article}

% tikz
\usepackage{tikz}
\usetikzlibrary{positioning} %relative positioning
\usetikzlibrary{fit} %box around multiople nodes
\usetikzlibrary{calc} %complex positioning
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}[
block/.style={draw},
container/.style={inner sep=0,},
]

\def\EDFA{
\begin{tikzpicture}[scale=0.25]
\draw (-1,1) --  (1,0) --  (-1,-1) -- (-1,1);
\node[anchor=north,inner sep=2pt] at (0,-1) {$1$};
\end{tikzpicture}
}


\node[block] (source) {Source};

\node[container,right= of source] (edfa) {\EDFA};

\node[block, right= of edfa] (sink) {Sink};

\draw[->] (source) -- (edfa);
\draw[->] (edfa) -- (sink);

\end{tikzpicture}

\end{document}
Source Link
Eric S
  • 165
  • 1
  • 10
Loading