3

In the following code a table is drawn:

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}

\newcolumntype{Y}{>{\centering\arraybackslash}X}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=white!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}

\begin{document}

\begin{tcolorbox}[tab2,tabularx={X|Y|Y|Y|Y|Y},title= to be replaced with table number,boxrule=0.8pt]
group & one     & two     & three    & four     & sum      \\\hline
red   & 1000.00 & 2000.00 & 3000.00  & 4000.00  & 10000.00 \\\hline
green & 2000.00 & 3000.00 & 4000.00  & 5000.00  & 14000.00 \\\hline
blue  & 3000.00 & 4000.00 & 5000.00  & 6000.00  & 18000.00 \\\hline
sum   & 6000.00 & 9000.00 & 12000.00 & 15000.00 & 42000.00
\end{tcolorbox}

\end{document}

I have a few problems with it:

  1. The contents of the left column are not in the center of cells. How can I solve this problem?

  2. How can I add a label for this table?

  3. How can I increase the height of rows a bit more?

1 Answer 1

7

I could not follow whether you want to label using a separate counter or using the regular table counter. Here I used the table counter.

  1. Use the Y column type for first column also.

  2. Enclose the entire thing inside the table environment and then use

    title={Table \thetable. This is a table}
    
  3. You can use tabularx* (note the *) and put the \renewcommand{\arraystretch}{1.5} command to be executed before the tabular to increase the row height.

Now the full code:

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}

\newcolumntype{Y}{>{\centering\arraybackslash}X}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=white!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}

\begin{document}
\begin{table}[htb]
\refstepcounter{table}\label{tab:mytab}
\begin{tcolorbox}[tab2,tabularx*={\renewcommand{\arraystretch}{1.5}}{Y|Y|Y|Y|Y|Y},title={Table \thetable. This is a table},boxrule=0.8pt]
group & one     & two     & three    & four     & sum      \\\hline
red   & 1000.00 & 2000.00 & 3000.00  & 4000.00  & 10000.00 \\\hline
green & 2000.00 & 3000.00 & 4000.00  & 5000.00  & 14000.00 \\\hline
blue  & 3000.00 & 4000.00 & 5000.00  & 6000.00  & 18000.00 \\\hline
sum   & 6000.00 & 9000.00 & 12000.00 & 15000.00 & 42000.00
\end{tcolorbox}
\end{table}
From Table~\ref{tab:mytab}, we see many colors.
\end{document}

enter image description here

1
  • If my understanding is not correct let me know if any thing needs to be changed.
    – user11232
    Commented Oct 23, 2015 at 6:36

You must log in to answer this question.

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