[Tex/LaTex] Highlighting table cells

highlightingtables

I have a large (13×13) table in which I need to highlight a subset of cells. I know that I can set a background color to those cells using colortbl or xcolor. But I need to highlight the table without using color (it is a scientific paper, and the table should communicate its purpose without assuming the reader will have access to a color printer). Is there a way to do so? For example a circle around the cell?

Best Answer

Generally I agree with lockstep that circling might not be the best way to highlight text. In addition to his suggestions, you could also try using a light gray background.

Having said that, here is a way to circle text using TikZ:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{fit,shapes.geometric}

\newcounter{nodemarkers}
\newcommand\circletext[1]{%
    \tikz[overlay,remember picture] 
        \node (marker-\arabic{nodemarkers}-a) at (0,1.5ex) {};%
    #1%
    \tikz[overlay,remember picture]
        \node (marker-\arabic{nodemarkers}-b) at (0,0){};%
    \tikz[overlay,remember picture,inner sep=2pt]
        \node[draw,ellipse,fit=(marker-\arabic{nodemarkers}-a.center) (marker-\arabic{nodemarkers}-b.center)] {};%
    \stepcounter{nodemarkers}%
}

\begin{document}

\begin{tabular}{*6{c}}\hline
    Col 1 & Col 2 & Col 3 & Col 4 & Col 5 & Col 6 \\\hline
    bla   & bla   & \circletext{bla}   & bla   & bla   & bla \\
    bla   & bla   & bla   & bla   & bla   & bla \\ 
    ble   & ble   & ble   & bla   & \circletext{bla}   & bla \\ 
    bla   & bla   & bla   & bla   & bla   & bla \\ \hline
\end{tabular}

\end{document}

exampl

The \circletext command defines a node to the left and right of the text and then fits an ellipse around them. More fanciful graphics are of course possible, this is a rather basic example (since I do not know what your table looks like). Two LaTeX runs are necessary to have everything show up in the right place.


Edit: Here is an example of how to mark arbitrary blocks. Ellipses don't look good with large blocks, so it is using rounded rectangles instead:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{fit,shapes.misc}

\newcommand\marktopleft[1]{%
    \tikz[overlay,remember picture] 
        \node (marker-#1-a) at (0,1.5ex) {};%
}
\newcommand\markbottomright[1]{%
    \tikz[overlay,remember picture] 
        \node (marker-#1-b) at (0,0) {};%
    \tikz[overlay,remember picture,thick,dashed,inner sep=3pt]
        \node[draw,rounded rectangle,fit=(marker-#1-a.center) (marker-#1-b.center)] {};%
}

\begin{document}

\begin{tabular}{*6{c}}\hline
    Col 1 & Col 2 & Col 3 & Col 4 & Col 5 & Col 6 \\\hline
    bla   & bla   & \marktopleft{c1}bla   & bla   & bla   & bla \\
    bla   & bla   & bla   & bla   & bla   & bla \\ 
    ble   & ble   & ble   & bla   & bla\markbottomright{c1}   & bla \\ 
    bla   & bla   & bla   & bla   & bla   & bla \\ 
    bla   & \marktopleft{c2}bla   & bla   & bla   & bla\markbottomright{c2}   & bla \\ \hline
\end{tabular}

\end{document}

example