Seltsame Einrückung von tcblisting innerhalb von itemize

Seltsame Einrückung von tcblisting innerhalb von itemize
\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:

Bildbeschreibung hier eingeben

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 onlydie Kompilierung fehlschlägt und ich verstehe nicht, warum

[EDIT2] Tatsächlich listing onlytritt das Problem nur auf, wenn hboxeingestellt ist.

Antwort1

Wie @muzimuzhi Z bereits erklärt hat, hboxkann a keinen unteren Teil haben. Daher listing onlywird hier Folgendes benötigt.

Das Verschiebungsproblem wird dadurch verursacht, dass innerhalb einer Umgebung \@totalleftmarginerhöht wird . In einemitemizenormaltcolorbox, der Inhalt wird in ein gesetzt, minipagewobei \@totalleftmargin0 gesetzt ist. Für den hboxTyp tcolorbox gibt es derzeit keine solche Einstellung. Er verhält sich wie \fbox.

minipageIch denke jedoch, dass es sinnvoll wäre , dem Typ einige Funktionen hinzuzufügen, hboxum solche Probleme allgemein zu lösen. Der folgende Patch fügt \@parboxrestorevon minipagezu 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.

verwandte Informationen