# How to create a box spanning across rows and columns of a table [duplicate]

Starting from this thread How to make box in a row of a table. I'm also aware of Highlight elements in the matrix I'm just wondering if there is any quick way like this to create a box spanning across rows and columns rather than having to use TikZ

\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}


## marked as duplicate by schtandard, Phelype Oleinik, Raaja, Marcel Krüger, Stefan PinnowJun 7 at 15:07

• Did you look at the question the question you linked is a duplicate of? It's right there.. – schtandard Jun 7 at 13:22
• Many thanks. I'm aware of Highlight elements in the matrix I'm just wondering if there is any quick way like this to create a box spanning across rows and columns rather than having to use TikZ. – OrangeEfficiency Jun 7 at 13:29
• What do you mean? There are many different solutions there, not all of them using TikZ. The fact that all of the top voted ones use TikZ is not a coincidence though, it's just very easy with TikZ. Why do you not want to use TikZ? Why are the alternatives in the other question not adequate? – schtandard Jun 7 at 13:35
• I'm just a bit curious as how to modify the provided code to make a box spanning across both rows and columns rather than just columns. – OrangeEfficiency Jun 7 at 13:42

Modifying the given macro to accept a height in addition to a width is easy enough. I do not understand why you would want to do this, though. It is much easier to follow the approaches given here than to manually specify width and height of the box, which is subject to change depending on factors like font, font size, table content etc. But if you insist..

\documentclass{article}

\usepackage{xcolor}

\def\boxit#1#2{%
\smash{\color{red}\fboxrule=1pt\relax\fboxsep=2pt\relax%
\llap{\rlap{\fbox{\phantom{\rule{#1}{#2}}}}~}}\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}{.1in} 1 &  3 &  24 &  42 &  43\\
2 &  4 &  25 &  43 &  44\\
3 &  5 &  16 &  26 &  34\\
4 &  6 &  \boxit{0.77in}{.26in}17 &  27 &  35\\
\hline
\end{tabular}

\end{document}


• Many thanks for this. I don't need to use it often so I simply prefer a quick way like this. – OrangeEfficiency Jun 7 at 14:00