
\documentclass{article}
\usepackage[listings]{tcolorbox}
\newtcblisting{mylisting}{
listing only,
size=fbox,
}
\newtcblisting{mylistingb}{
listing only,
size=fbox,
hbox,
}
\begin{document}
\begin{itemize}
\item
\begin{mylisting}
blah
\end{mylisting}
\item
\begin{mylistingb}
blah
\end{mylistingb}
\end{itemize}
\end{document}
Gibt ein seltsames Verhalten aus:
Ist es möglich, dies zu umgehen, oder sollte ich es so machen wie jetzt, nämlich meine Kartons außerhalb der Einzelaufstellung platzieren?
[EDIT1] Es sollte beachtet werden, dass das Entfernen listing only
die Kompilierung fehlschlägt und ich verstehe nicht, warum
[EDIT2] Tatsächlich listing only
tritt das Problem nur auf, wenn hbox
eingestellt ist.
Antwort1
Wie @muzimuzhi Z bereits erklärt hat, hbox
kann a keinen unteren Teil haben. Daher listing only
wird hier Folgendes benötigt.
Das Verschiebungsproblem wird dadurch verursacht, dass innerhalb einer Umgebung \@totalleftmargin
erhöht wird . In einemitemize
normaltcolorbox, der Inhalt wird in ein gesetzt, minipage
wobei \@totalleftmargin
0 gesetzt ist. Für den hbox
Typ tcolorbox gibt es derzeit keine solche Einstellung. Er verhält sich wie \fbox
.
minipage
Ich denke jedoch, dass es sinnvoll wäre , dem Typ einige Funktionen hinzuzufügen, hbox
um solche Probleme allgemein zu lösen. Der folgende Patch fügt \@parboxrestore
von minipage
zu hinzu hbox
:
\long\def\tcbox@inner@hbox#1{%
\tcbset{breakable@false,sidebyside=false}%
\tcb@set@@phantom%
\sbox\tcb@upperbox{\tcb@embed@tcbox{%
\csname tcb@parbox@use@\kvtcb@parbox\endcsname%
\@parboxrestore%
\color{tcbcolupper}\kvtcb@fontupper\kvtcb@halignupper\tcb@insert@before@upper#1\tcb@insert@after@upper}}%
\tcbdimto\tcb@val@raisebase{\the\dimexpr\dp\tcb@upperbox+\kvtcb@bottom+\kvtcb@boxsep+\kvtcb@bottom@rule@stand+\kvtcb@bbbottom@stand\relax}%
\tcbdimto\kvtcb@width{\wd\tcb@upperbox+\kvtcb@left@rule+\kvtcb@leftupper+\kvtcb@boxsep*2+\kvtcb@rightupper+\kvtcb@right@rule}%
\tcb@hasLowerfalse%
\tcb@set@@title%
\tcb@set@@dimensions%
\tcb@draw@color@box%
}
Das vollständige Beispiel ist
\documentclass{article}
\usepackage[listings]{tcolorbox}
% patch
\makeatletter
\long\def\tcbox@inner@hbox#1{%
\tcbset{breakable@false,sidebyside=false}%
\tcb@set@@phantom%
\sbox\tcb@upperbox{\tcb@embed@tcbox{%
\csname tcb@parbox@use@\kvtcb@parbox\endcsname%
\@parboxrestore%
\color{tcbcolupper}\kvtcb@fontupper\kvtcb@halignupper\tcb@insert@before@upper#1\tcb@insert@after@upper}}%
\tcbdimto\tcb@val@raisebase{\the\dimexpr\dp\tcb@upperbox+\kvtcb@bottom+\kvtcb@boxsep+\kvtcb@bottom@rule@stand+\kvtcb@bbbottom@stand\relax}%
\tcbdimto\kvtcb@width{\wd\tcb@upperbox+\kvtcb@left@rule+\kvtcb@leftupper+\kvtcb@boxsep*2+\kvtcb@rightupper+\kvtcb@right@rule}%
\tcb@hasLowerfalse%
\tcb@set@@title%
\tcb@set@@dimensions%
\tcb@draw@color@box%
}
\makeatother
\newtcblisting{mylisting}{
listing only,
size=fbox,
}
\newtcblisting{mylistingb}{
listing only,
size=fbox,
hbox,
}
\begin{document}
\begin{itemize}
\item
\begin{mylisting}
blah
\end{mylisting}
\item
\begin{mylistingb}
blah
\end{mylistingb}
\end{itemize}
\end{document}
Wenn nichts Kritisches auftritt, beabsichtige ich, diesen Patch der nächsten tcolorbox-Version hinzuzufügen.