1

I'd like to know if it's possible to define a kind of column weight in tcolorbox, so say for example "The first column must use 20%, the second column must use 80%".

If possible I'd like to be able to use \tcbtextwidth inside the box, like in the enclosed MWE, and if possible I'd like to avoid to multicolumns=2, because if I want a precise pourcentage, I need to create lot's of very small columns, and it does not seem very proper...

Thank you!

MWE

\documentclass{article}
\usepackage[raster,most]{tcolorbox}
\begin{document}
\begin{minipage}{\linewidth}%
    \begin{tcbitemize}[raster columns=2,
        raster equal height]
        \tcbitem[] % Should take 20%
        \includegraphics[width=\tcbtextwidth]{example-image-a}
        \tcbitem[] % Should take 80%
        \includegraphics[width=\tcbtextwidth]{example-image-b}
    \end{tcbitemize}%
\end{minipage}
\end{document}

-- EDIT -- I found a pseudo solution, using raster force size=false in the tcbitemize, and in the tcbitem I use width=\linewidth/2, but it does not take into account the space between the columns, and I always have a bad alignment... And also I'm not sure how to convert it in text height to do the same thing for rows.

2
  • Do you think your solution meets your own request or you are looking for something more?
    – Cragfelt
    Nov 21, 2017 at 22:42
  • @Cragfelt I edited my answer, I just saw that the space between the column is not taken into account, so at the end the boxes goes outside of the initial box. So I'm still looking for a solution.
    – tobiasBora
    Nov 21, 2017 at 22:54

2 Answers 2

3

If desired proportions allow it, you can use a raster multicolumn.

In this case, the left column uses 20% and right 80%. You can define a raster with 5 columns and fill it with one column on the left and a raster multicolumn which occupies 4 columns on the right.

\documentclass{article}
\usepackage[raster,most]{tcolorbox}
\begin{document}
%\begin{minipage}{\linewidth}%
    \begin{tcbitemize}[raster columns=5,
        raster equal height]
        \tcbitem[] % Should take 20%
        \includegraphics[width=\tcbtextwidth]{example-image-a}
        \tcbitem[raster multicolumn=4] % Should take 80%
        \includegraphics[width=\tcbtextwidth]{example-image-b}
    \end{tcbitemize}%
%\end{minipage}
\end{document}

enter image description here

2
  • This is a nice trick. Why not just raster columns = 100, and from now on whole percents work without any problems. :)
    – cis
    Jul 13, 2020 at 16:39
  • @cis Please taka a look at this answer tex.stackexchange.com/a/553481/1952, I think it's a better solution for irregular distributions.
    – Ignasi
    Jul 14, 2020 at 7:38
2

The various lengths involved here are stored in \kvtcb@raster... macros which must be evaluated first and then be reused in a special style setting for column 1 and column 2 with raster column 1/.style=...

The macro \getremainingboxwidth{0.2} will calculate the remaining width reserving 20% for the relevant column. The column skip is taken into account for one skip.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{showframe}
\begin{document}
\makeatletter
\newcommand{\getremainingboxwidth}[1]{%
  #1\dimexpr\kvtcb@raster@width-\kvtcb@raster@skip@left-\kvtcb@raster@skip@right-\kvtcb@raster@xskip
}
%\begin{minipage}{\linewidth}%
    \begin{tcbitemize}[
      raster columns=2,
      raster force size=false,
      raster column skip=20pt,% Just for testing
        raster equal height, 
        raster column 2/.style={width=\getremainingboxwidth{0.8}},
        raster column 1/.style={width=\getremainingboxwidth{0.2}}]
        \tcbitem[] % Should take 20%
        \includegraphics[width=\tcbtextwidth]{example-image-a}
        \tcbitem[] % Should take 80%
        \includegraphics[width=\tcbtextwidth]{example-image-b}
    \end{tcbitemize}%
%\end{minipage}
\end{document}

enter image description here

1
  • I will edit this answer later on
    – user31729
    Nov 22, 2017 at 4:49

You must log in to answer this question.

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