FireDustMC

LaTeX

Sep 27th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 2.43 KB | None | 0 0
  1. \documentclass[11pt]{article}
  2.    \usepackage{fp}
  3.    \usepackage{tikz}
  4.    \usetikzlibrary{calc}
  5.  
  6. \begin{document}
  7.     \newcommand\junctionNode[7]
  8.     {
  9.         % Modular core, works even if you don't enter anything. So changing the color/text/etc. is optional
  10.         \ifstrequal {#1} {} {\def\varLoc{0,0}}      {\def\varLoc{#1}}
  11.        \ifstrequal {#2} {} {\def\varIn{1}}         {\def\varIn{#2}}
  12.        \ifstrequal {#3} {} {\def\varOut{1}}        {\def\varOut{#3}}
  13.        \ifstrequal {#4} {} {\def\varName{Node}}    {\def\varName{#4}}
  14.                                                     \def\varText{\textit{#5}}
  15.                                                     \def\varLabel{#6}
  16.        \ifstrequal {#7} {} {\def\varFill{blue!10}} {\def\varFill{#7}}
  17.         % Getting the highest number of Inputs or Outputs
  18.         \ifnumgreater {\varIn} {\varOut} {\def\varMinWidth{\varIn}} {\def\varMinWidth{\varOut}}
  19.         % Creating the main/visible node
  20.         \node
  21.             [shape=rectangle,               draw=black,     fill=\varFill,
  22.            label=above:\varLabel,          inner sep=0,    minimum height=1cm,
  23.            minimum width=\varMinWidth cm]  at(\varLoc)     {\varText}
  24.         ;
  25.         % Subtracting 1 from the number of inputs and outputs because I need a zero based number in the loop
  26.         \FPeval\varInputs {clip(\varIn-1)}
  27.        \FPeval\varOutputs {clip(\varOut-1)}
  28.         % Defining the current node width
  29.         \newdimen\varAX
  30.         \pgfextractx{\varAX}{\varName.west}
  31.        \newdimen\varBX
  32.        \pgfextractx{\varBX}{\varName.east}
  33.     \FPeval\varASpacing {(\varBX - \varAX)/\varIn}
  34.         % TO DO : Subtract the two X Coords to get node width, divide that by \varIn to get the node spacing <- VarASpacing.
  35.         % The \pgfextract doesn't seem to work properly, replace that.
  36.         % A 'For Loop' for the Inputs
  37.         \foreach \varA in {0,...,\varInputs}
  38.        {          
  39.            \node (\varName\varA) at (\varAX+\varASpacing/2+\varASpacing*\varA,0) {N1};
  40.        }
  41.         % A 'For Loop' for the Outputs
  42.         \foreach \varB in {0,...,\varInputs}
  43.        {          
  44.            \node (\varName\varB) at (\varAX+\varBSpacing/2+\varBSpacing*\varB,0) {N1};
  45.        }
  46.    }
  47.  
  48.    \begin{tikzpicture}
  49.        \junctionNode{}{}{}{}{}{}{}
  50.     %   \junctionNode{location}{n of in}{n of out}{name}{text}{label}{node fill}{input side}{output side}
  51.     \end{tikzpicture}
  52. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment