# How to make box in a row of a table [duplicate]

I want to make a box in second row. That is on 1 & 3 & 24 & 42 & 43. Also on part of forth row 5 & 16 & 26 & 34.

 \begin{tabular}{| c | c  c  c  c | }
\hline
Location & \multicolumn{4}{c|}{Rounds}\\
\hline
0 &  2 &  23 &  41 &  42\\
1 &  3 &  24 &  42 &  43\\
2 &  4 &  25 &  43 &  44\\
3 &  5 &  16 &  26 &  34\\
4 &  6 &  17 &  27 &  35\\
\hline
\end{tabular}


There are better ways, as Werner alludes to, but here is a quick way, if you don't need to use it often (since the box width must be tailored to the content).

I have stuffed it into a macro \boxit{<width>}.

\documentclass{article}
\def\boxit#1{%
\smash{\fboxsep=0pt\llap{\rlap{\fbox{\strut\makebox[#1]{}}}~}}\ignorespaces
}
\begin{document}
\begin{tabular}{| c | c  c  c  c | }
\hline
Location & \multicolumn{4}{c|}{Rounds}\\
\hline
0 &  2 &  23 &  41 &  42\\
\boxit{1.52in} 1 &  3 &  24 &  42 &  43\\
2 &  4 &  25 &  43 &  44\\
3 &  5 &  \boxit{0.81in} 16 &  26 &  34\\
4 &  6 &  17 &  27 &  35\\
\hline
\end{tabular}
\end{document}


If your tabular data is purely numeric, one could trim the height of the box to be symmetric about the numerals (the above solution uses a \strut which allows extra depth for descenders). I also make the box in red, with a thicker (1pt) rule.

\documentclass{article}
\usepackage{xcolor}
\def\boxit#1{%
\smash{\color{red}\fboxrule=1pt\relax\fboxsep=2pt\relax%
\llap{\rlap{\fbox{\vphantom{0}\makebox[#1]{}}}~}}\ignorespaces
}
\begin{document}
\begin{tabular}{| c | c  c  c  c | }
\hline
Location & \multicolumn{4}{c|}{Rounds}\\
\hline
0 &  2 &  23 &  41 &  42\\
\boxit{1.47in} 1 &  3 &  24 &  42 &  43\\
2 &  4 &  25 &  43 &  44\\
3 &  5 &  \boxit{0.77in} 16 &  26 &  34\\
4 &  6 &  17 &  27 &  35\\
\hline
\end{tabular}
\end{document}


• Thanks a lot. Is it possible to make it red box? – user12290 Apr 7 '15 at 15:18
• @user12290 I have to depart at the moment, but will do so upon my return. – Steven B. Segletes Apr 7 '15 at 15:33
• @user12290 But to do so is easy. \usepackage{xcolor} in the preamble, and add \color{red} just inside the \smash argument, as in \smash{\color{red}...} – Steven B. Segletes Apr 7 '15 at 15:35
• @user12290 ... and \fboxrule=1pt\relax will make the box rule thicker. – Steven B. Segletes Apr 7 '15 at 15:38