Closed muzimuzhi closed 9 months ago
In a similar situation, where text fill
option wraps the upper part in another layer of minipage
, \kvtcb@halignupper
is already reinserted right after the inner minipage
. See line 693 below:
https://github.com/T-F-S/tcolorbox/blob/6d98db4263c612279cca47efde22d1ef8404e573/tex/latex/tcolorbox/tcolorbox.sty#L687-L694
varwidth upper
should respect the alignment settings. I will correct this for the next version. Thank you!
varwidth upper
wraps the upper part in avarwidth
environment. Insidevarwidth
,\leftskip
,\rightskip
, and\parfillskip
are reset (similar tominipage
, through\@arrayparboxrestore
), hencevarwidth upper
will almost reset horizontal alignment of upper part set byhalign
or similar options.https://github.com/T-F-S/tcolorbox/blob/6d98db4263c612279cca47efde22d1ef8404e573/tex/latex/tcolorbox/tcolorbox.sty#L684-L686
Reinserting
\kvtcb@halignupper
at the beginning of thatvarwidth
environment content seems to work.One limitation is that, if alignment analogy to plain TeX is used (which sets, e.g.,
\leftskip
to a skip containingem
value), at the time of executing the two\kvtcb@halignupper
, current font size should be the same.Testing all feasible alignment values
```tex \documentclass{article} \usepackage{tcolorbox} \usepackage{varwidth} \usepackage[margin=.5in, landscape]{geometry} \usepackage{pgffor} \tcbuselibrary{hooks} \tcbset{ nobeforeafter, width=.165\linewidth, box align=top, fonttitle=\bfseries\large } \parindent=0pt \begin{document} \foreach \options in {% {adjusted title=\alignment}, {adjusted title=with \texttt{varwidth upper}, hbox, varwidth upper},% {adjusted title=alignment reinserted, hbox, varwidth upper, before upper app={\UseName{kvtcb@halignupper}}}% } {% \foreach \alignment in {% flush center,flush left,flush right,center,left,right } {% \begin{tcolorbox}[ halign/.expand once=\alignment, /utils/exec={\expandafter\pgfkeysalso\expandafter{\options}} ] This is a demonstration text for showing how line breaking works. \end{tcolorbox} } \par } \end{document} ```