设置线上的节点的通常方法应该是这样的:
\begin{tikzpicture}
% place nodes
\node[draw] at (0, 0) (a) {A};
\node[draw] at (5, 0) (b) {B};
\node[draw] at (0, -2) (c) {C};
\node[draw] at (5, -2) (d) {D};
% draw edges
\draw[] (a) -- (b) node[near start, above] {$x(kT)$};
\draw[] (c) -- (d) node[near start, above] {$y(kT)$};
\end{tikzpicture}
但在这里我发现有点烦人,节点的位置取决于线的长度(我试图在上面的例子中说明这一点)。我想要的是,节点完全处于相同的位置。为了实现这一点,我必须这样写:
\begin{tikzpicture}
% place nodes
\node[draw] at (0, -4) (a2) {A};
\node[draw] at (3, -4) (b2) {B};
\node[draw] at (0, -6) (c2) {C};
\node[draw] at (5, -6) (d2) {D};
% draw edges
\draw[] (a2.east) -- (b2) node[at start, above right] {$x(kT)$};
\draw[] (c2.east) -- (d2) node[at start, above right] {$y(kT)$};
\end{tikzpicture}
所以我的问题是,有没有更直观的方法来做这样的事情(类似于near start
/ at start
node选项)?
答案1
也许这太过简单或不够自动化,无法满足您的实际需求,但我认为根据问题文本和评论,简单的方法xshift=<shift-dimension>
就可以了。您可以(可选)将其包装成样式(此处为near start abs
),以便可以根据需要全局调整距离。
\documentclass[tikz]{standalone}
\tikzset{near start abs/.style={xshift=1cm}}
\begin{document}
\begin{tikzpicture}
% place nodes
\node[draw] at (0, 0) (a) {A};
\node[draw] at (3, 0) (b) {B};
\node[draw] at (0, -2) (c) {C};
\node[draw] at (5, -2) (d) {D};
% draw edges
\draw[] (a) node[above,xshift=1cm] {$x(kT)$} -- (b);
\draw[] (c) node[above,xshift=1cm] {$y(kT)$} -- (d);
\draw (0,-3) node[above,near start abs] {Test} -- ++(7,0);
\end{tikzpicture}
\end{document}