5

I would like to modify the code of this answer

\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}

to get the output of this answer of a summation circle with four input ports separated by two perpendicular diameters.


Additionally, if the circle is drawn by

\documentclass{article}
\usepackage{tikz,mathtools,amssymb}
\usetikzlibrary{shapes,arrows,positioning,calc}

\begin{document}
    \tikzset{
        port/.style     = {inner sep=0pt, font=\tiny},
        sum/.style n args = {4}{draw, circle, node distance = 2cm, minimum size=5mm, alias=sum,%https://tex.stackexchange.com/a/234545/2288
            append after command={
                node at (sum.north) [port, below=1pt] {$#1$}
                node at (sum.west) [port, right=1pt] {$#2$}
                node at (sum.south) [port, above=1pt] {$#3$}
                node at (sum.east) [port, left=1pt] {$#4$}}},
        }
    \begin{tikzpicture}[auto, node distance=5mm,>=latex',align=center,]
    \node [sum={}{+}{-}{}] (sum) {};
    \end{tikzpicture}   
\end{document}

how can the two prependicular diameters be drawn?

enter image description here

Diaa
  • 9,599

1 Answers1

6

Do you mean 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$}
          ;
        \draw
          (n.north west) -- (n.south east)
          (n.south west) -- (n.north east)
          ;
      }
    }
  }
  \begin{tikzpicture}
    \path pic at (10mm,0) {sum block={+}{-}{+}{-}}
    pic at (20mm,0) {sum block={}{+}{-}{}}
    ;
  \end{tikzpicture}
\end{document}

enter image description here

It is possible to also append the lines in your second variant. And thanks to @marmot, it is possible to do so without paying further attention:

\documentclass{standalone}
\usepackage{tikz}

\tikzset
  {
    port/.style     = {inner sep=0pt, font=\tiny},
    cross/.style =
      {%
        path picture=%
          {
            \draw
              (path picture bounding box.north west) --
                (path picture bounding box.south east)
              (path picture bounding box.south west) --
                (path picture bounding box.north east)
              ;
          }
      },
    sum/.style n args = {4}%
      {%
        draw, circle, node distance = 2cm, minimum size=5mm, cross, alias=sum,%https://tex.stackexchange.com/a/234545/2288
        append after command=%
          {%
            node at (sum.north) [port, below=1pt] {$#1$}
            node at (sum.west) [port, right=1pt] {$#2$}
            node at (sum.south) [port, above=1pt] {$#3$}
            node at (sum.east) [port, left=1pt] {$#4$}
          },
      },
  }
\begin{document}
\begin{tikzpicture}
  \node [sum={}{+}{-}{}] (b) {};
\end{tikzpicture}   
\end{document}

enter image description here

Skillmon
  • 60,462
  • Exactly. May I know how can I draw the two diameters in the second case that I appended to my question? – Diaa Nov 16 '18 at 09:20
  • Off-topic question: is it possible to declare multiple nodes using one single command \node? – Diaa Nov 18 '18 at 11:14
  • @Diaa \node is the same as \path node so you can specify further nodes using \node (a) {a} node (b) {b} .... – Skillmon Nov 18 '18 at 14:14