Highlight a table row with a rectangular overlay
You could put the \input
in a node
and draw a rectangle relative to the corners of the node.
\begin{filecontents*}{table.tex}
\begin{tabular}{l*{3}{c}}
& A & B & C \\
\hline
1 & blah & blah & blah \\
2 & blah & blah & blah \\
3 & blah & blah & blah \\
\hline
\end{tabular}
\end{filecontents*}
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}
\node (table) {\input{table.tex}};
\draw [red,ultra thick,rounded corners]
($(table.south west) !.3! (table.north west)$)
rectangle
($(table.south east) !.5! (table.north east)$);
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
Some explanation to the above code
There are several standard anchors on a node
by default, denoted by compass directions, accessed with the syntax <node name>.<anchor>
. For example will MyNode.north west
be the top left corner of MyNode
.
To get a coordinate between two existing coordinates you can use the TikZ library calc
. This is described in section 13.5 Coordinate Calculations of the manual. It provides the syntax
($(<nodename or coordinate>) ! <factor> ! (<nodename or coordinate>)$)
Dollar signs indicate that a coordinate calculation should be done. The <factor>
is a number saying how far, on the line between the two specified nodes, relative to the distance between the nodes, the point should be. For example,
($(0,0) !.3! (1,0)$)
is 30% of the way between (0,0)
and (1,0)
, meaning (0.3,0)
.
In other words,
\draw [red,ultra thick,rounded corners]
($(table.south west) !.3! (table.north west)$)
rectangle
($(table.south east) !.5! (table.north east)$);
draws a rectangle
from the point that is 30% of the distance from the lower left corner to the upper left corner, to the point that is halfway between the lower right and upper right corners.
Here's a sans-TikZ way of obtaining the rectangle via a coloured \fbox
:
\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\newsavebox{\mytable}
\begin{document}
\begin{center}
\begin{lrbox}{\mytable}
\input{table.tex}
\end{lrbox}
%\setlength{\fboxrule}{2pt}% Modify rule width if necessary
\ooalign{%
\hss\usebox{\mytable}\hss \cr
{\color{red}%
\fbox{\phantom{\rule[-5pt]{\dimexpr\wd\mytable+10pt}{\dimexpr\baselineskip+5pt}}}%
}
}
\end{center}
\end{document}
The table \input
is stored in a box \mytable
in order to obtain the width. The box is subsequently positioned with a 5pt
overlap on either side of the table by setting a blank box of appropriate dimensions inside the coloured \fbox
.
Within \ooalign
, the table is centrred (since it's less wide than the 10pt
-wider \fbox
) using \hss
...\hss
. This is overprint with the coloured \fbox
. Here is a quick course on \ooalign
.
You could also reverse the sequence to use a shaded highlighting:
\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\newsavebox{\mytable}
\begin{document}
\begin{center}
\begin{lrbox}{\mytable}
\input{table.tex}
\end{lrbox}%
\setlength{\fboxrule}{2pt}% Modify rule width if necessary
\ooalign{%
{\fcolorbox{red!50}{red!30}{%
\phantom{\rule[-5pt]{\dimexpr\wd\mytable+10pt}{\dimexpr\baselineskip+5pt}}%
}} \cr
\hss\usebox{\mytable}\hss
}
\end{center}
\end{document}
If you don't want to input the table into tikz
, use this simple solution:
\begin{tikzpicture}[overlay]
\draw[red,ultra thick,rounded corners] (5.5,5.3) rectangle (6.4,9.2);
\end{tikzpicture}
Add this after the table if using overlays (e.g. \visible<>{}
). Change the draw options and the coordinates manually. After a few iterations you will get it right.