6

I want to make a table and highlight a certain region in it using thick lines as shown below.

Enter image description here

In my attempt to reproduce the above table, I have used the tabu package to make thick horizontal and vertical lines. However, there isn't any command in LaTeX to make thick vertical lines spanning given rows. Basically, I'm looking for a vertical version of \tabucline. Here's my code and output:

\begin{table}[h!]
\centering
\renewcommand{\arraystretch}{1.75}
\begin{tabu}{|[1.5pt]c|c|c|c|c|c|c|c|}
    \tabucline[1.5pt]{-}
    (-4, -4) & (-3, -4) & (-2, -4) & (-1, -4) & (0, -4) & (1, -4) & (2, -4) & (3, -4)    \\
    \hline
    (-4, -3) & (-3, -3) & (-2, -3) & (-1, -3) & (0, -3) & (1, -3) & (2, -3) & (3, -3)    \\
    \hline
    (-4, -2) & (-3, -2) & (-2, -2) & (-1, -2) & (0, -2) & (1, -2) & (2, -2) & (3, -2)    \\
    \hline
    (-4, -1) & (-3, -1) & (-2, -1) & (-1, -1) & (0, -1) & (1, -1) & (2, -1) & (3, -1)    \\
    \tabucline[1.5pt]{5-8}\hline
    (-4, 0) & (-3, 0) & (-2, 0) & (-1, 0) & (0, 0) & (1, 0) & (2, 0) & (3, 0)    \\
    \tabucline[1.5pt]{2-4}\hline
    (-4, 1) & (-3, 1) & (-2, 1) & (-1, 1) & (0, 1) & (1, 1) & (2, 1) & (3, 1)    \\
    \hline
    (-4, 2) & (-3, 2) & (-2, 2) & (-1, 2) & (0, 2) & (1, 2) & (2, 2) & (3, 2)    \\
    \hline
    (-4, 3) & (-3, 3) & (-2, 3) & (-1, 3) & (0, 3) & (1, 3) & (2, 3) & (3, 3)    \\
    \hline\tabucline[1.5pt]{1-1}
  \end{tabu}
\end{table}

Enter image description here

2 Answers 2

7
  • don't use tabu. It is buggy and not maintained
  • instead it I suggest to use (relative new) package tabularray
  • using it you can define all horizontal as well vertical lines in table preamble.
\documentclass{article}
\usepackage{tabularray}

\begin{document}
    \begin{table}[ht]
    \centering
\begin{tblr}{hlines = {0.1pt}, vlines = {0.1pt},
             hline{1} = 1pt, 
             hline{5}={5-Z}{1pt}, hline{6}={2-4}{1pt}, hline{Z}={1}{1pt},
             vline{1}={1pt}, 
             vline{2}={6-Z}{1pt}, vline{5}={5}{1pt}, vline{Z}={1-4}{1pt},
             colspec =  {*{8}{Q[c, $]}},
             }
    (-4, -4) & (-3, -4) & (-2, -4) & (-1, -4) & (0, -4) & (1, -4) & (2, -4) & (3, -4)    \\
    (-4, -3) & (-3, -3) & (-2, -3) & (-1, -3) & (0, -3) & (1, -3) & (2, -3) & (3, -3)    \\
    (-4, -2) & (-3, -2) & (-2, -2) & (-1, -2) & (0, -2) & (1, -2) & (2, -2) & (3, -2)    \\
    (-4, -1) & (-3, -1) & (-2, -1) & (-1, -1) & (0, -1) & (1, -1) & (2, -1) & (3, -1)    \\
   (-4, 0)   & (-3, 0)  & (-2, 0)  & (-1, 0)  & (0, 0)  & (1, 0)  & (2, 0)  & (3, 0)     \\
    (-4, 1)  & (-3, 1)  & (-2, 1)  & (-1, 1)  & (0, 1)  & (1, 1)  & (2, 1)  & (3, 1)     \\
    (-4, 2)  & (-3, 2)  & (-2, 2)  & (-1, 2)  & (0, 2)  & (1, 2)  & (2, 2)  & (3, 2)     \\
    (-4, 3)  & (-3, 3)  & (-2, 3)  & (-1, 3)  & (0, 3)  & (1, 3)  & (2, 3)  & (3, 3)     \\
  \end{tblr}
\end{table}
\end{document}

enter image description here

Note: above MWE is tested with tabularray package version 2022C.

3
  • 1
    Wow this method is super cool! Thanks a lot. I'll look into the package documentation for further use.
    – ShaunakP
    Commented Aug 20, 2022 at 13:13
  • You are always a talented user.
    – Sebastiano
    Commented Aug 20, 2022 at 17:57
  • 1
    @Sebastiano, oh, thank you very much! You are so kind person!
    – Zarko
    Commented Aug 20, 2022 at 18:05
5

Here is a solution with {NiceTabular} of nicematrix.

In this environment, the key hvlines draws all the rules.

However, it's still possible to draw whatever rule you want with Tikz by using the Tikz nodes created by nicematrix under the rows, columns and cells.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}
\begin{table}[ht]
\centering
\begin{NiceTabular}[hvlines]{cccccccc}
    (-4, -4) & (-3, -4) & (-2, -4) & (-1, -4) & (0, -4) & (1, -4) & (2, -4) & (3, -4)    \\
    (-4, -3) & (-3, -3) & (-2, -3) & (-1, -3) & (0, -3) & (1, -3) & (2, -3) & (3, -3)    \\
    (-4, -2) & (-3, -2) & (-2, -2) & (-1, -2) & (0, -2) & (1, -2) & (2, -2) & (3, -2)    \\
    (-4, -1) & (-3, -1) & (-2, -1) & (-1, -1) & (0, -1) & (1, -1) & (2, -1) & (3, -1)    \\
    (-4, 0)  & (-3, 0)  & (-2, 0)  & (-1, 0)  & (0, 0)  & (1, 0)  & (2, 0)  & (3, 0)     \\
    (-4, 1)  & (-3, 1)  & (-2, 1)  & (-1, 1)  & (0, 1)  & (1, 1)  & (2, 1)  & (3, 1)     \\
    (-4, 2)  & (-3, 2)  & (-2, 2)  & (-1, 2)  & (0, 2)  & (1, 2)  & (2, 2)  & (3, 2)     \\
    (-4, 3)  & (-3, 3)  & (-2, 3)  & (-1, 3)  & (0, 3)  & (1, 3)  & (2, 3)  & (3, 3)     \\
\CodeAfter
  \tikz \draw [very thick] (1-|1) |- (9-|2) |- (5-|5) |- (4-|last) |- (1-|1) -- cycle ; 
\end{NiceTabular}
\end{table}
\end{document}

You need several compilations (because of the PGF/Tikz nodes).

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .