23

enter image description here

This table I can create with this code:

\begin{tabular}{|l|l|}
  \hline
  \multicolumn{2}{|c|}{Team sheet} \\
  \hline
  GK & Paul Robinson \\
  LB & Lucus Radebe \\
  DC & Michael Duberry \\
  DC & Dominic Matteo \\
  RB & Didier Domi \\
  MC & David Batty \\
  MC & Eirik Bakke \\
  MC & Jody Morris \\
  FW & Jamie McMaster \\
  ST & Alan Smith \\
  ST & Mark Viduka \\
  \hline
\end{tabular}

But is there a possibility to use rounded corners? I'm talking about the 4 main corners and not the corners of each cell.

7 Answers 7

24

You can use a TikZ node with inner sep=0pt that holds the table, and then draw a rectangle around it.

Update: You can enclose this TikZ/tabular construct in a table environment to add a table caption and label to it.

\documentclass{article}
\usepackage{tikz}
\usepackage[bf]{caption}

\begin{document}

\begin{table}
\caption{A table with rounded corners}
\centering
\begin{tikzpicture}
\node (table) [inner sep=0pt] {
\begin{tabular}{l|l}
  \multicolumn{2}{c}{Team sheet} \\
  \hline
  GK & Paul Robinson \\
  LB & Lucus Radebe \\
  DC & Michael Duberry \\
  DC & Dominic Matteo \\
  RB & Didier Domi \\
  MC & David Batty \\
  MC & Eirik Bakke \\
  MC & Jody Morris \\
  FW & Jamie McMaster \\
  ST & Alan Smith \\
  ST & Mark Viduka \\
\end{tabular}
};
\draw [rounded corners=.5em] (table.north west) rectangle (table.south east);
\end{tikzpicture}
\label{tab1}
\end{table}

Table~\ref{tab1} can be referenced like any other.
\end{document}

table with TikZ rounded corners, caption and label

7
  • Oh wow, what a staccato of TikZ solutions here. Interesting to see the variation in the details of the approaches, though.
    – Jake
    Commented Feb 4, 2011 at 10:12
  • But yours is the simplest. So +1 for that. Commented Feb 4, 2011 at 10:18
  • @Jake Thanks that works, but were can i put the label and caption? Commented Feb 7, 2011 at 21:41
  • 1
    @Roflcoptr: You just enclose the whole stuff in a table environment, like you would with a normal table. I've edited my answer accordingly.
    – Jake
    Commented Feb 7, 2011 at 22:00
  • Captions above tables are better set up with the caption package. Commented Feb 7, 2011 at 22:02
13

All (I think?) the previous solutions don't work all that well in combination with coloured cell backgrounds: the backgrounds will stick out over the prettily rounded corners.

The solution is to apply clipping. And the difficulty with that is that the clipping path needs to be set before the table is drawn. A.f.a.I.k., the only way of achieving this is saving the whole table into a box first, then setting the clipping path accordingly. Just adding clip to the TikZ node didn't do it for me at least.

Since this amounts to quite a bit of boilerplate around the table, you could put the whole thing into an environment, and use the environ package to capture the table content conveniently.

\documentclass{article}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{array}
\usepackage{environ}
\usepackage{tikz}

\newsavebox{\tablebox}
\definecolor{tablecolor}{named}{ForestGreen}

\NewEnviron{rndtable}[1]{%
  \addtolength{\extrarowheight}{1ex}%
  \rowcolors{2}{tablecolor!20}{tablecolor!40}%
  \savebox{\tablebox}{%
    \begin{tabular}{#1}%
      \BODY%
    \end{tabular}}%
  \begin{tikzpicture}
    \begin{scope}
      \clip[rounded corners=1ex] (0,-\dp\tablebox) -- (\wd\tablebox,-\dp\tablebox) -- (\wd\tablebox,\ht\tablebox) -- (0,\ht\tablebox) -- cycle;
      \node at (0,-\dp\tablebox) [anchor=south west,inner sep=0pt]{\usebox{\tablebox}};
    \end{scope}
    \draw[rounded corners=1ex] (0,-\dp\tablebox) -- (\wd\tablebox,-\dp\tablebox) -- (\wd\tablebox,\ht\tablebox) -- (0,\ht\tablebox) -- cycle;
  \end{tikzpicture}
}

\begin{document}

\begin{rndtable}{l|l}
    \multicolumn{2}{c}{\cellcolor{tablecolor}\color{white} Team sheet} \\ \hline
    GK & Paul Robinson \\
    LB & Lucus Radebe \\
    DC & Michael Duberry \\
    DC & Dominic Matteo \\
    RB & Didier Domi \\
    MC & David Batty \\
    MC & Eirik Bakke \\
    MC & Jody Morris \\
    FW & Jamie McMaster \\
    ST & Alan Smith \\
    ST & Mark Viduka \\
  \end{rndtable}

\end{document}

Looks like this:

enter image description here

3
  • tex.stackexchange.com/a/67736/3235 ;)
    – percusse
    Commented Apr 28, 2014 at 14:01
  • @percusse ah, a TikZ matrix, not bad! Maybe mine is more convenient if you already have your table code with all the conventional colortbl/array/multicolumn markup?
    – mabartibin
    Commented Apr 28, 2014 at 14:12
  • Wow! @mabartibin that is good. Just what I've been looking for.
    – BlackMagic
    Commented Oct 25, 2015 at 3:48
12

tcolorbox includes options tabularx and tabularx* which can draw framed tables with rounded corners.

The main problem will be to decide table width. All tcolorboxes use \linewidth as default horizontal box size, liketabularx and tabularx*. Therefore, tables narrower than \linewidth need to use manually calculated widths.

An example:

\documentclass{article}
\usepackage{array,tabularx}
\usepackage[table]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage[bf]{caption}

\begin{document}

\begin{table}
\caption{A table with rounded corners}
\centering
\rowcolors{1}{black!30}{white}
\begin{tcolorbox}[enhanced, width=.5\linewidth, tabularx={>{\centering\arraybackslash}l|>{\centering\arraybackslash}X}, title={Team sheet}]
  GK & Paul Robinson \\
  LB & Lucus Radebe \\
  DC & Michael Duberry \\
  DC & Dominic Matteo \\
  RB & Didier Domi \\
  MC & David Batty \\
  MC & Eirik Bakke \\
  MC & Jody Morris \\
  FW & Jamie McMaster \\
  ST & Alan Smith \\
  ST & Mark Viduka \\
\end{tcolorbox}
\label{tab1}
\end{table}

Table~\ref{tab1} can be referenced like any other.
\end{document}

enter image description here

1
  • One of a nice suggestion...
    – MadyYuvi
    Commented Aug 27, 2019 at 5:22
7

you can do it with tikz fit library

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}

\begin{tikzpicture}
 \node[inner sep=0pt] (tab){%
 \begin{tabular}{l|l}
  \multicolumn{2}{c}{Team sheet} \\
  \hline
  GK & Paul Robinson \\
  LB & Lucus Radebe \\
  DC & Michael Duberry \\
  DC & Dominic Matteo \\
  RB & Didier Domi \\
  MC & David Batty \\
  MC & Eirik Bakke \\
  MC & Jody Morris \\
  FW & Jamie McMaster \\
  ST & Alan Smith \\
  ST & Mark Viduka \\
\end{tabular}
};
\node[draw=red, inner sep=0pt, rounded corners=3pt, line width=2pt,
fit=(tab.north west) (tab.north east) (tab.south east) (tab.south west)] {};
\end{tikzpicture}

\end{document}

enter image description here

3
  • about 30sec too late :) and a slightly different approach
    – Martin H
    Commented Feb 4, 2011 at 10:06
  • Hmm. I always forget this inner sep option. Commented Feb 4, 2011 at 10:19
  • 2
    AFAIK you can just say fit=(tab) here. TikZ then automatically takes the (tab.north west) (tab.north east) (tab.south east) (tab.south west) coordinates. Commented Feb 4, 2011 at 10:23
7

You could do this by putting the table into a tikZ node and framing that node with a rectangle that has rounded corners. See code below for some inspiration.

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
  \begin{tikzpicture}
    \node (tbl) {%
      \begin{tabular}{l|l}
        \multicolumn{2}{c}{Team sheet} \\ \hline
        GK & Paul Robinson \\
        LB & Lucus Radebe \\
        DC & Michael Duberry \\
        DC & Dominic Matteo \\
        RB & Didier Domi \\
        MC & David Batty \\
        MC & Eirik Bakke \\
        MC & Jody Morris \\
        FW & Jamie McMaster \\
        ST & Alan Smith \\
        ST & Mark Viduka \\
      \end{tabular}
    };
      \draw[rounded corners] ($(tbl.north west)+(0.14,-0.14)$) rectangle ($(tbl.south east)+(-0.14,0.14)$);
  \end{tikzpicture}
\end{document}

The result of the above code

7

Here is what you can do with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{siunitx}
\usepackage{nicematrix}

\begin{document}

\renewcommand{\arraystretch}{1.5}
\begin{NiceTabular}{lcS}[hvlines, rounded-corners, rules/color=gray!60]
\CodeBefore
   \rowcolor{gray!60}{1}
   \rowcolors{2}{gray!20}{}
\Body
   \RowStyle[bold]{}
    Town & Correspondant & {Value} \\
   Paris & Peter & 1.23 \\
   London & Helena & 23.23\\
   Madrid & Georges &12.5 \\
   Moscou & Henry & 4.77 \\
   Tokyo & Selena & 85.3 \\
   Lima & Victoria & 13.2 \\
   Cap Town & Alexandra & 6 \\
   Chicago & Vladimier & 1.34
\end{NiceTabular}

\end{document}

Output of the above code

1
  • Simple and nice suggestion
    – MadyYuvi
    Commented Jul 21, 2023 at 17:05
6

In OpTeX, you can use \inoval{\table{...}}:

\inoval[\fcolor=\relax \lcolor=\Black] {\table{l|l}{
  GK & Paul Robinson \cr
  LB & Lucus Radebe \cr
  DC & Michael Duberry \cr
  DC & Dominic Matteo \cr
  RB & Didier Domi \cr
  MC & David Batty \cr
  MC & Eirik Bakke \cr
  MC & Jody Morris \cr
  FW & Jamie McMaster \cr
  ST & Alan Smith \cr
  ST & Mark Viduka \cr
}}

\bye

You must log in to answer this question.

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