
我對路徑和節點的適當間距有疑問。
我想要下面的圖:
我目前正在使用這段程式碼:
\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}
在隱藏節點上這條指令。所有其他箭頭一開始都在其節點上完全對齊,但這個箭頭只是以一點距離開始。
免責聲明:這是我第一次嘗試使用 TikZ和上面的程式碼是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}