2

I would like to create a tcolorbox, but now I need your help:

  1. Centering vertically the content

  2. Absolute position of tcolorbox: when I change position x or y

My minimal code:

\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|Y|},title={This is a table},boxrule=0.8pt]
A & B          \\\hline
A   & \includegraphics[width = 2cm]{"example-image-a"}   \\\hline
A & AAA  \\\hline
B  & BBB  \\\hline
A   & \includegraphics[width = 2cm]{"example-image-b"} 
\end{tcolorbox}
}
\end{tcbraster}


\end{document}

enter image description here

Thanks so much

1 Answer 1

3

It's very simple if you load \usepackage[export]{adjustbox} and use the option valign=c in \includegraphics.

\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}}

\usepackage[export]{adjustbox}

\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|Y|},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}

enter image description here

3
  • Many thanks for your help. It look beautiful
    – latexforti
    Mar 3, 2019 at 8:28
  • When i edit {Y|Y|} => {|Y{2cm}|Y{5cm}|}, the center vertical line between 2 columns is hidden. Please help. imgur.com/zfiFj9s
    – latexforti
    Mar 3, 2019 at 9:35
  • 1
    @tisaigon I have no time at the moment, sorry. Please post another question, someone else will help before me.
    – CarLaTeX
    Mar 3, 2019 at 9:38

You must log in to answer this question.

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