我对路径和节点的适当间距有疑问。
我想要下面这张图:
我目前正在使用这个代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta, positioning, calc}
\begin{document}
\begin{tikzpicture}[node distance=1cm, auto]
\tikzset{
block/.style= {draw, rectangle, align=center,minimum width=2cm,minimum height=1cm},
>={Classical TikZ Rightarrow[length=1.7mm]},
XOR/.style={draw,circle,append after command={
[shorten >=\pgflinewidth, shorten <=\pgflinewidth,]
(\tikzlastnode.north) edge (\tikzlastnode.south)
(\tikzlastnode.east) edge (\tikzlastnode.west)}}
}
%}
\node[] (k) {k};
\node[right=of k] (t) {t};
\node[block, below =2cm of t] (AES) {AES};
\node[above =1cm of AES] (splitof) {};
\node[XOR, below =1cm of AES] (xor) {};
\node[below =1.5cm of xor] (c) {c};
%% paths
\path[draw,->] (k) |- (AES);
\path[draw,->] (AES) edge (xor);
\path[draw,->] (t) edge (AES);
\path[draw,->,style={shorten <=-1.1mm}] (splitof) -- +(2, 0) |- (xor);
\path[draw,->] (xor) edge (c);
\end{tikzpicture}
\end{document}
我不明白为什么我需要style={shorten <=-1.1mm}
在隐藏节点上使用这个指令。所有其他箭头在它们的节点上都完全对齐,但这个箭头只是在节点上稍微留出一点空间。
免责声明:这是我第一次尝试使用 Ti钾Z 和上面的代码是 c&p 工作。
答案1
您应该使用坐标而不是“隐藏节点”,因为它似乎\node[above =1cm of AES, text width=0mm, inner sep=0mm, outer sep=0mm] (splitof) {};
需要一些空间。
以下是无需缩短即可运行的代码:
% arara: pdflatex
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\begin{document}
\begin{tikzpicture}
\tikzset{%
,block/.style={%
,draw
,rectangle
,align=center
,minimum width=2cm
,minimum height=1cm
}
,>={Classical TikZ Rightarrow[length=1.7mm]}
,XOR/.style={%
,draw
,circle,append after command={%
[shorten >=\pgflinewidth, shorten <=\pgflinewidth,]
(\tikzlastnode.north) edge (\tikzlastnode.south)
(\tikzlastnode.east) edge (\tikzlastnode.west)
}
}
}
\node (k) {k};
\node[right=of k] (t) {t};
\node[block, below =2cm of t] (AES) {AES};%
\coordinate[above =1cm of AES] (splitof) {};
\node[XOR, below =1cm of AES] (xor) {};
\node[below =1.5cm of xor] (c) {c};
\path[draw,->] (k) |- (AES);
\path[draw,->] (AES) edge (xor);
\path[draw,->] (t) edge (AES);
\path[draw,->] (splitof) -- +(2, 0) |- (xor);
\path[draw,->] (xor) edge (c);
\end{tikzpicture}
\end{document}