A Table Cell with Rounded Corners in LaTeX

borderrounded-cornerstablestikz-matrix

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}

Best Answer

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

Related Question