TransWikia.com

My question is about to generating cross table and mid table arrows as shown in fig. I have tried many options but not getting accurate result

TeX - LaTeX Asked by Aliasgar Rangwala on December 12, 2020

enter image description here

begin{table}[!htb]
        begin{minipage}{.5linewidth}
            caption{}
            centering
            begin{tabular}{|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|}
                hline
                D & 1 & 0 & 1 & D & 1 & 1 
                hline              
            end{tabular}vspace{0.8 cm}            
            begin{tabular}{|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|}
               hline
               D & 1 & 0 & 1 & D & 1 & 1 
               hline
            end{tabular}       
        end{minipage}vspace{-1.5cm}
    $Rightarrow$
        begin{minipage}{.5linewidth}
            centering
            caption{}
            begin{tabular}{|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|}
                hline
                D & 1 & 0 & 1 & D & 1 & 1 
                hline
            end{tabular}vspace{0.8 cm}
        begin{tabular}{|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|}
            hline
            D & 1 & 0 & 1 & D & 1 & 1 
            hline
        end{tabular}       
        end{minipage}    
    end{table}

3 Answers

You can draw the arrows with the help of tikzpicture environment with tikz node.

Here is the code..

documentclass[margin=1in]{standalone}

usepackage{tikz}
usetikzlibrary[arrows, decorations.pathmorphing, backgrounds, positioning, fit, petri, calc]

usetikzlibrary{shapes.arrows}


begin{document}
    begin{tikzpicture}[node distance=0pt,
        bluebox/.style={draw, fill=cyan!50, text width=0.5cm, inner sep=0.1cm, align=center},
        box/.style={draw,  text width=0.5cm, inner sep=0.1cm, align=center}]
        
        begin{scope}
            node[bluebox] (b7) {0};
            node[bluebox] (b6) [right=of b7] {1};
            node[bluebox] (b5) [right=of b6] {0};
            node[bluebox] (b4) [right=of b5] {1};
            node[bluebox] (b3) [right=of b4] {0};
            node[bluebox] (b2) [right=of b3] {1};
            node[bluebox] (b1) [right=of b2] {1};
            
            
            node[box, yshift=-1.25cm] (a7) {1};
            node[box] (a6) [right=of a7] {1};
            node[box] (a5) [right=of a6] {1};
            node[box] (a4) [right=of a5] {0};
            node[box] (a3) [right=of a4] {0};
            node[box] (a2) [right=of a3] {1};
            node[box] (a1) [right=of a2] {0};
            
            draw[->, very thick] ($(a6.south east) + (0,-0.25cm)$) node[yshift=2.5cm] {crossover point} node[yshift=-0.15cm] {Parent chromosomes} -- ($(b6.north east) + (0,0.25cm)$);
            
            
            
        end{scope}
        
        node[draw, single arrow,
        minimum height=30mm, minimum width=20mm,
        single arrow head extend=2mm,
        anchor=west, rounded corners=2pt, right of=b1, xshift=2.25cm, yshift=-0.75cm] (arrow)  {};
        
        
        node [above=of arrow, yshift=1.5cm]{One Point Crossover};
        


        
        begin{scope}[xshift=9cm]
            node[bluebox] (b7) {0};
            node[bluebox] (b6) [right=of b7] {1};
            node[box] (b5) [right=of b6] {1};
            node[box] (b4) [right=of b5] {0};
            node[box] (b3) [right=of b4] {0};
            node[box] (b2) [right=of b3] {1};
            node[box] (b1) [right=of b2] {0};
            
            
            node[box, yshift=-1.25cm] (a7) {1};
            node[box] (a6) [right=of a7] {1};
            node[bluebox] (a5) [right=of a6] {0};
            node[bluebox] (a4) [right=of a5] {1};
            node[bluebox] (a3) [right=of a4] {0};
            node[bluebox] (a2) [right=of a3] {1};
            node[bluebox] (a1) [right=of a2] {1};
            
            node [below of=a4, yshift=-0.75cm] {Offspring chromosomes};
            
        end{scope}     
        
    end{tikzpicture}
end{document}

THe output is shown as

Answered by Abuzar Ghafari on December 12, 2020

A pstricks solution: I inserted 2 rnodes, then connected them with a node connection. For the bigarrow, I loaded pst-arrow and used psBigArrow to connect an empty node (pnode) placed at the end of the first minipage and another placed at the beginning of the second minipage.

documentclass[11pt]{article}
 usepackage{geometry}
usepackage{array, caption}
usepackage[table, svgnames]{xcolor}
usepackage{pst-node, pst-arrow}
colorlet{mygrey}{Gainsboro!50!Lavender}

begin{document}

    begin{table}[!htb]
    sffamilysetlength{extrarowheight}{2pt}
    begin{minipage}{.35linewidth}
        centering
        begin{tabular}{|*{7}{wc{0.3cm}|}}
        multicolumn{7}{l}{hskip 1.5emrnode[bl]{C}{Crossover point}} [1.5ex]
            hline
   rowcolor{mygrey} D & 1 & 0 & 1 & D & 1 & 1 
            hline
    noalign{vspace{0.4cm}}
           hline
           D & 1 & 0 & 1 & D & 1 & 1 
           hline
    noalign{vskip 1.5ex}
        multicolumn{7}{l}{hskip1.5emrnode[tl]{P}{Parent chromosomes}}
        end{tabular}
    end{minipage}%
    pnode[0.5em,1.2ex]{A} hspace{2.2cm}pnode[-0.5em,1.2ex]{W}
    begin{minipage}{.35linewidth}
        centering
        begin{tabular}{|*{7}{p{0.3cm}|}}
        multicolumn{5}{c}{} [1.5ex]
            hline
            cellcolor{mygrey}D & cellcolor{mygrey}1 & 0 & 1 & D & 1 & 1 
            hline
        noalign{vspace{0.4cm}}
        hline
     rowcolor{mygrey}cellcolor{white} D &cellcolor{white} 1 & 0 & 1 & D & 1 & 1 
        hlinenoalign{vskip 1.5ex}
        multicolumn{7}{c}{hskip1.5emrnode{O}{offspring chromosomes}}
    end{tabular}
    end{minipage}
    ncline[arrows=->, arrowinset=0.12, nodesep=2pt, offset =-22pt]{P}{C}
    psBigArrow[doublesep=3mm](A)(W)
    end{table}

end{document} 

enter image description here

Answered by Bernard on December 12, 2020

One more solution with TikZ:

  • drawing in the loops
  • used libraries chains
  • conditional coloring of boxes
documentclass[tikz, margin=3mm]{standalone}
usetikzlibrary{arrows.meta, 
                calc, chains,
                fit, 
                positioning,
                shapes.arrows}


begin{document}
    begin{tikzpicture}[
node distance = 7mm and 0mm,
  start chain = going right,
    ARR/.style = {single arrow, single arrow head extend=2mm, draw,
                  minimum height=5.5em, minimum width=13mm},
    box/.style = {draw, fill=#1, minimum width=1.6em, outer sep=0pt},
    box/.default = cyan!50,
                        ]
foreach i [count=j] in {0,1, 0,1, 0,1, 1}
{
    node (n1j) [box,on chain] {i};
ifnumj<3
    node   [box,right=17em of n1j] {i};
else
    node   [box=white,right=17em of n1j] {i};
fi
}
foreach i [count=j] in {1,1, 1,0, 0,1, 0}
{
    node (n2j) [box=white, below=of n1j] {i};
ifnumj<3
    node   [box=white,right=17em of n2j] {i};
else
    node (n4j) [box,right=17em of n2j] {i};
fi
}
%
draw[-Straight Barb, very thick]   ([yshift=-3mm] n22.south east) 
    node (aux1) [align=center, below] {Parent chromosomes} -- 
                        ([yshift=+3mm] n12.north east)
    node (aux2) [align=center, above] {crossover point};
node[align=center, below] at  (aux1.north -| n44) {offsping chromosomes};
%
node [ARR,right=1em] at ($(n17.east)!0.5!(n27.east)$)  {};
%
node [draw, rounded corners, fit = (aux1) (aux2) (n47),
       label={[anchor=north]north: One Point Crossover}] {};
    end{tikzpicture}
end{document}

enter image description here

Answered by Zarko on December 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP