\begin{center}
\scalebox{0.8}{
\begin{tikzpicture}
% directory
\xyshift{+00mm}{+00mm}{\exthashidxdirectoryeight{directory}{3}}
% buckets
\xyshift{+20mm}{+50mm}{\exthashidxbucketfour{A}{3}{}{}{64}{16}}
\xyshift{+20mm}{+25mm}{\exthashidxbucketfour{B}{2}{1}{5}{21}{}}
\xyshift{+20mm}{+00mm}{\exthashidxbucketfour{C}{2}{10}{}{}{}}
\xyshift{+20mm}{-25mm}{\exthashidxbucketfour{D}{2}{15}{7}{51}{}}
\xyshift{+20mm}{-50mm}{\exthashidxbucketfour{A2}{4}{4}{12}{20}{36}}
\xyshift{+20mm}{-75mm}{\exthashidxbucketfour{A3}{4}{12}{}{}{}}
% links
\exthashidxlink{directory-0000}{A}
\exthashidxlink{directory-0001}{B}
\exthashidxlink{directory-0010}{C}
\exthashidxlink{directory-0011}{D}
\exthashidxlink{directory-0100}{A2}
\exthashidxlink{directory-0101}{B}
\exthashidxlink{directory-0110}{C}
\exthashidxlink{directory-0111}{D}
\exthashidxlink{directory-1000}{A}
\exthashidxlink{directory-1001}{B}
\exthashidxlink{directory-1010}{C}
\exthashidxlink{directory-1011}{D}
\exthashidxlink{directory-1100}{A3}
\exthashidxlink{directory-1101}{B}
\exthashidxlink{directory-1110}{C}
\exthashidxlink{directory-1111}{D}
\end{tikzpicture}
}
\结束{中心}
受到以下答案的启发如何使用 Tikz 库绘制可扩展哈希/跳过列表图?,我想画一个这样的图形。 但是,我的代码无法成功编译,并且显示“Package pff 错误:没有已知名为 directory-0000 的形状” 我不知道如何绘制这样的图形。提前感谢帮助。
答案1
如果想要四个二进制数,则需要使用\exthashidxdirectorysixteen
而不是\exthashidxdirectoryeight
。
\documentclass[12pt, a4paper]{article}
\usepackage{exthashidx}
\renewcommand{\exthashidxlink}[2]{
\draw[ehilink] (#1.east) -- (#2-a.west);
}
\begin{document}
\begin{center}
\scalebox{0.8}{
\begin{tikzpicture}
% directory
\xyshift{+00mm}{+00mm}{\exthashidxdirectorysixteen{directory}{3}}
% buckets
\xyshift{+20mm}{+50mm}{\exthashidxbucketfour{A}{3}{}{}{64}{16}}
\xyshift{+20mm}{+25mm}{\exthashidxbucketfour{B}{2}{1}{5}{21}{}}
\xyshift{+20mm}{+00mm}{\exthashidxbucketfour{C}{2}{10}{}{}{}}
\xyshift{+20mm}{-25mm}{\exthashidxbucketfour{D}{2}{15}{7}{51}{}}
\xyshift{+20mm}{-50mm}{\exthashidxbucketfour{A2}{4}{4}{12}{20}{36}}
\xyshift{+20mm}{-75mm}{\exthashidxbucketfour{A3}{4}{12}{}{}{}}
% links
\exthashidxlink{directory-0000}{A}
\exthashidxlink{directory-0001}{B}
\exthashidxlink{directory-0010}{C}
\exthashidxlink{directory-0011}{D}
\exthashidxlink{directory-0100}{A2}
\exthashidxlink{directory-0101}{B}
\exthashidxlink{directory-0110}{C}
\exthashidxlink{directory-0111}{D}
\exthashidxlink{directory-1000}{A}
\exthashidxlink{directory-1001}{B}
\exthashidxlink{directory-1010}{C}
\exthashidxlink{directory-1011}{D}
\exthashidxlink{directory-1100}{A3}
\exthashidxlink{directory-1101}{B}
\exthashidxlink{directory-1110}{C}
\exthashidxlink{directory-1111}{D}
\end{tikzpicture}
}
\end{center}
\end{document}
我还重新定义了\exthashidxlink
。我还想礼貌地告诉你不要使用这个包,而是使用标准 Ti钾Z 工具。说实话(但请不要将此解释为一种攻击性)样式文件远非最佳,迟早你会遇到无法轻易解决的问题。所以我会用一些基本的 Ti钾Z 命令如下。
\documentclass[12pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart,positioning}
\newcommand{\fourdigits}[1]{%
\ifnum #1<10 0%
\fi%
\ifnum #1<100 0%
\fi%
\ifnum #1<1000 0%
\fi%
\number #1
}
\tikzset{bucket/.style={draw,rectangle split,rectangle split
horizontal,rectangle split parts=#1,text width=.5cm,anchor=west},
mybox/.style={rectangle,draw,minimum width=1.5cm,minimum height=0.5cm}}
\newcommand{\mybucketfour}[7][]{
\node[bucket=4,#1] (#2){#4
\nodepart{two}
#5
\nodepart{three}
#6
\nodepart{four}
#7
};
\node[draw,above left=0pt of #2.north west,anchor=south west,fill=gray!30,
text width=.5cm,yshift=-\pgflinewidth]{\textbf{#3}};
}
\newcommand{\Connect}[3][-latex]{\draw[#1] (#2) to[out=0,in=180] (#3);}
\begin{document}
\begin{center}
\begin{tikzpicture}[font=\sffamily,node distance=1.5cm]
% directory
\begin{scope}[xshift=-4cm,yshift=2cm]
\foreach \X [count=\Y] in {0,...,15}
{\pgfmathsetmacro{\Bin}{bin(\X)}
\ifnum\X=0
\node[mybox,label=left:{\fourdigits{\Bin}},alias=directory-\fourdigits{\Bin}] (box-\Y) {};
\else
\node[mybox,below=0.2cm of box-\X,label=left:{\fourdigits{\Bin}},
alias=directory-\fourdigits{\Bin}] (box-\Y) {};
\fi
}
\end{scope}
% buckets
\mybucketfour{A}{3}{}{}{64}{16}
\mybucketfour[below=of A.west,anchor=west]{B}{2}{1}{5}{21}{}
\mybucketfour[below=of B.west,anchor=west]{C}{2}{10}{}{}{}
\mybucketfour[below=of C.west,anchor=west]{D}{2}{15}{7}{51}{}
\mybucketfour[below=of D.west,anchor=west]{A2}{4}{4}{12}{20}{36}
\mybucketfour[below=of A2.west,anchor=west]{A3}{4}{12}{}{}{}
% links
\Connect{directory-0000}{A}
\Connect{directory-0001}{B}
\Connect{directory-0010}{C}
\Connect{directory-0011}{D}
\Connect{directory-0100}{A2}
\Connect{directory-0101}{B}
\Connect{directory-0110}{C}
\Connect{directory-0111}{D}
\Connect{directory-1000}{A}
\Connect{directory-1001}{B}
\Connect{directory-1010}{C}
\Connect{directory-1011}{D}
\Connect{directory-1100}{A3}
\Connect{directory-1101}{B}
\Connect{directory-1110}{C}
\Connect{directory-1111}{D}
\end{tikzpicture}
\end{center}
\end{document}
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[
>={Stealth[scale=1.5]},
bullet/.style={
fill=black,
circle,
inner sep=1pt
},
projection/.style={
->,
thick,
shorten <=2pt,
shorten >=2pt
},
]
\draw (0, 0) circle [x radius=1, y radius=1.7];
\node [bullet, label=left:\( a \)] (a) at (0,1.2) {};
\node [bullet, label=left:\( b \)] (b) at (0,0.4) {};
\node [bullet, label=left:\( c \)] (c) at (0,-0.4) {};
\node [bullet, label=left:\( d \)] (d) at (0,-1.2) {};
\node[font=\large] (E) at (0, 2) {\(E\)};
\begin{scope}[xshift=3.5cm]
\draw (0, 0) circle [x radius=1, y radius=1.7];
\node [bullet, label=right:\( \tilde{a} \)] (w) at (0,1.2) {};
\node [bullet, label=right:\( \tilde{b} \)] (x) at (0,0.4) {};
\node [bullet, label=right:\( \tilde{c} \)] (h) at (0,-0.4) {};
\node [bullet, label=right:\( \tilde{d} \)] (v) at (0,-1.2) {};
\node[font=\large] (F) at (0, 2) {\(F\)};
\end{scope}
\draw [projection] (a) -- (x);
\draw [projection] (b) -- (h);
\draw [projection] (c) -- (v);
\draw [projection] (d) -- (x);
\end{tikzpicture}
\end{document}