TeX - LaTeX Asked by user79244 on March 20, 2021
How to draw such arrows in the table?
Next time, please provide a small example document people can use as the basis for an answer. In this case, for example, since your question is about the arrows, you should provide the code for the table so that people can concentrate on answering the question rather than having to construct a suitable table first.
One way is to use tikzmark
to mark coordinates within the table which you can then use to overlay a tikzpicture
containing the arrows.
For example, the following code illustrates the two kinds of arrows you need: curved arrows from one row to another within a column and straight arrows between cells in consecutive columns:
documentclass{article}
usepackage{tikz}
usetikzlibrary{tikzmark}
begin{document}
begin{tabular}{cc}
14tikzmark{a} & 78
71tikzmark{b} & tikzmark{c}93
end{tabular}
begin{tikzpicture}[overlay, remember picture, shorten >=.5pt, shorten <=.5pt, transform canvas={yshift=.25baselineskip}]
draw [->] ({pic cs:a}) [bend left] to ({pic cs:b});
draw [->] ([yshift=.75pt]{pic cs:a}) -- ({pic cs:c});
end{tikzpicture}
end{document}
Correct answer by absent on March 20, 2021
If you want to use a matrix instead of tabular, you can get inspiration from the following code:
% Code by Anonymous User from https://www.latex4technics.com/?note=1w9f
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
tikzset{
table/.style={
matrix of nodes,
row sep=-pgflinewidth,
column sep=-pgflinewidth,
nodes={rectangle,text width=3em,align=center},
text depth=1.25ex,
text height=2.5ex,
nodes in empty cells
},
row 1/.style={nodes={fill=green!10,text depth=0.4ex,text height=2ex}},
row 6/.style={nodes={text depth=0.4ex,text height=2ex}},
column 1/.style={nodes={fill=green!10}},
}
begin{document}
begin{tikzpicture}
% the matrix entries
matrix (mat) [table]
{
& $D_1$ & $D_2$ & $D_3$ & $D_4$ & foo
$O_1$ & 50 & 0 & & & 50
$O_2$ & & 60 & & & 60
$O_3$ & & 10 & 30 & 10 & 50
$O_4$ & & & & 50 & 50
bar & 50 & 70 & 30 & 60 & 210
};
% the matrix rules
foreach x in {1,...,5}
{
draw
([xshift=-.5pgflinewidth]mat-x-1.south west) --
([xshift=-.5pgflinewidth]mat-x-6.south east);
}
foreach x in {1,...,5}
{
draw
([yshift=.5pgflinewidth]mat-1-x.north east) --
([yshift=.5pgflinewidth]mat-6-x.south east);
}
% the arrows
begin{scope}[shorten >=7pt,shorten <= 7pt]
draw[->] (mat-2-2.center) -- (mat-2-3.center);
draw[->] (mat-2-3.center) -- (mat-3-3.center);
draw[->] (mat-3-3.center) -- (mat-4-3.center);
draw[->] (mat-4-3.center) -- (mat-4-4.center);
draw[->] (mat-4-4.center) -- (mat-4-5.center);
draw[->] (mat-4-5.center) -- (mat-5-5.center);
draw[->] (mat-5-5.center) -- (mat-6-6.center);
end{scope}
end{tikzpicture}
end{document}
You can experiment with the code here: https://www.latex4technics.com/?note=1w9f
Answered by Franck Dernoncourt on March 20, 2021
You can do that with {NiceArray}
of nicematrix
. This environment is similar to the classical environment {array}
(of array
) but constructs PGF/Tikz nodes under the cells. Then, it's possible to use these nodes with Tikz.
documentclass{article}
usepackage{nicematrix,tikz}
begin{document}
renewcommand{arraystretch}{1.5}
$begin{NiceArray}{*{9}{c}}
0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8
& 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17
& 19 & & 21 & 22 & 23 & 24 & 25 & 26
& 28 & & 30rlap{${}=s$} & & 32 & 33 & 34 & 35
& 37 & & 39 & & 41 & & 43 & 44
& 46 & & 48 & & 50 & & 52 &
& 55 & & 57 & & 59 & & 61 &
& & & 66 & & 68 & & 70 &
& & & & & 77 & & 79rlap{${}=t=30+3a+2b$}
& & & & & & & 88 &
CodeAfter
begin{tikzpicture}
draw (1-1) circle (2mm)
(2-3) circle (2mm)
(3-5) circle (2mm)
(4-7) circle (2mm)
(5-9) circle (2mm)
(7-2) circle (2mm)
(8-4) circle (2mm)
(9-6) circle (2mm)
(10-8) circle (2mm) ;
begin{scope} [->]
draw (4-4.east) to [bend left=45] (5-4.east) ;
draw (5-4.east) to [bend left=45] (6-4.east) ;
draw (6-4.east) to [bend left=45] (7-4.east) ;
draw (7-4) -- (8-6) ;
draw (8-6) -- (9-8) ;
end{scope}
end{tikzpicture}
end{NiceArray}$
end{document}
You need several compilations (because nicematrix
uses PGF/Tikz nodes).
Answered by F. Pantigny on March 20, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP