Home > tables > Drawing divided table

# Drawing divided table

October 26Hits:1

Can anyone recommend any tutorial/library or just explain how can I draw this type of table, divided into few part with arrows? Like on

:

This solution uses the following packages:

• forest (also etoolbox)

forest is used to create the upper part of the tree, every node of this tree will use the algorithm behind the sort key. Every mirrored node will be placed at the orthogonal opposite of the last line. The edges of the lower part are rudimentary drawn with an edge path operator of TikZ (forest offers a few options for edges that are not used here).

• l3sort

The very first example of the l3sort manual is directly used here to sort the integers of a node.

• xstring

The xstring package provides a \StrSubstitute macro that first replaces all spaces to commas , for the l3sort macro. The sorted result is then again thrown into \StrSubstitute to re-replace the commas to spaces.

Furthermore, the calc library from TikZ is used to place the sorted nodes at the other side (this could have been easily done without calc) as well as the PGFmath function strrepeat.

A similar approach for a calc-less positioning can be found in another answer of mine (look for Stern Brocot at and Stern Brocot at*). This is also the answer where I first used the strrepeat function.

This function is only used once to automatically create the name of the first child of the last level of the tree (here: 39) so that it can be used later as \forestOnes.
The sort level key also sets up the \forestSortLevel macro so that it can be used inside the sort key.

### Possible improvements

• Getting the maximum level directly from forest and not from the user.
• Sorting with spaces without the need to replace the spaces (or maybe a LaTeX3 solution for the replacing).
• Automatic splitting of a list of numbers by forest so that one does only need to add the root node.
• Exploiting something like execute at end picture but for forest for the lower part of the tree. The sort key is actually executed before anything is drawn (and outside of TikZ) which is the reason that all \nodes (and their edges) are saved in \myNodes. The same is true for the \coordinate call which just as well should be setup by sort level.

## Code

\documentclass[tikz]{standalone}
\usepackage{forest,l3sort,xstring}
\usetikzlibrary{calc}
\makeatletter
\pgfmathdeclarefunction{strrepeat}{2}{%
\begingroup\pgfmathint{#2}\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */\pgfmathresult
\let\pgfmathresult\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */\ifnum\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */>0\relax
\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult#1}%
\advance\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */\relax
\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */\pgfmathresult\endgroup}
\makeatother
\def\myNodes{}
\ExplSyntaxOn
\newcommand*\sortList[1]{%
\clist_sort:Nn#1{\int_compare:nNnTF{##1}>{##2}\sort_reversed:\sort_ordered:}}
\ExplSyntaxOff
\forestset{
sort/.code={%
\pgfmathparse{level()>\forestSortLevel}%
\ifnum\pgfmathresult=0
\StrSubstitute{\forestov{content}}{ }{,}[\myList]%
\sortList\myList
\StrSubstitute{\myList}{,}{ }[\myList]%
\pgfmathparse{strrepeat("1",level())}%
\xappto\myNodes{\noexpand\node at ($(\forestov{name}|-m)!-1!(\forestov{name})$)
(m\forestov{name}) {\myList}}%
\pgfmathparse{level()==\forestSortLevel}%
\ifnum\pgfmathresult=1
\forestOget{\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */}}{name}\forestFirst
\forestOget{\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */}}{name}\forestLast
\xappto\myNodes{{[<-]edge (\forestOv{\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */}}{name})
\ifx\forestFirst\forestLast\else edge (\forestOv{\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */}}{name})\fi}}%
\fi
\ifnum\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */}=0\else
\xappto\myNodes{edge (m\forestOv{\[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */}}{name})}%
\fi
\gappto\myNodes{;}%
\fi}}
\forestset{sort level/.code=%
\pgfmathparse{#1}\let\forestSortLevel\pgfmathresult
\pgfmathparse{strrepeat("1",\forestSortLevel+1)}\let\forestOnes\pgfmathresult}
\begin{document}
\begin{forest}
/tikz/arrows=->, /tikz/>=latex, %/tikz/nodes={draw},
for tree={delay={sort}}, sort level=2
[38 27 43 3 9 82 10
[38 27 43 3
[38 27 [39][27]]
[43 3 [43][3]]
]
[9 82 10
[9 82 [9] [82]]
[10 [10]]
]
]
%
\coordinate (m) at (!|-!\forestOnes);
\myNodes
\end{forest}
\end{document}



Tags:tables

## Related Articles

• ### Drawing divided tableOctober 26

Can anyone recommend any tutorial/library or just explain how can I draw this type of table, divided into few part with arrows? Like on : --------------Solutions------------- This solution uses the following packages: forest (also etoolbox) forest is

• ### How can I draw a table where the upper left corner is missing? (Pic)November 12

Is it possible to draw a table like the one in the attached picture? I've read documentation on the tabular environment but nothing really describes this well. The shading would be nice but the crucial part is the layout (5 columns, 2x2 merged cells

• ### How to draw inside table cell in OneNote?November 18

Drawings in one note are overlaid on text. So, they do not maintain relations with text. For example, one can't draw inside table cell: drawing will shift away if table resized or something. Is it possible to overcome this feature? --------------Solu

• ### Drawing database tables in tikzSeptember 24

I am bit confused about how can i draw a table like this using tikz. Any ideas please? --------------Solutions------------- This answer uses my positioning-plus library, my node-families library (note that the key Text Width is not perfect and needs

• ### Drawing a table in Python3November 22

I have created a module to draw text tables. The relevant parts are below and here's the full code for txtable). class Row(Txtable): [...] def format(self, col_widths): """Return the row as formatted string. """ columns = []

• ### Draw the table like 6³ = 3³ + 4³ + 5³ to 100³ = 35³ + 70³ + 85³February 7

I want to draw the table like this: 6³ = 3³ + 4³ + 5³ 9³ = 1³ + 6³ + 8³ 12³ = 6³ + 8³ + 10³ 18³ = 2³ + 12³ + 16³ 18³ = 9³ + 12³ + 15³ 19³ = 3³ + 10³ + 18³ 20³ = 7³ + 14³ + 17³ ..... 100³ = 35³ + 70³ + 85³ I've tried this: \$start = microtime(true); fu

• ### Drawing multicolumn table in latexMarch 15

I have a problem for drawing a multicolumn table in ieeetran latex. This is what I want to draw: However, I couldn't manage it. I am having problem to add OBR and AR rows. I tried some codes, none of them worked. My last trial is: \begin{table}[!h] \

• ### How to properly draw a table using tabularMay 16

How to draw a table using tabular \documentclass{beamer} \begin{document} \begin{frame}{Cs} \centering \begin{table} \centering \caption{C} \begin{tabular}{|l|l|} \hline u & i\\ \hline ~58Ko & ~1Mo.\\ \hline DqsdqsdqsdqsdDqsdqsdqsdqsdDqsdqsdqsdqsd

• ### How to draw a table with annotation? (screenshot inside)April 2

I need to draw a table like this into my paper. I know to draw a table but I'm not sure how to annotate it (rows and columns) with indexes. Do you have some example how to do it in LaTex? --------------Solutions------------- A possible solution with

• ### how to draw a table for comparisionDecember 20

i want to draw a table similar to this, but i have no idea about it, could someone can help me with it. I appreciate it!! --------------Solutions------------- Some pointers: Load the booktabs package and use the macros \toprule, \midrule, \bottomrule

• ### Draw a table after some text in a pdf document with reportlabJanuary 21

I have a pdf document written with a canvas object, and I want to draw a table at the end. My code is like this: # Create the HttpResponse object with the appropriate PDF headers. response = HttpResponse(content_type='application/pdf') response['Cont

• ### Draw Dynamic table in pdf SwiftFebruary 8

I am using this Source code SimplePDF for Drawing in PDF. This Works fine for Drawing Text and Images. Now, I am trying to Draw Dynamic tables. Means, user can enter number Of rows, number Of columns and data of Table. Background Color for particular

• ### Drawing a table using multirow and multicolumnFebruary 11

I would really like to draw a table like on the photo. Everything I have tried does not work. Maybe I do something wrong right at the beginning. I only got the table you can see in the code below. There is still a lot to do for getting a table like o

• ### Diagonally divided table cell December 17

Possible Duplicate: Diagonal lines in table cell I'd like to include a table of numbers in my document. Those numbers are defined by two parameters n and k, and I'd like to achieve a presentation similar to what Comtet did in "Advanced Combinatorics&

• ### divide table cells by a certain amountJuly 31

I made a mistake in the values that i put in the table. I need to divide all the values by 105. Is there a method where i can do it without having to replace this with a completely new table ? % Table generated by Excel2LaTeX from sheet 'Sheet1' \beg

• ### Draw a table with bars going across the rowsMay 2

Is there a way to do this? My hunch is that I can simulate this by creating a table that has 20 columns, no separators, use the | as a manual column separator, and then draw a rectangle that can span rows (not sure how to do that exactly, but its pro

• ### Colored diagonal divided table cellDecember 6

How can I fill a table cell with different colors? I have tried the diagbox package but it doesn't work as you can see. I am not so much interested in the diagonal line. I only want to separate the cell in two triangles, put text in both triangles an

• ### I want to draw a table like this, but my code does not work January 6

I am trying to implement a table given in the snapshot. Firstly, I just want to draw a multirow, as it is shown in the image. \documentclass[12pt, a4paper,twoside]{memoir} \begin{document} \definecolor{c1}{rgb}{0.30980, 0.50588, 0.73725} \definecolor

• ### How do I add columns and rows in a draw.io table?January 20

How do I insert new rows and columns in the Table in perspective to draw.io Mockup Text? --------------Solutions------------- Assuming you're referring to the Table object in Mockup Text, when you go into edit mode (double click) select one of the ro

• ### Are there keyboard shortcuts for adding columns and rows in a draw.io table?November 3

I make a lot of database schemas with draw.io but it's annoying to create new rows in the table having to go to the drop down and select the add row icon. Are there any keyboard shortcuts in draw.io to make that task easier? It would be nice if it wa