3

Inspired by this, here is an MWE that show a visible margin between the end of the row and the right hand side of the table. That's annoying. Any idea how to remove that?

\documentclass[12pt]{article}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fancy table
% https://tex.stackexchange.com/questions/112343/beautiful-table-samples
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}
\usepackage{multirow}

\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\newcolumntype{Z}{>{\centering\arraybackslash\hsize=.6\hsize}X}

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


\begin{document}

\begin{tcolorbox}[tab2,tabularx={Z || Z | Z | Z},title=AAA,width=0.7\textwidth]
    BBB & BBB & BBB & BBB \\ \hline\hline
    \multirow{3}{*}{XXX} & AAA & AAA & AAA \\ \cline{2-4}
    &  & AAA & AAA \\ \cline{2-4}
    &  & AAA & AAA
\end{tcolorbox}

\end{document}

enter image description here

  • 3
    Change the definition of Z column \newcolumntype{Z}{>{\centering\arraybackslash}X} – Salim Bou Nov 30 '16 at 12:52
2

The problem comes a misunderstanding of >{\hsize=0.6\hsize}X: it is made for X columns of unequal lengths and the values work as barycentric coordinates: their sum must be equal to the number of columns (4, here). Their sum is equal to 2.4 instead! As all your columns have equal widths, remove this specification and it will be fine:

\documentclass[12pt]{article}
\usepackage[table, dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\tcbuselibrary{skins}
\usepackage{multirow}

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

\begin{document}

\begin{tcolorbox}[tab2,tabularx={Z || Z | Z | Z },title=AAA, width=0.7\textwidth]
    BBB & BBB & BBB & BBB \\ \hline\hline
    \multirow{3}{*}{XXX} & AAA & AAA & AAA \\ \cline{2-4}
    & & AAA & AAA \\ \cline{2-4}
    & & AAA & AAA
\end{tcolorbox}

\end{document} 

enter image description here

Additionally, note the usenames option for xcolor is deprecated as it's tthe default now. I added the table option, which avoids you having to load explicitly colortbl.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.