12

enter image description here

I tried to draw this picture with TikZ but unfortunately I didn't succeed. I would be very grateful for any help! This is what I've done so far:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,fadings,calc,positioning,decorations.pathreplacing,arrows}


\begin{document}

\begin{figure}
\centering

% Define block styles
\tikzstyle{algo} = [text centered, minimum height=.5em, node font=\footnotesize] 
\tikzstyle{weight} = [rectangle, draw, text width=10em, text centered, minimum height=.1em, node font=\footnotesize]
\tikzstyle{length} = [rectangle, text width=10em, text centered, minimum height=.1em, node font=\footnotesize]

\begin{tikzpicture}
%Place nodes
\node [algo] (leer) {};
\node [algo, below of=leer] (plain) {Plain ISD:};
\node [algo, below of=plain] (lee) {Lee-Brickell:};
\node [algo, below of=lee] (leon) {Leon:};
\node [algo, below of=leon] (stern) {Stern:};


\node [weight, right of=plain, node distance=3cm] (plainone) {$0$};
\node [weight, right of=plainone, node distance=3.7cm] (plaintwo) {$\varepsilon$};
\node [weight, right of=lee, node distance=3cm] (leeone) {$p$};
\node [weight, right of=leeone, node distance=3.7cm] (leetwo) {$\varepsilon-p$};

\node [length, above of=plainone] (leerk) {$k$};
\node [length, above of=plaintwo] (leernk) {$n-k$};


\draw [stealth' - stealth', semithick] (leerk.south west)  -- (leerk.south east);
\draw [stealth' - stealth', semithick] (leernk.south west)  -- (leernk.south east);

\end{tikzpicture}
\end{figure}
\end{document}
6

Here's an alternative version drawn with Metapost wrapped up in luamplib (so compile with lualatex or adapt it for GMP or plain MP).

enter image description here

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
% a routine to draw each box.
% Arguments: name, followed by pairs of strings / numerics
% 
vardef algobox(expr name)(text specs) = 
    save p, s, w, i, j;
    % step through the spec and save the strings and widths
    string s[];  numeric w[]; numeric i, j; i = j = 0;
    for $=specs:
        if string $: s[incr i] elseif numeric $: w[incr j] fi := $; 
    endfor
    numeric x; x = 0; path b;
    % make a picture to return
    picture p; p = image(
        for k=1 upto i:
            % define the box then fill it and draw it
            b := unitsquare yscaled dp xscaled (w[k]-gap) shifted (x,0);
            fill b withcolor 7/8[green+red, white]; draw b;
            % do the labels with special case for "split" labels
            if substring (0,1) of s[k] = ":":
                label(substring (1,infinity) of s[k], (x + 1/4 w[k], 1/2 dp));
                label(substring (1,infinity) of s[k], (x + 3/4 w[k], 1/2 dp));
                draw (x + 1/2 w[k], 0) -- (x + 1/2 w[k], dp) dashed evenly scaled 1/2;
            else:
                label(s[k], (x + 1/2 w[k], 1/2 dp));
            fi
            % advance x
            x := x + w[k];
        endfor
        % add the name
        label.rt(name, (x, 1/2 dp));
    ); p
enddef;

beginfig(1);
    % some parameters to control the dp of the boxes, the gap between them 
    % and the values of l, k, and n
    numeric dp, gap, k, l, n; 
    l = 40; k = 100;  n = 240; dp = 14; gap = 2;

    % draw the labelled boxes, shifted as desired...
    draw algobox("Plain ISD",    "$0$", k, "$t$", n-k);
    draw algobox("Lee-Brickell", "$p$", k, "$t-p$", n-k)                        shifted 25 down;
    draw algobox("Leon", "$p$", k, "$0$", l, "$t-p$", n-k-l)                    shifted 80 down;
    draw algobox("Stern", "$p$", 1/2k, "$p$", 1/2k, "$0$", l, "$t-2p$", n-k-l)  shifted 105 down;
    draw algobox("Finiasz/Sendrier", ":$p$", k+l, "$t-2p$", n-k-l)              shifted 130 down;
    draw algobox("Bernstein (Ball)", ":$p_1$", k, ":$p_2$", l, "$t-2p_1 - 2p_2$", n-k-l) shifted 155 down;

    % define some paths for the arrows
    path a[];
    a1 = (0,24) -- (k-gap,24);
    a2 = (k,24) -- (n-gap,24);
    a3 = (k,-56) -- (k+l-gap, -56);
    a4 = (k+l,-56) -- (n-gap, -56);

    % and draw them (with narrower arrow heads)
    ahangle := 30;
    drawdblarrow a1; label.top("$k$", point 1/2 of a1);
    drawdblarrow a2; label.top("$n-k$", point 1/2 of a2);
    drawdblarrow a3; label.top("$\ell$", point 1/2 of a3);
    drawdblarrow a4; label.top("$n-k-\ell$", point 1/2 of a4);

endfig;
\end{mplibcode}
\end{document}

Notes

  • The algobox macro returns a picture, which you can draw directly with draw or save etc.

  • The macro shows one way to deal with variable numbers of arguments of different types.

  • It must be possible to draw the same with asymptote. I might try that. – SPV Jan 1 '18 at 0:30
  • @Thruston Thank you for your answer! As I have never used lualatex I am a bit confused and don't know how to use it though. Is it possible to use this code in a "normal" latex document and just compile with pdflatex to generate a PDF document? Because when I tried this I got unfortunately an error "! LaTeX Error: File 'luatex85.sty' not found." – Mathuser Jan 1 '18 at 21:37
  • 2
    To use my answer with pdflatex you would need to adapt to for GMP package (link above) or just compile this to a separate PDF and use includegraphic. – Thruston Jan 2 '18 at 8:27
8

I would probably not use a TikZ picture, but a tabular with TikZ annotations. UPDATE: Boxed and unboxed texts should be aligned now.

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\newlength{\nodeshift}\setlength{\nodeshift}{1.2cm}
\usetikzlibrary{matrix,fadings,calc,positioning,decorations.pathreplacing,arrows}

\newcommand\tikznode[2]{\tikz[remember picture]{\node(#1)[inner sep=0pt]{#2};}}
\newcommand{\WeightNode}[3][3cm]{\tikz[remember picture]{%
\node(#2)[draw,minimum height=1.4em,inner sep=0pt, node font=\footnotesize,text
width=#1,text centered]{#3};}}
\newcommand{\DividedWeightNode}[3][3cm]{\tikz[remember picture]{%
\node(#2)[draw,minimum height=1.4em,inner sep=0pt, node font=\footnotesize,text
width=#1,text centered,append after command={%
  \pgfextra{ %
   \draw[densely dashed] (\tikzlastnode.north) -- (\tikzlastnode.south);
   \path (\tikzlastnode.west) -- (\tikzlastnode.center) node[midway,node font=\footnotesize]{#3};
   \path (\tikzlastnode.center) -- (\tikzlastnode.east) node[midway,node font=\footnotesize]{#3};}}
]{};}}


\newcommand{\AlgoNode}[3][3cm]{\tikz[remember picture]{%
\node(#2)[minimum height=1.4em,inner sep=0pt ,text
width=#1,text centered,align=left]{#3};}}

\begin{document}

\lipsum[1]

\begin{figure}[h]
\centering

\begin{tabular}{p{3cm}p{1.3cm}p{1.3cm}p{1cm}p{2.8cm}}
& & & & \\[0.5cm] % because the overlay may overshoot otherwise
\AlgoNode{plain}{Plain ISD:} & \multicolumn{2}{p{2.8cm}}{\WeightNode{plainone}{$0$}}
& \multicolumn{2}{p{4cm}}{\WeightNode[4cm]{plaintwo}{$t$}}\\
\AlgoNode{lee}{Lee--Brickell:} &
\multicolumn{2}{p{2.8cm}}{\WeightNode{leeone}{$p$}}
& \multicolumn{2}{p{4cm}}{\WeightNode[4cm]{leetwo}{$p-t$}}\\[1.5cm]
\AlgoNode{leon}{Leon:} &
\multicolumn{2}{p{2.8cm}}{\WeightNode{leonone}{$p$}} &
\WeightNode[1cm]{leontwo}{$0$} &
\WeightNode{leonthree}{$t-p$}\\
\AlgoNode{stern}{Stern:} & \WeightNode[1.3cm]{sternone}{$p$} & 
\WeightNode[1.3cm]{sterntwo}{$p$} &
\WeightNode[1cm]{sternthree}{$0$} &
\WeightNode[3cm]{sternfour}{$t-2p$} \\
\AlgoNode{fini}{Finiasz/Sendrier:} & 
\multicolumn{3}{p{3.8cm}}{\DividedWeightNode[4.4cm]{finione}{$p$}} &
\WeightNode{finitwo}{$t-2p$}\\
\AlgoNode{fini}{Bernstein (Ball):} & 
\multicolumn{2}{p{2.8cm}}{\DividedWeightNode{finione}{$p_1$}} &
\DividedWeightNode[1cm]{finione}{$p_2$} &
\WeightNode{finitwo}{$t-2p_1-2p_2$}\\
\end{tabular}
\end{figure}
\tikzstyle{length} = [rectangle, text centered, minimum height=.1em, node font=\footnotesize]
\begin{tikzpicture}[overlay,remember picture]
\node [length, above of=plainone,text width=2.8cm] (leerk) {$k$};
\node [overlay,length, above of=plaintwo,text width=3.8cm] (leernk) {$n-k$};
\draw [stealth' - stealth', semithick] (leerk.south west)  -- (leerk.south east);
\draw [stealth' - stealth', semithick] (leernk.south west)  -- (leernk.south east);
\node [length, above of=leontwo,text width=0.6cm] (leerl) {$\ell$};
\node [overlay,length, above of=leonthree,text width=2.8cm] (leernkl) {$n-k-\ell$};
\draw [stealth' - stealth', semithick] (leerl.south west)  -- (leerl.south east);
\draw [stealth' - stealth', semithick] (leernkl.south west)  -- (leernkl.south east);
\end{tikzpicture}

\lipsum[2]
\end{document}

enter image description here

  • Thank you very much for your helpful answer! This seems indeed easier to me than to create the whole figure with TikZ. However, it seems to me that the names aren't on the same height as the boxes. They are a bit lower, arent they? I tried to change this, but I was not able to. – Mathuser Dec 31 '17 at 16:57
  • 1
    @user151637 Made an update. Is that what you want? – user121799 Dec 31 '17 at 17:20
  • This is great, thank you! Let me please ask you one last question. I do get some overful errors, for example "Overfull \hbox (17.47137pt too wide) in paragraph at lines 48--48 [][]|". How can I get rid of them? Is it even useful to try to avoid these errors, because actually everything looks nice? – Mathuser Jan 1 '18 at 14:37
  • 1
    @user151637 Yes, in order to make the gaps between the blocks smaller, I let the overshoot the widths set by p{xcm}. Alternatively, one could use arraystretch, see e.g. here. However, I didn't want to overwrite your settings, and these warnings appeared to be the minimal damage solutions to me. – user121799 Jan 1 '18 at 14:43
5

Here is a simple solution with table with multicolumn and some TikZ

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{arydshln}
\usepackage{booktabs}
\usepackage{tikz}

\newcommand\myarrow[3]{%
\begin{tikzpicture}[remember picture, overlay, >=stealth, shorten >= 1pt]
  \draw[<->, thick] (#1,0) to (#2,0) node[midway, above]{$#3$};
\end{tikzpicture}%
}


\begin{document}

\begin{table}[!htpb]
\centering
\begin{tabular}{@{}lcclccc@{}}
                                        & \multicolumn{3}{c}{\myarrow{-1.5}{1.5}{k}}              & \multicolumn{3}{c}{\myarrow{-2}{2}{n-k}}                                                  \\[-2ex]
                                        &                            &    &                       &                            &                             &                                    \\ \cline{2-7} 
\multicolumn{1}{l|}{Plain ISD:}         & \multicolumn{3}{c|}{$0$}                                & \multicolumn{3}{c|}{$t$}                                                                      \\ \cline{2-7}
                                        &                            &    &                       &                            &                             &                                    \\ \cline{2-7} 
\multicolumn{1}{l|}{Lee-Brickell:}      & \multicolumn{3}{c|}{$p$}                                & \multicolumn{3}{c|}{$t-p$}                                                                    \\ \cline{2-7} 
                                        &                            &    &                       &                            &                             &                                    \\
                                        &                            &    &                       & \multicolumn{2}{c}{\myarrow{-0.75}{0.8}{\ell}}          & \myarrow{-1.4}{1.2}{n-k-\ell}        \\[-2ex]
                                        &                            &    &                       &                            &                             &                                    \\ \cline{2-7} 
\multicolumn{1}{l|}{Leon:}              & \multicolumn{3}{c|}{$p$}                                & \multicolumn{2}{c|}{$0$}                                 & \multicolumn{1}{c|}{$t-p$}         \\ \cline{2-7} 
                                        &                            &    &                       &                            &                             &                                    \\ \cline{2-7} 
\multicolumn{1}{l|}{Stern:}             & \multicolumn{1}{c|}{$p$}   & \multicolumn{2}{c|}{$p$}   & \multicolumn{2}{c|}{$0$}                                 & \multicolumn{1}{c|}{$t-2p$}        \\ \cline{2-7} 
                                        &                            &    &                       &                            &                             &                                    \\ \cline{2-7} 
\multicolumn{1}{l|}{Finniasz/Sendrier:} & \multicolumn{2}{c;{2pt/2pt}}{$\qquad p\qquad$}          & \multicolumn{3}{@{}c|}{$p$} & \multicolumn{1}{c|}{$t-2p$}                                        \\ \cline{2-7} 
                                        &                            &    & \multicolumn{1}{c}{}  &                            &                             &                                    \\ \cline{2-7} 
\multicolumn{1}{l|}{Bernstein (Ball):}   & \multicolumn{1}{c;{2pt/2pt}}{$\quad p_1\quad$} & \multicolumn{2}{c|}{$\quad p_1\quad$} & \multicolumn{1}{c;{2pt/2pt}}{$p_2$} & \multicolumn{1}{c|}{$p_2$} & \multicolumn{1}{c|}{$t-2p_1-2p_2$} \\ \cline{2-7} 
\end{tabular}
\end{table}

\end{document}
5

The tcbitemize environment from tcolorbox could be used, annotations can easily be added using TikZ code and allows for separate boxing of each element more easily than a table-based solution, and entering each element is slightly easier than creating a full TikZ node each time.

The main limitation of this approach (which may be down to my ignorance) is the lack of flexibility in specifying different column widths in a tcbraster. While one can use raster force size=false and add to width to each box as appropriate, this seems to be incompatible with raster multicolumn.

The basic alignment can be set up as

\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document}  
\begin{tcbitemize}[raster width=15cm,raster columns=5,
raster equal height=rows,
enhanced,sharp corners,colback=white,colframe=black,
top=0mm,bottom=0mm,
halign=center,valign=center,halign upper=center,halign lower=center,
raster left skip=0mm,raster right skip=0mm,
raster column skip=0.5mm,
raster column 1/.style={blanker,halign=left},
]
\tcbitem Plain ISD:
\tcbitem[raster multicolumn=2] $0$
\tcbitem[raster multicolumn=2] $t$
\tcbitem Lee-Brickell:
\tcbitem[raster multicolumn=2] $p$
\tcbitem[raster multicolumn=2] $t-p$
\tcbitem Leon:
\tcbitem[raster multicolumn=2] $p$
\tcbitem $0$
\tcbitem $t-p$
\tcbitem Stern:
\tcbitem $p$
\tcbitem $p$
\tcbitem $0$
\tcbitem $t-2p$
\end{tcbitemize}
\end{document}

where the raster multicolumn key creates boxes spanning over multiple columns. Box style settings can be set in the tcbitemize options, raster column 1/.style={blanker,halign=left} applies a distinct style to each column 1 box, rather than having to apply a different style to each box individually.

The annotations can be input using blank boxes with TikZ code inside them, using the nodes defined on each corner, through the at end tikz key to individual \tcbitems, raster row 1/.style={blanker} is used as with raster row column 1/.style= above to set the entire row of arrows to be blank boxes. Finally, as long as the dashed lines just divide a single box, this can be done with \tcbitem[sidebyside] and using \tcblower to divide the left and right content, the separator can then be customised.

\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document} 
\begin{tcbitemize}[raster width=15cm,raster columns=5,
raster equal height=rows,
enhanced,sharp corners,colback=white,colframe=black,
top=0mm,bottom=0mm,
halign=center,valign=center,halign upper=center,halign lower=center,
raster left skip=0mm,raster right skip=0mm,
raster column skip=0.5mm,
raster column 1/.style={blanker,halign=left},
raster row 1/.style={blanker},
raster row 4/.style={blanker}
]
\tcbitem 
\tcbitem [raster multicolumn=2,at end tikz={\draw [<->] (frame.south east) -- (frame.south west) node[midway,above] {$k$};}] 
\tcbitem [raster multicolumn=2,at end tikz={\draw [<->] (frame.south east) -- (frame.south west) node[midway,above] {$n-k$};}]
\tcbitem Plain ISD:
\tcbitem[raster multicolumn=2] $0$
\tcbitem[raster multicolumn=2] $t$
\tcbitem Lee-Brickell:
\tcbitem[raster multicolumn=2] $p$
\tcbitem[raster multicolumn=2] $t-p$
\tcbitem \rule{0mm}{5mm}
\tcbitem [raster multicolumn=2] 
\tcbitem [at end tikz={\draw [<->] (frame.south east) -- (frame.south west) node[midway,above] {$l$};}]
\tcbitem [at end tikz={\draw [<->] (frame.south east) -- (frame.south west) node[midway,above] {$n-k-l$};}]
\tcbitem Leon:
\tcbitem[raster multicolumn=2] $p$
\tcbitem $0$
\tcbitem $t-p$
\tcbitem Stern:
\tcbitem $p$
\tcbitem $p$
\tcbitem $0$
\tcbitem $t-2p$
\tcbitem Finiasz/Sendrier:
\tcbitem[raster multicolumn=3,sidebyside] $p$ \tcblower $p$
\tcbitem $t-2p$
\tcbitem Bernstein (Ball):
\tcbitem[raster multicolumn=2,sidebyside] $p_1$ \tcblower $p_1$
\tcbitem[sidebyside] $p_2$ \tcblower $p_2$
\tcbitem $t-2p_1-2p_2$
\end{tcbitemize}
\end{document}

which produces

enter image description here

As mentioned earlier, to set columns to different widths, raster force size=false seems to be required but I'm not sure how to successfully adjust widths with add to width while simultaneously using raster multicolumn so the adjustments require a bit more manual effort.

\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document} 
\begin{tcbitemize}[raster width=15cm,raster columns=5,
raster equal height=rows,
raster force size=false,
enhanced,sharp corners,colback=white,colframe=black,
top=0mm,bottom=0mm,
left=0mm,right=0mm,middle=0mm,sidebyside gap=0mm,
halign=center,valign=center,halign upper=center,halign lower=center,
raster left skip=0mm,raster right skip=0mm,
raster column skip=0.5mm,
raster column 1/.style={blanker,halign=left},
raster row 1/.style={blanker},
raster row 4/.style={blanker}
]
\tcbitem 
\tcbitem [add to width=2cm,at end tikz={\draw [<->] (frame.south east) -- (frame.south west) node[midway,above] {$k$};}] 
\tcbitem [add to width=4cm,at end tikz={\draw [<->] (frame.south east) -- (frame.south west) node[midway,above] {$n-k$};}]
\tcbitem[blanker,add to width=-3cm]
\tcbitem[blanker,add to width=-3cm]
\tcbitem Plain ISD:
\tcbitem[add to width=2cm] $0$
\tcbitem[add to width=4cm] $t$
\tcbitem[blanker,add to width=-3cm]
\tcbitem[blanker,add to width=-3cm]
\tcbitem Lee-Brickell:
\tcbitem[add to width=2cm] $p$
\tcbitem[add to width=4cm] $t-p$
\tcbitem[blanker,add to width=-3cm]
\tcbitem[blanker,add to width=-3cm]
\tcbitem \rule{0mm}{5mm}
\tcbitem[add to width=2cm] 
\tcbitem[add to width=-1cm,at end tikz={\draw [<->] (frame.south east) -- (frame.south west) node[midway,above] {$l$};}]
\tcbitem[add to width=2cm,at end tikz={\draw [<->] (frame.south east) -- (frame.south west) node[midway,above] {$n-k-l$};}]
\tcbitem[blanker,add to width=-3cm]
\tcbitem Leon:
\tcbitem[add to width=2cm] $p$
\tcbitem[add to width=-1cm] $0$
\tcbitem[add to width=2cm] $t-p$
\tcbitem[blanker,add to width=-3cm]
\tcbitem Stern:
\tcbitem[add to width=-0.5cm] $p$
\tcbitem[add to width=-0.5cm] $p$
\tcbitem[add to width=-1cm] $0$
\tcbitem[add to width=2cm] $t-2p$
\tcbitem Finiasz/Sendrier:
\tcbitem[add to width=4cm,sidebyside] $p$ \tcblower $p$
\tcbitem[add to width=2cm] $t-2p$
\tcbitem[blanker,add to width=-3cm]
\tcbitem[blanker,add to width=-3cm]
\tcbitem Bernstein (Ball):
\tcbitem[add to width=2cm,sidebyside] $p_1$ \tcblower $p_1$
\tcbitem[add to width=-1cm,sidebyside] $p_2$ \tcblower $p_2$
\tcbitem[add to width=2cm] $t-2p_1-2p_2$
\end{tcbitemize}
\end{document}

which produces

enter image description here

  • (+1) This one should be the accepted answer. Very neat! – Cragfelt Jan 7 '18 at 3:35

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.