Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass[11pt]{article}
- \usepackage{fp}
- \usepackage{tikz}
- \usetikzlibrary{calc}
- \begin{document}
- \newcommand\junctionNode[7]
- {
- % Modular core, works even if you don't enter anything. So changing the color/text/etc. is optional
- \ifstrequal {#1} {} {\def\varLoc{0,0}} {\def\varLoc{#1}}
- \ifstrequal {#2} {} {\def\varIn{1}} {\def\varIn{#2}}
- \ifstrequal {#3} {} {\def\varOut{1}} {\def\varOut{#3}}
- \ifstrequal {#4} {} {\def\varName{Node}} {\def\varName{#4}}
- \def\varText{\textit{#5}}
- \def\varLabel{#6}
- \ifstrequal {#7} {} {\def\varFill{blue!10}} {\def\varFill{#7}}
- % Getting the highest number of Inputs or Outputs
- \ifnumgreater {\varIn} {\varOut} {\def\varMinWidth{\varIn}} {\def\varMinWidth{\varOut}}
- % Creating the main/visible node
- \node
- [shape=rectangle, draw=black, fill=\varFill,
- label=above:\varLabel, inner sep=0, minimum height=1cm,
- minimum width=\varMinWidth cm] at(\varLoc) {\varText}
- ;
- % Subtracting 1 from the number of inputs and outputs because I need a zero based number in the loop
- \FPeval\varInputs {clip(\varIn-1)}
- \FPeval\varOutputs {clip(\varOut-1)}
- % Defining the current node width
- \newdimen\varAX
- \pgfextractx{\varAX}{\varName.west}
- \newdimen\varBX
- \pgfextractx{\varBX}{\varName.east}
- \FPeval\varASpacing {(\varBX - \varAX)/\varIn}
- % TO DO : Subtract the two X Coords to get node width, divide that by \varIn to get the node spacing <- VarASpacing.
- % The \pgfextract doesn't seem to work properly, replace that.
- % A 'For Loop' for the Inputs
- \foreach \varA in {0,...,\varInputs}
- {
- \node (\varName\varA) at (\varAX+\varASpacing/2+\varASpacing*\varA,0) {N1};
- }
- % A 'For Loop' for the Outputs
- \foreach \varB in {0,...,\varInputs}
- {
- \node (\varName\varB) at (\varAX+\varBSpacing/2+\varBSpacing*\varB,0) {N1};
- }
- }
- \begin{tikzpicture}
- \junctionNode{}{}{}{}{}{}{}
- % \junctionNode{location}{n of in}{n of out}{name}{text}{label}{node fill}{input side}{output side}
- \end{tikzpicture}
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment