Table with rounded corners?
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}
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:
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 width
s.
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}