4

Suppose I have a table like this:

An arbitrary table without rounded corners

\documentclass{article}

\usepackage{multirow}
\begin{document}
\begin{tabular}{cc|cc|c|}
\cline{3-5}
                        &   & \multicolumn{2}{c|}{\multirow{2}{*}{a}} & c \\ \cline{1-2} \cline{5-5} 
\multicolumn{1}{|c|}{d} & e & \multicolumn{2}{c|}{}                   & h \\ \hline
\multicolumn{2}{c|}{}       & \multicolumn{1}{c|}{i}        & j       & k \\ \hline
\multicolumn{1}{|c|}{l} & m & \multicolumn{1}{c|}{n}        & o       & p \\ \hline
\end{tabular}
\end{document}

Is there any way to modify each cell of a table in LaTeX, and change the corners of each box independently? How can I achieve such a table?

The "a" cell is a multirow cell, and I want to change the corners of the other cells similar to the image below:

An arbitrary table with custom rounded corners

In this answer [here], it only gives the entire table's corner, and you cannot make a table like this one:

enter image description here

What about coloring those cells?

This is the code for the latest table with LaTeX's default sharp corners:

\documentclass{article}

\usepackage{multirow}
\begin{document}
\begin{tabular}{ll|ll|ll|}
\cline{3-6}
                        &   & \multicolumn{2}{l|}{\multirow{2}{*}{a}}    & \multicolumn{2}{l|}{b}  \\ \cline{5-6} 
                        &   & \multicolumn{2}{l|}{}                      & \multicolumn{2}{l|}{c}  \\ \hline
\multicolumn{1}{|l|}{x} & 1 & y                    & 1                   & z           & 1         \\ \hline
\multicolumn{1}{|l|}{}  &   &                      &                     &             &           \\ \hline
\end{tabular}
\end{document}
1
  • 1
    You could use a TikZ matrix, maybe. Or you could try the nicematrix package. But please consider making your MWE compilable (that is, add a \documentclass etc). Commented Sep 6, 2023 at 9:54

1 Answer 1

6

You can make use of the nicematrix package, which gives you a lot of flexibility as it allows to draw the borders with TikZ (but it is also quite a lot of work as you'd need to draw everything manually). You could do for example like this:

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

\begin{document}

\begin{NiceTabular}{ccccc}
\CodeBefore
    \begin{tikzpicture} 
        \fill[yellow, rounded corners] 
            (3-|3) -- (1-|3) [sharp corners] -- (1-|5) -- (3-|5) -- cycle;
    \end{tikzpicture}
\Body
  &   & \Block{2-2}{a} & & c \\
d & e &   &   & h \\
  &   & i & j & k \\
l & m & n & o & p \\
\CodeAfter
    \begin{tikzpicture} 
        \draw[rounded corners] 
            (3-|3) -- (1-|3) -- (1-|6)
            (1-|6) -- (5-|6) -- (5-|1)
            (2-|3) -- (2-|1) -- (3-|1) -- (3-|3) -- (5-|3);
        \draw 
            (4-|1) -- (5-|1)
            (2-|2) -- (3-|2) 
            (4-|2) -- (5-|2) 
            (3-|4) -- (5-|4)
            (1-|5) -- (5-|5)
            (2-|5) -- (2-|6)
            (3-|3) -- (3-|6)
            (4-|1) -- (4-|6);
    \end{tikzpicture}
\end{NiceTabular}

\end{document}

enter image description here

2
  • Why is the width of block "a" fixed? Can you give me a trick to change it? (Based on these codes)
    – Qaher
    Commented Sep 6, 2023 at 10:39
  • 1
    @Qaher The block is as wide as the two columns it is spanning. You can set the width of a column to 2cm by using w{c}{2cm} instead of c for example. If you want the block to span only two rows of one column, just use \Block{2-1}{a}. Consider consulting the package manual. Commented Sep 6, 2023 at 11:10

You must log in to answer this question.

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