
\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}
이상한 동작을 출력합니다.
이것을 극복하는 것이 가능합니까, 아니면 지금 하고 있는 일, 즉 내 상자를 itemize 외부에 두는 일을 해야 합니까?
[EDIT1] 제거하면 listing only
컴파일이 실패하고 그 이유를 이해할 수 없습니다.
[EDIT2] 실제로 문제는 설정된 listing only
경우에만 나타납니다 .hbox
답변1
@muzimuzhi Z alraedy가 설명했듯이 a는 hbox
아래쪽 부분을 가질 수 없습니다. 그러므로 listing only
여기에 필요합니다.
교대 문제는 환경 \@totalleftmargin
내부에서 증가하여 발생합니다 itemize
. 안에정상tcolorbox에서 콘텐츠는 0으로 설정된 minipage
곳에 저장됩니다. tcolorbox 유형 \@totalleftmargin
의 경우 hbox
현재 그러한 설정이 없습니다. 그것은 다음과 같이 동작합니다 \fbox
.
하지만 이러한 문제를 일반적인 방식으로 해결하려면 minipage
해당 유형에 몇 가지 기능을 추가하는 것이 유용할 것이라고 생각합니다 . hbox
다음 패치는 에서 \@parboxrestore
에 추가됩니다 .minipage
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%
}
전체 예는 다음과 같습니다.
\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}
중요한 문제가 발생하지 않으면 이 패치를 다음 tcolorbox 버전에 추가할 예정입니다.