3

Here's the code I have to draw an arrow that points to a particular column of a table, I am somewhat satisfied with the output as is, but less satisfied with how I made it: the xshift and yshift number are chosen purely by blind trial and error, and I have so many similar tables to draw! What would be a more efficient and elegant way for positioning this arrow?

I probably could draw the table with tikz entirely, but that's a different story: the tables are created already, I then decided to add arrows to highlight some rows.

The code:

\documentclass{article}
\usepackage{tikz}
\usepackage{colortbl}
\usetikzlibrary{matrix}
\newcommand{\tikzmark}[1]{\tikz[overlay, remember picture] \coordinate (#1);}
\definecolor{Gray}{gray}{0.9}
\newcolumntype{g}{>{\columncolor{Gray}}c}
\begin{document}
  \begin{table}[h]
    \centering
\begin{tabular}{ccgcccc|c}
      & 1     & 3/2   & 1/2   & 1/2   & 0     & 0     & 5/2 \\
      & 0     & -5    & 0     & -2    & 1     & 0     & 1 \\ \rowcolor{Gray}
      & 0     & -1/2  & 1/2   & -3/2  & 0     & 1     & 1/2 \\ \hline
$z$   & 0     & \tikzmark{here} -7/2  & 1/2   & -5/2  & 0     & 0     & -25/2 \\
\end{tabular}%
    \end{table}
\tikz[overlay,remember picture] {
  \draw[->,>=stealth] ([xshift=12pt,yshift=-25pt]here) -- ([xshift=12pt,yshift=-5pt]here);
}
\end{document}

The output:

enter image description here

eN_Joy
  • 227

2 Answers2

4

In this case, it's better to change tikzmark definition and use a regular node instead of coordinate. This way you can reference its center.

\documentclass{article}
\usepackage{tikz}
\usepackage{colortbl}
\usetikzlibrary{matrix}
\newcommand{\tikzmark}[2]{\tikz[overlay, remember picture] \node[inner sep=0pt, outer sep=0pt, anchor=base] (#1) {#2};}
\definecolor{Gray}{gray}{0.9}
\newcolumntype{g}{>{\columncolor{Gray}}c}
\begin{document}
  \begin{table}[h]
    \centering
\begin{tabular}{ccgcccc|c}
      & 1     & 3/2   & 1/2   & 1/2   & 0     & 0     & 5/2 \\
      & 0     & -5    & 0     & -2    & 1     & 0     & 1 \\ \rowcolor{Gray}
      & 0     & -1/2  & 1/2   & -3/2  & 0     & 1     & 1/2 \\ \hline
$z$   & 0     & \tikzmark{here}{-7/2}  & 1/2   & -5/2  & 0     & 0     & -25/2 \\
\end{tabular}%
    \end{table}
\tikz[overlay,remember picture] {
  \draw[<-,>=stealth] (here) -- ++(-90:1cm);
}
\end{document}

enter image description here

Ignasi
  • 136,588
3

You can use the simple \vector macro with the default unit pt. It can be changed by setting \unitlength=...:

\documentclass{article}
\usepackage[table]{xcolor}
\definecolor{Gray}{gray}{0.9}
\newcolumntype{g}{>{\columncolor{Gray}}c}    
\begin{document}

\begin{center}
\begin{tabular}{ccgcccc|c}
      & 1     & 3/2   & 1/2   & 1/2   & 0     & 0     & 5/2 \\
      & 0     & -5    & 0     & -2    & 1     & 0     & 1 \\ \rowcolor{Gray}
      & 0     & -1/2  & 1/2   & -3/2  & 0     & 1     & 1/2 \\ \hline
$z$   & 0     & -7/2  & 1/2   & -5/2  & 0     & 0     & -25/2 \\
      &       &  \put(0,-10){\vector(0,1){20}}
\end{tabular}%
\end{center}

\end{document}

enter image description here

  • This really works as well as @Thruston's suggestion. I should have accepted this as an answer, but really I wanted is to play with tikz, sorry I didn't make this point clear. – eN_Joy Jun 02 '14 at 16:33