垂直居中 tcolorbox、tcbraster 的内容和绝对位置

垂直居中 tcolorbox、tcbraster 的内容和绝对位置

我想创建一个tcolorbox,但现在我需要你的帮助:

  1. 垂直居中内容

  2. 绝对位置tcolorbox:当我改变位置时X或者

我的最小代码:

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

在此处输入图片描述

非常感谢

答案1

如果您加载并使用中的\usepackage[export]{adjustbox}选项,那就非常简单了。valign=c\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}

在此处输入图片描述

相关内容