1

I would like to nest two boxes in my table. It looks like this:

 content      content      content      content      content
            +----------------------+
 content    | content      content |    content      content
            |+--------------------+|
 content    ||content      content||    content      content
            |+--------------------+|
 content    | content      content |    content      content
            +----------------------+
 content      content      content      content      content

I looked at Framing cells in a table which provides a good solution, but the main issue is that I can't set the length of the horizontal line in the inner box. \cline{2-3} always produces the same width. It would produce something that looks like this:

 content      content      content      content      content
            +----------------------+
 content    | content      content |    content      content
            ++--------------------++
 content    ||content      content||    content      content
            ++--------------------++
 content    | content      content |    content      content
            +----------------------+
 content      content      content      content      content

But I would like to avoid the inner box from intersecting with / joining the outer box.

2
  • 1
    You should rather show the code so far instead of a an ASCII-ART like image ;-)
    – user31729
    Feb 2, 2016 at 16:51
  • Using matrix from TikZ is probably the simplest way to achieve this.
    – Zarko
    Feb 2, 2016 at 17:05

2 Answers 2

4

For exercises and starting point:

enter image description here

\documentclass[border=3mm,
               tikz,
               preview
               ]{standalone}
\usetikzlibrary{fit,
                matrix,
                }

\begin{document}   
\begin{tikzpicture}[
every node/.style = {inner sep=0.5mm}
                    ]
\matrix (magic) [matrix of nodes,
                 column sep=1.5mm,
                 row sep=1.5mm]
{
content & content & content & content & content \\
content & content & content & content & content \\
content & content & content & content & content \\
content & content & content & content & content \\
content & content & content & content & content \\
};
\node (a) [draw, fit=(magic-3-2) (magic-3-3)] {};
\node (b) [draw, fit=(magic-2-2) (a) (magic-4-3)] {};
\end{tikzpicture}
    \end{document}

How to do this in your table? First you need to provide complete document with your table, that I can see, what can be done. Above image only replicate your image in question :-)

3

Here is a solution with {NiceTabular} of nicematrix. That environment is similar to the classical environment {tabular} (as provided by array) but creates PGF/TikZ nodes under the cells, rows and columns. Then it's possible to use these nodes with TikZ to draw whatever rule you want.

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

\begin{document}

\begin{NiceTabular}{ccccc}
  content & content & content & content & content \\
  content & content & content & content & content \\
  content & content & content & content & content \\
  content & content & content & content & content \\
  content & content & content & content & content \\
\CodeAfter
  \tikz \draw (1-|1) rectangle (last-|last) 
              (2-|2) rectangle (5-|4) 
              ([xshift=2pt]3-|2) rectangle ([xshift=-2pt]4-|4) ; 
\end{NiceTabular}

\end{document}

Output of the above code

You must log in to answer this question.

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