# Gaps between blocks in NiceTabular

Here's a starting point for my example:

\begin{NiceTabular}{c c c c c c}
\hline
x & x & x & x & x & x \\
x & \Block[draw=black]{1-5}{thin} \\
x & x & x & x & \Block[draw=black]{3-2}{tall} \\
x & x & x & x \\
x & x & x & x \\
\hline
\end{NiceTabular}


This creates:

I don't want the tall block to be touching the bottom or the thin block. Fixing the first part of that is easy:

\begin{NiceTabular}{c c c c c c}
\hline
x & x & x & x & x & x \\
x & \Block[draw=black]{1-5}{thin} \\
x & x & x & x & \Block[draw=black]{3-2}{tall} \\
x & x & x & x \\
x & x & x & x \\
\\[-3mm]
\hline
\end{NiceTabular}


But when I try the same for the top margin, this happens:

\begin{NiceTabular}{c c c c c c}
\hline
x & x & x & x & x & x \\
x & \Block[draw=black]{1-5}{}  \\
\\[-3mm]
x & x & x & x & \Block[draw=black]{3-2}{tall} \\
x & x & x & x \\
x & x & x & x \\
\\[-3mm]
\hline
\end{NiceTabular}


Now the tall block is no longer tall enough to encompass the top row.

How do I create a small gap between the rows/blocks without affecting their size?

Here is a solution which shrinks all the sides of the rectangles.

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

\begin{document}

\begin{NiceTabular}{c c c c c c}
\hline
x & x & x & x & x & x \\
x & \Block[tikz={offset=0.5pt,draw}]{1-5}{thin} \\
x & x & x & x & \Block[tikz={offset=0.5pt,draw}]{3-2}{tall} \\
x & x & x & x \\
x & x & x & x \\
\\[-4mm]
\hline
\end{NiceTabular}

\end{document}


As usual with nicematrix, you need several compilations.

If you don't want to shrink horizontally, it's always possible to draw whatever you want by using TikZ and the PGF/TikZ nodes created by nicematrix under the cells, rows and columns of the tabular.

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

\begin{document}

\begin{NiceTabular}{c c c c c c}
\Hline
x & x & x & x & x & x \\
x & \Block{1-5}{thin} \\[1mm]
x & x & x & x & \Block{3-2}{tall} \\
x & x & x & x \\
x & x & x & x \\[1mm]
\Hline
\CodeAfter
\begin{tikzpicture}
\draw (2-|2) rectangle ([yshift=1mm]3-|last) ;
\draw (3-|5) rectangle ([yshift=1mm]6-|last) ;
\end{tikzpicture}
\end{NiceTabular}

\end{document}


• For some reason this is giving me an error that says: "Package pgfkeys Error: I do not know the key '/tikz/offset', to which you passed '0.5pt', and I am going to ignore it. Perhaps you misspelled it." Any idea why? Commented Mar 18 at 9:36
• I think that you don't have the latest version of nicematrix. You should update thoroughly your TeX installation (MiKTeX, TexLives, etc.). If you use Overleaf, you should upload the latest version of the file nicematrix.sty in the repertory of your Overleaf project. You can find that file on the SVN server of TeXLive: www.tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty Commented Mar 18 at 9:42
• Now I got it working, thank you! But unfortunately this is not quite what I want. This shrinks the entire rectangle on all sides, which becomes more noticeable when I want to increase the gap size. I want to introduce a gap without changing the rectangle size. Commented Mar 18 at 9:56
• I have added a second part to my answer. Commented Mar 18 at 10:05
• This works. Thank you very much! Commented Mar 18 at 10:10