Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. For example, where do you use \vector or what package defines this command? Also, does this \vector stretch in a straight line from one cell to the other? –  Werner Mar 7 '12 at 18:30
    
Added MWE (which is misleading because it doesn't work) and yes it does stretch in a straight line from one cell to the other. Vector is a part of LaTeX and is not a part of any package that I know of. –  Fred Mar 7 '12 at 18:48
add comment

1 Answer

up vote 6 down vote accepted

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}
share|improve this answer
    
I haven't heard of tikzmark, but that is exactly what I want. Thanks! –  Fred Mar 7 '12 at 19:12
    
@Fred you're welcome! Note that tikzmark is just the name of the newcommand- it's the tikz package that does the work. –  cmhughes Mar 7 '12 at 19:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.