这个问题继续我的其他。
我的代码:
\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}
问题处理了这一[->] (input y) -- node {$y$} node[pos = .95] {$-$} (sum);
行。可以将这一行简化为一个node
语句,如下所示:
- 自动标记
y
。 - 通过
-
进行自身对齐pos = .95
。
提前感谢您的努力!
答案1
对于上图我将编写以下代码:
\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}
答案2
实际上,您只是将其变成了一行代码。它不是两条指令,而是 TikZ 针对同一路径收集的两个对象。想象一下,如果您没有此功能,那么当您尝试实现更多节点时,情况会比这更糟糕,而且您会抱怨得更厉害。
但是在这里,如果您实际指定了连接对象(因为您闻起来像个程序员)并带有适当的信号符号,效果可能会更好。
\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}