You need to set the value of \fboxsep
to zero to remove the extra margin:
{\setlength{\fboxsep}{0pt}\colorbox{<color>}{<text>}}
You don't need the outer braces if it is the whole cell, however then I would use the macros of the colortbl
or colortab
packages. The new tabu
package also provides a lot of new features for tables, including a lot of different color features, but it might be an effort to change to this package.
You can also use the adjustbox
package for this:
\adjustbox{cframe=<color>}{<text>}
which draws a tight frame as well.
It has also an extended syntax which allows to set the rule thickness, inner separation and outer margin:
\adjustbox{cframe=<color> <thickness> <inner sep> <outer margin>}{<text>}
The margin can be negative and if it is -(thickness+inner sep) the original size is kept, e.g.:
\adjustbox{cframe=blue {\fboxrule} {\fboxsep} {-\fboxrule-\fboxsep}}{<text>}
(The { }
around the macros are there to preserve the space behind them.)
I have prevented the cell from becoming wider due to the border, but allowed it to grow vertically. If that isn't desired a bit more negative spacing is needed.
rather than use colortbl
it is easier to grab the cell contents in a box (since you are doing that anyway for p
columns) and using \fcolorbox
.
\documentclass{article}
\usepackage{array,colortbl,xcolor}
\begin{document}
\makeatletter
\def\highlight#1{%
\fboxrule2pt %
\hsize=\dimexpr\hsize-2\fboxrule-2\fboxsep\relax
#1%
\@endpbox\unskip\setbox0\lastbox\bgroup
\fboxrule2pt %
\fcolorbox{red}{lightgray}{\box0}\hfill}
\begin{tabular}{p{1.4cm}p{2.55cm}p{2.55cm}p{2.55cm}p{2.55cm}}
\hline
\multicolumn{1}{c}{} & \multicolumn{2}{c}{\textbf{Football}} & \multicolumn{2}{c}{\textbf{Basketball}} \\\hline
\multicolumn{1}{c}{} & \multicolumn{1}{c}{\textbf{1. League}} & \multicolumn{1}{c}{\textbf{2. League}} & \multicolumn{1}{c}{\textbf{1. League}} & \multicolumn{1}{c}{\textbf{2. League}} \\ \hline
\textbf{Average} & 10000000000 & \cellcolor{lightgray}20000000000 & 30000000000 & 40000000000\\ \hline
\textbf{Total} & 50000000000 & 60000000000 &
\highlight{70000000000}& \cellcolor{lightgray}80000000000\\ \hline
\end{tabular}
\end{document}
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:
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: