2

enter image description here

I want the rasterboxes horizontally only as wide as the content (like in "section 1"). What do I have to do?

\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbset{sharp corners, }

\begin{document}
\section{tight works here}
\tcbox[size=tight,on line]{\Huge B}

\section{tight works not horizontally here}
\begin{tcbitemize}[
raster equal height=rows,  % needed
raster equal skip=0pt, % needed
raster columns=2,
halign=center, valign=center, 
raster force size=false, 
size=tight, % no horizontally effect
]
\tcbitem A
\tcbitem[colframe=red] \Huge B
\end{tcbitemize}

\subsection{In the result it should look like} 
\tcbox[size=tight,on line]{A\vphantom{\Huge B}}\tcbox[size=tight,on line,colframe=red]{\Huge B}
\end{document}
3
  • what do you mean? the point of a raster is to build a raster. If you want two boxes near by each other, why don't you use two \tcbbox commands? Sep 1, 2020 at 21:31
  • See edit........ Because I want a tcbitemize- environment for complex arragement tasks. Note that this is a MWE and not my true document, if that's unclear.
    – cis
    Sep 1, 2020 at 21:52
  • As i told you (tex.stackexchange.com/q/550349/1952) I think what you want is not possible. In any case, if you better explain the problem, may be we can find some other alternatives.
    – Ignasi
    Sep 2, 2020 at 10:20

2 Answers 2

2

Until you explain why to use tcbitemize here you have a solution with two tcboxes which keep equal height with equal height group option.

\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbset{sharp corners, }

\newtcbox{\mybox}[1][]{size=tight, on line, equal height group=mygroup, valign=bottom, #1}

\begin{document}
\section{tight works here}
\tcbox[size=tight, on line]{\Huge B}

\section{tight works not horizontally here}
\mybox{A}\mybox[colframe=red]{\Huge B}


\subsection{In the result it should look like} 
\tcbox[size=tight,on line]{A\vphantom{\Huge B}}\tcbox[size=tight,on line,colframe=red]{\Huge B}
\end{document}

enter image description here

2
  • Could you apply it to this code? tex.stackexchange.com/a/560909/67761
    – O0123
    Sep 2, 2020 at 18:51
  • @VincentMiaEdieVerheyen Better not. It is a possibility to create the desired image here, but not a solution in the sense of the task. I have given a solution to this myself.
    – cis
    Sep 2, 2020 at 19:09
1

I solved it with

\def\LeftContent{A}
\pgfmathsetlengthmacro\LeftWidth{width("\LeftContent")}

enter image description here

\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbset{sharp corners, }

\begin{document}

\section{tight works here}
\tcbox[size=tight,on line]{\Huge B}

\section{tight works not horizontally here}
\def\LeftContent{\includegraphics[scale=0.1]{example-image.jpg}}%test
\def\LeftContent{A}
\pgfmathsetlengthmacro\LeftWidth{width("\LeftContent")}
\def\RightContent{\Huge B}
\pgfmathsetlengthmacro\RightWidth{width("\RightContent")}
LeftWidth =\LeftWidth, RightWidth =\RightWidth

\begin{tcbitemize}[%NoGaps,
raster equal height=rows,  % needed
raster equal skip=0pt, % needed
raster columns=2,
halign=center, valign=center, 
raster force size=false, % <---
size=tight, % no horizontally effect
]
\tcbitem[size=tight, width=\LeftWidth, valign=bottom] \LeftContent
\tcbitem[colframe=red, width=\RightWidth] \RightContent
\end{tcbitemize}

\subsection{In the result it should look like} 
\tcbox[size=tight,on line]{A\vphantom{\Huge B}}\tcbox[size=tight,on line,colframe=red]{\Huge B}
\end{document}

You must log in to answer this question.

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