1

Does any know how to put an arrow on top of a table in latex? Got the feeling I need tikzmark. But wasn't able to get the arrow at the right position.

enter image description here

\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
    \hline 
    \tikzmark{b}4 & 2 & 1 & 3 & 6 & 5 & 12 & 8\tikzmark{a} & 7 & 10 & 11 & 12 & 14 & 13 & 15 \\
    \hline
\end{tabular}
\begin{tikzpicture}[overlay, remember picture]
    \draw [<-] (a) [bend left] to (b);
\end{tikzpicture}
\end{table}
2
  • Welcome to TeX.SE. Please, in future provide complete small document which start with \documentclass{...}, continued by essential used packages, \begin{document} and ending with \end{document}. Also use figure environment option [H] is measure of last resort if other options doesn't work as you expected. In your case use of [htb] is just fine.
    – Zarko
    Commented Sep 11, 2016 at 9:50
  • See also proportional boxes in Tikz (array diagram)
    – Alenanno
    Commented Sep 11, 2016 at 10:16

2 Answers 2

2

Like this:

enter image description here

in your MWE you are quit close to what you looking for. Suppose, that in your preamble is \usetikzlibrary{tikzmark} than correct syntax for arrows coordinate is for example (pic cs:b). Complete MWE:

\documentclass[border=11mm,preview]{standalone}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}
\begin{table}[htb]
\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
    \hline
4\tikzmark{b} & 2 & 1 & 3 & 6 & 5 & 12 & \tikzmark{a}8 & 7 & 10 & 11 & 12 & 14 & 13 & 15 \\
    \hline
\end{tabular}
\begin{tikzpicture}[ remember picture, overlay]
    \draw [<-,red] ([yshift=3ex]pic cs:b) [bend left] to ([yshift=3ex]pic cs:a);
\end{tikzpicture}
\end{table}
\end{document}

Edit: if you change position of tikzmarks to after and before cell content, the arrow will be tetter positioned. This change is now considered in MWE.

1

TikZ is not the only easy solutions: you can also do it with pstricks:

\documentclass[svgnames]{article}
\usepackage{array}%
 \usepackage{pst-node, auto-pst-pdf}

\begin{document}

\begin{table}[!htb]
  \centering\setlength\extrarowheight{2pt}
  \begin{postscript}
    \begin{tabular}{|*{15}{c|}}
      \hline
      \pnode[0.5ex, 2.5ex]{b} 4 & 2 & 1 & 3 & 6 & 5 & 12 & \pnode[0.5ex, 2.5ex]{a} 8 & 7 & 10 & 11 & 12 & 14 & 13 & 15 \\
      \hline
    \end{tabular}
    \psset{arrows=->, linecolor=IndianRed}
    \ncarc[arcangle=-30]{a}{b}
    \ncangle[angle=-90, nodesep=2.8ex]{a}{b}
  \end{postscript}
\end{table}

\end{document} 

enter image description here

You must log in to answer this question.

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