我需要它看起来完全像这样:
这是我取得的进展,但我被困住了:
\documentclass[10pt, a4paper] {article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage [Symbol]{upgreek}
\usepackage{tikz}
\begin{document}
\begin{figure}[!htb]
\begin{tikzpicture}
\draw[ultra thick] [ | ->] (0,4.4) --(3,4.4)
\draw[fill=white] (4,4) rectangle (5,5);
\begin{scope}[xshift=-1cm] \draw [fill=white] (4,4) rectangle (5,5);
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
你知道你不需要有要使用 TikZ,这里有一个替代方案元帖子。您需要使用lualatex
TeX 版本来编译此示例。
\documentclass[border=5mm]{standalone}
\usepackage{luatex85}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
def drawtailarrow expr p = _apth := p; _fintarr enddef;
def _fintarr text t =
draw (up--down) scaled 3 shifted point 0 of _apth t;
draw _apth t;
filldraw arrowhead _apth t
enddef;
beginfig(1);
numeric ht, wd; ht = 21; wd = 34;
path box[];
box1 = unitsquare xscaled wd yscaled ht;
box3 = box1 shifted (3 wd, 0);
box5 = box1 shifted (6 wd, 0);
box2 = unitsquare scaled ht shifted point 1 of box1;
box4 = unitsquare scaled ht shifted point 1 of box3;
box6 = unitsquare scaled ht shifted point 1 of box5;
z0 = center box1 shifted (-3/2 wd, 0);
label("$C$", z0);
label("$4$", center box1);
label("$6$", center box3);
label("$6$", center box5);
label("Nil", center box6);
forsuffixes $=1,2,3,4,5,6: draw box$ withcolor 3/4 blue; endfor
interim linecap := 0; % these parameters improve the look of
interim linejoin := 0; % the arrows drawn with a fat pen
interim ahangle := 30;
drawoptions(withpen pencircle scaled 1.2 withcolor 2/3 red);
drawtailarrow z0 shifted 10 right -- point 7/2 of box1;
drawtailarrow center box2 -- point 7/2 of box3;
drawtailarrow center box4 -- point 7/2 of box5;
drawoptions();
endfig;
\end{mplibcode}
\end{document}
答案2
这是对您的欢迎。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{shapes.multipart,chains}
\begin{document}
\begin{tikzpicture}[mp/.style args={#1/#2}{rectangle split,rectangle split horizontal,
rectangle split parts=2,text width=2em,align=center,minimum height=2.2em,
on chain,draw,node contents={#1\nodepart[text width=3em]{two}#2}}]
\begin{scope}[start chain=going right,node distance=4em]
\node[on chain](C) {C};
\node (A1)[mp=4/~];
\node (A2)[mp=4/~];
\node (A3)[mp=6/Nil];
\end{scope}
\draw[very thick,|-latex] (C) -- (A1);
\foreach \X in {1,2}
{\draw[very thick,|-latex] (A\X.two north|-A\X) -- (A\the\numexpr\X+1);}
\end{tikzpicture}
\end{document}
将来,请始终发布您尝试过的代码,切勿使用屏幕截图(否则您真的希望其他人从中输入文本),也不要使用代码链接(因为这些链接可能会失效,并且通常不要在互联网上跟踪随机链接)。此外,您的屏幕截图描绘了一个代码片段。但是,希望发布以 开头、\documentclass
以 结尾\end{document}
、尽可能简洁并且可以编译的完整文档。
这是带注释的版本。显然,注释不会像手册那么详细。
\documentclass[tikz,border=3mm]{standalone}
% we load two libraries. shapes.multipart allows us to draw partitioned boxes
% and chains makes it possible to place nodes along chains
\usetikzlibrary{shapes.multipart,chains}
\begin{document}
\begin{tikzpicture}[mp/.style args={#1/#2}{ %<- defines a style that takes 2 args
rectangle split,%<- we want a partitioned rectangle
rectangle split horizontal,%<- the partitions should be horizontal
rectangle split parts=2,%<- two partitions, please
text width=2em,%<- overall text width (we will change the second one
align=center,%<- texts should be centered
minimum height=2.2em,%<- selfexplantory
on chain,%<- puts them on the chain
draw,%<- draw node boundaries
node contents={#1\nodepart[text width=3em]{two}#2}}
]% ^ here we specify how the arguments are to be used
% whatever is before the / will go in the first part,
% what comes after in the second
\begin{scope}[start chain=going right,% start a chain growing to the right
node distance=4em]% distance between nodes
\node[on chain](C) {C};
\node (A1)[mp=4/~]; %<- use the mp style to create a node of name A1
% with first part 4 and second part just a space (standard trick)
\node (A2)[mp=4/~];
\node (A3)[mp=6/Nil];
\end{scope}
\draw[very thick,|-latex] (C) -- (A1);
\foreach \X in {1,2}
{\draw[very thick,|-latex] (A\X.two north|-A\X) -- (A\the\numexpr\X+1);
% ^ draws the arrow from the center of the right partition of node \X
% to node \X+1 (we need to evaluate \X+1, hence \the\numexpr)
}
\end{tikzpicture}
\end{document}
附录:对 lucky1928 的扩展评论/回复,他建议使用join
。这是一个好主意,但必须对第一个节点进行一些额外的处理。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{shapes.multipart,chains}
\begin{document}
\begin{tikzpicture}[mp/.style args={#1/#2}{rectangle split,rectangle split horizontal,
rectangle split parts=2,text width=2em,align=center,minimum height=2.2em,
on chain,draw,join,node contents={#1\nodepart[text width=3em]{two}#2}}]
\begin{scope}[start chain=going right,node distance=4em,
every join/.style={very thick,|-latex,to path={(\tikztostart.two north|-\tikztostart) -- (\tikztotarget)}}]
\node[on chain,rectangle split,rectangle split horizontal,
rectangle split parts=2,inner xsep=0.5pt](C) {C};
\node (A1)[mp=4/~];
\node (A2)[mp=4/~];
\node (A3)[mp=6/Nil];
\end{scope}
\end{tikzpicture}
\end{document}
答案3
这里有一种方法pstricks
:
\documentclass{article}
\usepackage{geometry}
\usepackage{array, bigstrut}
\newcommand{\mybox}[1]{%
\setlength{\bigstrutjot}{1.5ex}
\begin{tabular}{|>{\centering}p{3em}|>{\centering\arraybackslash}p{1.6em}|}%
\hline
\bigstrut #1 \tabularnewline
\hline
\end{tabular}
}%
\usepackage{pst-node, pst-arrow, auto-pst-pdf}
\begin{document}
\begin{psmatrix}[colsep=1.2cm]
[name =C]C &\mybox{4 & \pnode[0, 0.7ex]{A}} & \mybox{ 6 & \pnode[0, 0.7ex]{B}} & \mybox{ 6 & Nil}
\psset{linewidth=1.33pt, arrows=|-v, veearrowangle=60, veearrowlength=2mm, veearrowlinewidth=1.33pt, linejoin=1, nodesepB=-2.67pt}
\ncline[nodesepA=0.75em]{C}{1,2}\ncline{A}{1,3}\ncline{B}{1,4}
\end{psmatrix}
\end{document}