4

The question is an extension to this question, and is also related to this one.

I want to draw a Simulink-style sum block which is basically a circle node with a port in each direction (north, west, south, east). If a port is used as an added (or subtracted) input, a plus (or minus) sign is shown at the port. I hope I can specify the port configurations using custom node styles with arguments:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
    positive/.pic = {\draw (-1mm,0)--(1mm,0) (0,-1mm)--(0,1mm);},
    negative/.pic = {\draw (-1mm,0)--(1mm,0);},
    sum block/.style = {draw, circle, inner sep=0pt, minimum size=9mm,
        north/.style = {append after command={pic at +(0,3mm) {#1}}},
        south/.style = {append after command={pic at +(0,-3mm) {#1}}},
        west/.style = {append after command={pic at +(-3mm,0) {#1}}},
        east/.style = {append after command={pic at +(3mm,0) {#1}}},
    },
]
% I wish to create a node like this:
\path (1cm, 0) node [sum block] {} pic at +(0,3mm) {positive} pic at +(-3mm, 0) {negative};
% using a more elegant syntax like this:
\node at (2cm, 0) [sum block, north=positive, west=negative] {};
\end{tikzpicture}
\end{document}

The result is as follows; the desired fancy syntax is not producing any port sign.

test output

Is there an easy way to meet the objective? A TikZ-only solution like this one is preferred.

  • It's much easier with path picture – percusse Mar 22 '15 at 16:43
  • Also, you can use \pgftext{$+$} and \pgftext{$-$} instead of pics. – John Kormylo Mar 22 '15 at 18:58
5

Do you want something like this?

\documentclass[tikz, border=5pt]{standalone}
\begin{document}
  \tikzset{
    charge node/.style={inner sep=0pt},
    pics/sum block/.style n args={4}{
      code={
        \path node (n) [draw, circle, inner sep=0pt, minimum size=9mm] {}
          (n.north) +(0,-1.5mm) node [charge node] {$#1$}
          (n.south) +(0,1.5mm) node [charge node] {$#2$}
          (n.west) +(1.5mm,0) node [charge node] {$#3$}
          (n.east) +(-1.5mm,0) node [charge node] {$#4$}
          ;
      }
    }
  }
  \begin{tikzpicture}
    \path pic at (10mm,0) {sum block={+}{-}{+}{-}}
    pic at (20mm,0) {sum block={}{+}{-}{}}
    ;
  \end{tikzpicture}
\end{document}

charge pics

  • 1
    Nice style n args solution! I modified it a little bit using alias and append after command to enable a node creation syntax like \node [sum block={-}{+}{}{}] {}; This is especially useful when the node is on a chain with automatic join. – salviati Mar 23 '15 at 2:55
  • @salviati Can you post your finel solution please? – OHLÁLÁ Sep 17 '15 at 9:43
  • If I would like to draw two crossed diagonals, how can it be done? – Diaa Nov 15 '18 at 11:36
  • @Diaa Ask a new question with a minimal example (code) and a pointer to this answer, if it is relevant. I have no idea what you mean and can't answer here anyway. – cfr Nov 16 '18 at 3:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.