4

I am trying to position some arrows below a table and can't get them in the right place. The code below is how far I have got. The image shows roughly how I want the arrows to look, but positioned between the lines at the foot of the table, with the labels ("1-2") etc. centred below each arrow. The arrows should be positioned so that they start in the middle of one column and end in the middle of the next column.

\documentclass{article}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{tikzmark,arrows.meta,patterns,calc}
\newcommand\DrawArrow[4][]{
\begin{tikzpicture}[
remember picture,
overlay,
arr/.style={draw=gray,line width=2pt, {-latex}, #1}
]
\draw[arr]
([shift={(15pt,-1ex)}]pic cs:#2) 
to[out=-40,in=220] node[below=8pt] {#4} 
([shift={(6pt,-1ex)}]pic cs:#3); 
\end{tikzpicture}
}
\newcommand\DrawArrowB[4][]{
\begin{tikzpicture}[
remember picture,
overlay,
arr/.style={draw=gray,line width=2pt, {-latex}, #1}
]
%-.5ex cotrols gap between bottom of table and start of arrow head
%6pt etc. controls horizontal position
\draw[arr]
([shift={(6pt,-.8ex)}]pic cs:#2) 
 to[out=-40,in=220] node[below=8pt] {#4} 
([shift={(-8pt,-.8ex)}]pic cs:#3); 
 \end{tikzpicture}
}
\begin{document}
\begin{figure}[htbp]
\centering
\includegraphics[scale=0.8]{CLmethoddiagram.png}    
\caption{png version - low res}  
\end{figure} 
\begin{table}[htbp]
\centering
\caption{tikz version}
\begin{tabular}{@{}lllllll@{}}
\toprule
& \multicolumn{6}{c}{Development year} \\
\cmidrule(l){2-7}
{Year} & {1} & {2} & {3} & {4} & {5} & {6} \\
\midrule
2009  &            443  &        1,136  &        2,128  &        2,898  &        3,403  &        3,873  \\
2010  &            396  &        1,333  &        2,181  &        2,986  &        3,692  &  \\
2011  &            441  &        1,288  &        2,420  &        3,483  &       &  \\
2012  &            359  &        1,421  &        2,864  &       &       &  \\
2013  &            377  &        1,363  &       &       &       &  \\
2014  &  \tikzmark{start1B}344& \tikzmark{start2B}- &  \tikzmark{start3B}   -  &  \tikzmark{start4B}   -  &   \tikzmark{start5B}   -  &\tikzmark{start6B}  - \\
\midrule
&&&&&&\\
\DrawArrow{start1B}{start2B}{1-2}
\DrawArrowB{start2B}{start3B}{2-3}
\DrawArrowB{start3B}{start4B}{3-4}
\DrawArrowB{start4B}{start5B}{4-5}
\DrawArrowB{start5B}{start6B}{5-6}
&&&&&&\\
\bottomrule
\end{tabular}%
\end{table}%
\end{document}

This is what the code produces

The one at the top is a low res png version which is roughly how I would like the arrows to look

1 Answer 1

2

You can consolidate the shifts to position them uniformly below the table and from the (approximate) middle of the columns, then tune the in and out parameters:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{booktabs}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{tikzmark,arrows.meta,patterns,calc}


\newcommand\DrawArrow[4][]{
\begin{tikzpicture}[
remember picture,
overlay,
arr/.style={draw=gray,line width=2pt, {-latex}, #1},
xshift=1em,
yshift=-3ex,
]
\draw[arr]
([xshift=1ex]pic cs:#2)
 to[out=-80,in=-120,looseness=1.5] node[below=8pt] {#4}
([xshift=-1ex]pic cs:#3);
 \end{tikzpicture}
}
\begin{document}
\begin{figure}[htbp]
\centering
\includegraphics[scale=0.8]{CLmethoddiagram.png}
\caption{png version - low res}
\end{figure}
\begin{table}[htbp]
\centering
\caption{tikz version}
\begin{tabular}{@{}lllllll@{}}
\toprule
& \multicolumn{6}{c}{Development year} \\
\cmidrule(l){2-7}
{Year} & {1} & {2} & {3} & {4} & {5} & {6} \\
\midrule
2009  &            443  &        1,136  &        2,128  &        2,898  &        3,403  &        3,873  \\
2010  &            396  &        1,333  &        2,181  &        2,986  &        3,692  &  \\
2011  &            441  &        1,288  &        2,420  &        3,483  &       &  \\
2012  &            359  &        1,421  &        2,864  &       &       &  \\
2013  &            377  &        1,363  &       &       &       &  \\
2014  &  \tikzmark{start1B}344\phantom{,3}& \tikzmark{start2B}- &  \tikzmark{start3B}   -  &  \tikzmark{start4B}   -  &   \tikzmark{start5B}   -  &\tikzmark{start6B}  - \\
\midrule
&&&&&&\\
\DrawArrow{start1B}{start2B}{1-2}
\DrawArrow{start2B}{start3B}{2-3}
\DrawArrow{start3B}{start4B}{3-4}
\DrawArrow{start4B}{start5B}{4-5}
\DrawArrow{start5B}{start6B}{5-6}
&&&&&&\\
\bottomrule
\end{tabular}%
\end{table}%
\end{document}

To make all the arrows uniform, I added some padding to the first column with a \phantom

enter image description here

1
  • Brilliant Thanks for your very quick and helpful response. It worked! Nov 16, 2016 at 20:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .