# Missing vertical line when insert column width in tabularx

This question is a sequel to this question.

After column width added (Y{2cm}|Y{5cm}|), vertical line is missing.

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[skins,listings,breakable,listingsutf8,theorems,hooks,fitting]{tcolorbox}%
\tcbuselibrary{most}
\usepackage{makecell,tabularx}
\setcellgapes{12pt}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}

\usepackage{tikz}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

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

\begin{document}
\begin{tcbraster}[colback=red!5!white,colframe=red!75!black,
fonttitle=\bfseries,fontlower=\itshape] %
{
\makegapedcells
\begin{tcolorbox}[tableA,tabularx*={\renewcommand{\arraystretch}{1.5}}{Y{2cm}|Y{5cm}|},title={This is a table},boxrule=0.8pt]
A & B          \\\hline
A   & \includegraphics[width = 2cm, valign=c]{"example-image-a"}   \\\hline
A & AAA  \\\hline
B  & BBB  \\\hline
A   & \includegraphics[width = 2cm, valign=c]{"example-image-b"}
\end{tcolorbox}
}
\end{tcbraster}

\end{document}


How can I get the vertical line?

Thank you

• The Y type column does not take a width argument as you tried to to. This is why your above shown code reslts in the following error message: Package array Error: Illegal pream-token (2cm): As usual, it is not worth looking at the 'output' if you recieve an error message. – leandriis Mar 3 at 10:56
• If you want unevenly wide columns, you might be interested in using >{\hsize=0.56\hsize}Y|>{\hsize=1.44\hsize}Y| instead. This will result in the following output: i.stack.imgur.com/b3LV5.png – leandriis Mar 3 at 10:59
• @leandriis thank for your solution. And How can i set table width by cm? Thanks – latexforti Mar 3 at 11:41
• do you really need tcbraster? how many boxes you will have in one row? table width is equal to tcolorbox width, but it in your case is defined by raster width and raster columns= (which you not defined). – Zarko Mar 3 at 12:06
• Since you use the tabularx mode and columns that derive from the x type column, you can only specify their width relative to \hsize as shown in my previous comment. If you prefer to specify column widths using cm tabularx might not be the best package to use. – leandriis Mar 3 at 12:07

If you want to specify relative widths, you can define Y as

\newcolumntype{Y}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}


and in the argument you put a decimal number representing the fraction reserved for the column. In the example below, the second column will be three times as wide as the first column. The sum of the factors should equal the number of X columns allocated, here two.

Full example, with some reordering of the code.

\documentclass{article}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}
% add only the libraries you need
%\tcbuselibrary{skins,listings,breakable,listingsutf8,theorems,hooks,fitting}

\usepackage{makecell,tabularx}
\usepackage{array}
\usepackage{colortbl}

\usepackage{tikz}

\newcolumntype{Y}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}

\setcellgapes{12pt}

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

\begin{document}

\begin{tcbraster}[
colback=red!5!white,
colframe=red!75!black,
fonttitle=\bfseries,
fontlower=\itshape
]{
\makegapedcells
\begin{tcolorbox}[
tableA,
tabularx*={\renewcommand{\arraystretch}{1.5}}{Y{0.5}|Y{1.5}},
title={This is a table},boxrule=0.8pt
]
A & B \\
\hline
A & \includegraphics[width = 2cm, valign=c]{"example-image-a"} \\
\hline
A & AAA \\
\hline
B & BBB \\
\hline
A & \includegraphics[width = 2cm, valign=c]{"example-image-b"}
\end{tcolorbox}
}
\end{tcbraster}

\end{document}


• thank so much. tabularX is not too asomwe – latexforti Mar 4 at 3:20