1

I want to combine the column 3&4 of the first row in a tcolorbox tcbitemize envierement. Please see my code for details: But the typeset is not what I want. I think something is wrong in using the option "code=", but I really don't know the cause. Anyone can help me with this issue? Thanks in advance![enter image description here]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}
5
  • I don't know the exact working of code option in tcbitemize but here the unwanted behavior comes because of the extra spaces in the \newcommand definition of \mydata . You get the expected behavior after removing the extra spaces i.e. \newcommand{\mydata}{% ..... and \setlength{\mergewidth}{0.7\textwidth}%the cell.... .
    – Adarsh
    Commented Aug 12, 2017 at 2:56
  • Thank you, Adarsh. You provide with a good solution. Still, the marco \mydata does not contain any command that leads to typeset, why the symbol % must be used?
    – lyl
    Commented Aug 12, 2017 at 9:52
  • Loosely speaking line breaks (not terminated by %) inside \newcommand are not ignored and they are treated as space. Some more precise answers are here . Also, code option in \tcbitem doesn't ignore spaces (blank lines). I cannot explain how as I don't know how it works. The combination of these two result in the behavior that you saw in your example.
    – Adarsh
    Commented Aug 12, 2017 at 15:33
  • @Adarsh: Providing an answer?
    – user31729
    Commented Sep 6, 2017 at 16:08
  • @ChristianHupfer I added my first comment as an answer.
    – Adarsh
    Commented Sep 7, 2017 at 1:09

1 Answer 1

2

I don't know the exact working of code option in tcbitemize but here the unwanted behavior comes because of the extra spaces in the \newcommand definition of \mydata . You get the expected behavior after removing the extra spaces i.e. \newcommand{\mydata}{% ..... and \setlength{\mergewidth}{0.7\textwidth}%the cell.... .

0

You must log in to answer this question.

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