tcolorbox:如何在 tcbitemize 設定最小尺寸的光柵盒

tcolorbox:如何在 tcbitemize 設定最小尺寸的光柵盒

在此輸入影像描述

我希望光柵盒的水平寬度與內容物一樣寬(如「第 1 節」所示)。我需要做什麼?

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

答案1

在您解釋為什麼在這裡使用之前,tcbitemize您有一個解決方案,其中兩個tcboxes可以通過選項保持相等的高度equal height group

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

在此輸入影像描述

答案2

我解決了它

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

在此輸入影像描述

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

相關內容