在 tcolorbox tcbitemize 环境中合并列

在 tcolorbox tcbitemize 环境中合并列

我想将 tcolorbox tcbitemize 环境中第一行的第 3 列和第 4 列合并起来。详情请查看我的代码:但排版不是我想要的。我认为使用选项“code=”时出了点问题,但我真的不知道原因。有人能帮我解决这个问题吗?提前谢谢![在此处输入图片描述]1

\documentclass[12pt,a4paper]{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable,raster}

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\tcbset{%
    force width/.code={\tcbset@late@options{width={#1}}},
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\columnnumbers}{} %column numbers to be merged
\newlength{\mergewidth}{} %the cell width after merged
\newcommand{\mydata}{
    \renewcommand{\columnnumbers}{2} %column 3 and 4 will be merged
    \setlength{\mergewidth}{0.7\textwidth} %the cell width will be 0.7\textwidth
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\hmerge}[3][]{%
    \tcbitem[%
    code={\mydata},
    raster multicolumn=\columnnumbers,
    force width=\mergewidth,
    #1]#3
}%\hmerge
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tcolorbox}
    [enhanced,boxrule=3pt,left=0pt,boxsep=0pt,right=0pt,sharp corners,
    width=\textwidth]
\begin{tcbitemize}
    [raster force size=false,raster columns=4,sharp corners,
    boxrule=3pt,
    raster width=\textwidth,
    raster column skip=0pt,
    raster row skip=0pt,
    raster column 1/.style={width=0.1\textwidth},
    raster column 2/.style={width=0.2\textwidth},
    raster column 3/.style={width=0.3\textwidth},
    raster column 4/.style={width=0.4\textwidth},
    ]
    \tcbitem some text
    \tcbitem some text
    \hmerge {}{This should be "merged cell" of column number 3\&4 in row number 1. But now it is in the second row. And there is an unwanted skip between row 1 and row 2}
    \tcbitem some text
\end{tcbitemize}
\end{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}

答案1

我不知道 中的代码选项的具体工作原理,tcbitemize但此处不需要的行为是由于\newcommand的定义中的多余空格而导致的\mydata。删除多余空格即\newcommand{\mydata}{% .....和后,您将获得预期的行为\setlength{\mergewidth}{0.7\textwidth}%the cell....

相关内容