[Tex/LaTex] How to add a \vector to a table

diagramstablesvector

I am trying to make a table that shows how an element moves from location in the table to another. I would like to add a vector that starts at the first element and goes to the second element.

How do I do this?

I've tried putting the table in a picture but I get the error: Not in outer par mode.

\begin{figure}
\setlength{\unitlength}{1mm}
\begin{picture}(500,400)
\put(20,-10){\vector(1,-1){5}}
\begin{table}
\begin{tabular}[t]{ll}
\textbf{Something here} &  \\ \hline
A & F \\ 
B & A \\ 
C & G \\ 
D & H \\ 
E & I%
\end{tabular}
\end{table}
\end{picture}
\end{figure}

I want a vector pointing from A in left column to A in right column.

And I've tried putting the picture in a cell but the \vector commands don't show up in the PDF.

I have also searched Google but can't find how to do it.

Can anyone help?

Best Answer

You can use Andrew Stacey's tried and tested tikzmark idea, first posted here

Adding a large brace next to a body of text

and repeated in many examples since.

The idea is to set a node at each of the places in your table, and then connect the two nodes afterwards (using overlay and remember picture). You can tweak the placement of the connections using the calc tikz library.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1){};}

\begin{document}
\begin{table}
    \begin{tabular}[t]{ll}
    \textbf{Something here} &  \\ \hline
    A\tikzmark{firstmarker} & F \\ 
    B & A\tikzmark{secondmarker} \\ 
    C & G \\ 
    D & H \\ 
    E & I%
    \end{tabular}
\end{table}

\tikz[overlay,remember picture]\draw[red,->] ($(firstmarker)+(.2em,0.5em)$)--($(secondmarker)+(-.6em,0.5em)$);
\end{document}
Related Question