1

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}
  • Did you look at the question the question you linked is a duplicate of? It's right there.. – schtandard Jun 07 '19 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 07 '19 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 07 '19 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 07 '19 at 13:42

1 Answers1

3

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}

MWE output

schtandard
  • 14,892