I am trying to create a table with alternating row colours and rounded corners.
I combined two answers so far to achieve this:
- Thorsten Donnig's answer about alternating row colours.
- Jake's answer about adding rounded corners to a table.
This works great in general, but the problem is that the alternating row colours method fills a proper square, not a rounded one, and the row colour "leaks" outside the table border. See the top left and bottom left corners of the image below.
Is there an easy way to fix this? Maybe by using the named tikz
node to clip everything outside it?
Issue:
MWE:
\documentclass[border=10pt,10pt,table]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\definecolor{tablerow1}{RGB}{225,217,205}
\definecolor{tablerow2}{RGB}{236,229,221}
\begin{document}
\rowcolors{2}{tablerow1}{tablerow2}
\begin{tikzpicture}
\node (thetable) [inner sep=0pt] {
\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash\hsize=1.4\hsize}X>{\raggedright\arraybackslash\hsize=0.6\hsize}X}
\arrayrulecolor{white}
\textbf{Column 1} & \textbf{Column 2} \\ \hline
Some text. & Some text. \\ \hline
Some text. & Some text.
\end{tabularx}
};
\draw [rounded corners=.5em] (thetable.north west) rectangle (thetable.south east);
\end{tikzpicture}
\end{document}
:-)
Seems like I don't need something that complicated - all I need is to discard everything outside the node that draws the rounded rectangle. Plus, I'd prefer to stick withtabularx
instead oftikz
'smatrix
.tcolorbox
package?