texblog

Replacing repetitive values in a table column by an arrow

Ideally, tables are quickly and easily readable. Removing repetitive content helps the reader to grasp the essential result quicker and makes tables more readable. A possible option to make a table more readable is to replace repetitive content across a column with an arrow.

 
Preparations

We will use TikZ to draw an arrow from the second to the last row of the column, replacing repetitive content. For that purpose, we require two macros, the first stores a location in a cell and the second links two locations with an arrow.

The first macro creates a node in a table cell. The first parameter is the name of the node, so that we can later connect it with an arrow. The second parameter is the value of the cell. We use \phantom to occupy the right amount of space without showing the value to make sure the arrow will be horizontally centered.

\usepackage{tikz}

\newcommand\tikzmark[2]{%
\tikz[remember picture,baseline] \node[above, outer sep=0pt, inner sep=0pt] (#1){\phantom{#2}};%
}

The second macro links two nodes with an arrow. We call this macro outside the tabular environment.

\newcommand\link[2]{%
\begin{tikzpicture}[remember picture, overlay, >=stealth, shift={(0,0)}]
  \draw[->] (#1) to (#2);
\end{tikzpicture}%
}

 
Replacing repetitive content

Now, we use the two macros to replace repetitive content by an arrow. For that purpose, we add a \tikzmark to the first and last cell to be replaced. At the end of the table, we then \link the two cells by an arrow. The relevant lines are highlighted in the code below.

\begin{table}
\centering
\caption{Replaced repetitive values with arrow.}
\begin{tabular}{lrrrr}
\hline
Obs.&First&Second&Third&Forth\\
\hline
1&5.21&5.32&3.21&2.30\\
2&5.12&\tikzmark{a}{5.32}&3.43&\tikzmark{c}{2.30}\\
3&5.04&&3.14&\\
4&5.51&&3.41&\\
5&5.64&&3.11&\\
6&5.25&&3.25&\\
7&5.16&&3.71&\\
8&5.01&&3.86&\\
9&4.58&\tikzmark{b}{5.32}&3.12&\tikzmark{d}{2.30}\\
\hline
\end{tabular}
\link{a}{b}\link{c}{d}
\label{tab}
\end{table}

 
Complete code

\documentclass[11pt]{article}
\usepackage{subfig, tikz}

\newcommand\tikzmark[2]{%
\tikz[remember picture,baseline] \node[above, outer sep=0pt, inner sep=0pt] (#1){\phantom{#2}};%
}
\newcommand\link[2]{%
\begin{tikzpicture}[remember picture, overlay, >=stealth, shift={(0,0)}]
  \draw[->] (#1) to (#2);
\end{tikzpicture}%
}

\begin{document}

\begin{table}[ht]
\begin{center}\begin{scriptsize}
\caption{Tables with and without repetitive values.}
\label{tab:main}
\subfloat[Repetitive values]{
\begin{tabular}{lrrrr}
\hline
Obs.&First&Second&Third&Forth\\
\hline
1&5.21&5.32&3.21&2.30\\
2&5.12&5.32&3.43&2.30\\
3&5.04&5.32&3.14&2.30\\
4&5.51&5.32&3.41&2.30\\
5&5.64&5.32&3.11&2.30\\
6&5.25&5.32&3.25&2.30\\
7&5.16&5.32&3.71&2.30\\
8&5.01&5.32&3.86&2.30\\
9&4.58&5.32&3.12&2.30\\
\hline
\end{tabular}
\label{tab:sub1}
}\quad
\subfloat[Replaced repetitive values with arrow.]{
\begin{tabular}{lrrrr}
\hline
Obs.&First&Second&Third&Forth\\
\hline
1&5.21&5.32&3.21&2.30\\
2&5.12&\tikzmark{a}{5.32}&3.43&\tikzmark{c}{2.30}\\
3&5.04&&3.14&\\
4&5.51&&3.41&\\
5&5.64&&3.11&\\
6&5.25&&3.25&\\
7&5.16&&3.71&\\
8&5.01&&3.86&\\
9&4.58&\tikzmark{b}{5.32}&3.12&\tikzmark{d}{2.30}\\
\hline
\end{tabular}
\link{a}{b}\link{c}{d}
\label{tab:sub2}
}
\end{scriptsize}\end{center}
\end{table}
\end{document}

 
The idea of using macros based on TikZ was taken from here.

Exit mobile version