# How to draw such arrows in the table?

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}
14\tikzmark{a}  &   78  \\
71\tikzmark{b}  &   \tikzmark{c}93  \\
\end{tabular}
\begin{tikzpicture}[overlay, remember picture, yshift=.25\baselineskip, shorten >=.5pt, shorten <=.5pt]
\draw [->] ({pic cs:a}) [bend left] to ({pic cs:b});
\draw [->] ([yshift=.75pt]{pic cs:a}) -- ({pic cs:c});
\end{tikzpicture}
\end{document}


• I just ran this exact code, but it appears the tikzpicture yshift is not applied (the one for the second arrow is): output -- has something changed since this answer was posted? – meide Sep 19 '17 at 4:51

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=-.5\pgflinewidth]mat-\x-1.south west) --
([xshift=-.5\pgflinewidth]mat-\x-6.south east);
}
\foreach \x in {1,...,5}
{
\draw
([yshift=.5\pgflinewidth]mat-1-\x.north east) --
([yshift=.5\pgflinewidth]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