1

This question continues my another.

My code:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{
         signal/.style = coordinate,
         sum/.style = {
                       draw,
                       circle,
                       inner sep = 0pt,
                       minimum size = 2mm
                      }
        }

\begin{document}

  \begin{tikzpicture}[auto]

    %placing the nodes
    \node[signal] (input x) {};
    \node[
          sum,
          right = of input x
         ] (sum) {};
    \node[
          signal,
          above=of sum
         ] (input y) {};
    \node[
          signal,
          right=of sum
         ] (output) {};

    %connecting the nodes
    \draw
      [->] (input x) -- node {$x$} (sum);
    \draw
      [->] (input y) -- node {$y$} node[pos = .95] {$-$} (sum);
    \draw
    [->] (sum)       -- node {$z$} (output);

  \end{tikzpicture}

\end{document}

The question handles this [->] (input y) -- node {$y$} node[pos = .95] {$-$} (sum); line. It is possible to reduce this line to one node statement, with:

  1. Auto labeling for the y.
  2. The - gets its own aligning by pos = .95.

Thank you for your effort in advance!

  • Combine two nodes in one to do what ? Put the two texts one on top of the other ? – Kpym Apr 17 '18 at 21:20
  • Hello @Kpym! Thank you for your comment! It is only a question to discover the possibilities for this case. The result should stay the same. – Su-47 Apr 17 '18 at 21:31
  • For me it is not clear what is "this case" : if you move the position of the nodes is it "the same" case ? If you want two nodes at position .5 and .95, you can't combine them in one node that will produce the same output in general. – Kpym Apr 18 '18 at 9:59
  • Hello @Kpym! Thank you for your comment! Sorry for my unclear english, hope now it's clear. – Su-47 Apr 18 '18 at 22:16
4

enter image description here

for above image i would write the following code:

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{positioning, quotes}

\tikzset{sum/.style = {
                       draw,
                       circle,
                       inner sep = 0pt,
                       minimum size = 2mm
                      }
        }

\begin{document}
    \begin{tikzpicture}[auto]
%placing the coordinates and node
\coordinate (input x);
\node[sum,right=of input x] (sum) {};
\coordinate[above=of sum] (input y);
\coordinate[right=of sum] (output);
%connecting the nodes
\draw [->]  (input x) edge ["$x$"] (sum)
            (input y) edge ["$y$", "$-$"pos=.95] (sum)
            (sum)      to  ["$z$"] (output);

  \end{tikzpicture}
\end{document}
  • This is the accepted answer, so probably the question was about the "shortest" way to put two nodes on the edge. If this is the case, probably a simpler code will be edge ["$y$", "$-$"pos=.95]. – Kpym Apr 19 '18 at 5:27
  • @Kpym, thank yo very much. now is considered in answer. – Zarko Apr 19 '18 at 5:34
3

Actually you are making it a one-liner. It is not two instructions but two objects collected by TikZ for the same path. Imagine you didn't have this functionality, then it would smell way worse than this when you try to implement more nodes and you would be complaining much harder.

But here you might be better of if you actually specify the junction object (since you smell like a programmer) with proper signal signs.

\documentstyle[tikz]{standalone}
\usetikzlibrary{positioning}
\tikzset{signal/.style = coordinate,
  sum/.style = {draw,circle,inner sep = 0pt,minimum size = 2mm, junction labels/.list={#1}},
  sum/.default={0}{},
  junction labels/.style args={#1/#2}{label={#1:#2}},
}

\begin{document}
  \begin{tikzpicture}[auto]
    %placing the nodes
    \node[signal] (input x) {};
    \node[sum={30/$-$,-130/$+$,-60/$\circ$},right = of input x] (sum) {};
    \node[signal,above=of sum] (input y) {};
    \node[signal,right=of sum] (output) {};

    %connecting the nodes
    \draw[->] (input x) -- node {$x$} (sum);
    \draw[->] (input y) -- node {$y$}  (sum);
    \draw[->] (sum) -- node {$z$} (output);
  \end{tikzpicture}
\end{document}

enter image description here

  • You smell a bit angry;-) (+1) – user121799 Apr 17 '18 at 22:53
  • Haha, not really, just following the cue – percusse Apr 17 '18 at 22:55
  • Hello @marmot and @percusse! You guys are funny! Anyway thank you for the answer! – Su-47 Apr 18 '18 at 22:11

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.