5

I need it to look exactly like this:

Photo of printed page

This is how far I got, but I’m stuck:

Photo of screen

\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}
  • 2
    Welcome to TeX.SE! Can you help us to help you by posting your code as text please? And making sure that it is a complete, compilable example? – Thruston Nov 19 at 17:52
  • \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} – peachblossom Nov 19 at 17:57
  • Do you mean like this? – peachblossom Nov 19 at 17:58
  • 1
    Please remove the comment and edit the question... And be sure to include the \documentclass... parts. – Thruston Nov 19 at 17:59
10

And just so you know that you don't have to use TikZ, here's an alternative in Metapost. You will need to compile this example with the lualatex version of TeX.

enter image description here

\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}
  • Thanks for your dedication to providing good metapost answers Thruston. To anyone reading, while this answer might look slightly longer, it also saves loading several thousand (?) lines of code/predefined macros in the background. – Scott H. Nov 20 at 6:24
  • @ScottH. It is certainly true that it loads less packages, but personally I feel that one should also add that it relies on external code that has many many lines. You can always create some external software and thus keep the number of lines that LaTeX loads small. But it does not mean that the code in the background is small. Also one could argue that, unfortunately, as of now arXiv does not yet support lualatex, so it can be advantageous to rely on LaTeX packages only, which also do not require the -shell-escape flag. – Schrödinger's cat Nov 20 at 20:08
9

This is to give you a welcome.

\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}

enter image description here

For the future, please always post the code that you have tried, never use screen shots (or do you really expect others to punch in the text from these), nor links to codes (because these links may die, and it is generally not a good idea to follow random links on the internet). Also your screen shot depicts a code fragment. However, it is expected that one posts complete documents that start with \documentclass, end with \end{document}, are as minimal as possible, and can be compiled.

And here is an annotated version. Clearly, annotations won't be as detailed as the manual.

\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}

ADDENDUM: An extended comment/reply to lucky1928, who suggested to use join. It is a great idea but some extra treatment has to be applied to the first node.

\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}

enter image description here

  • 1
    @peachblossom No worries. You're welcome! – Schrödinger's cat Nov 19 at 18:02
  • 1
    @peachblossom You just copy it into the question, put it into the cursor (while editing) and then press the button that looks a bit like {}. This does the formatting. – Schrödinger's cat Nov 19 at 18:04
  • 1
    @peachblossom Done. – Schrödinger's cat Nov 19 at 18:18
  • 1
    @peachblossom You may think of it as a function (or macro) that takes two arguments and does something with them. In this case, the arguments are separated by a / (for no deep reason except that this can be more easily thrown under a /.list key but here I didn't use it). #1 is the place holder for the first argument, and #2 for the second. So if you say \node (A)[mp=pft/blub];, you will get pft in the first box and blub in the second. – Schrödinger's cat Nov 20 at 0:26
  • 1
    @peachblossom selfexplantory is a typo, it should read selfexplanatory and just indicates that the minimum height height key specifies the minimal height of the corresponding node. In the beginning these keys may appear a bit strange, but I have used PSTricks for almost 20 years and produced hundreds of diagrams with MetaPost. After having seen what TikZ can do, I quit PSTricks completely and use MetaPost only for very specialized applications. After a very short time one can do so many things so easily, precisely because of the styles and relative positioning. – Schrödinger's cat Nov 20 at 0:37
5

Here is a way with 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} 

enter image description here

  • 1
    Thanks again for a wonderful example :) – peachblossom Nov 19 at 22:41
  • Love PsTricks... – MadyYuvi Nov 21 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.