tcolorbox、break 和图标仅在标题左侧

tcolorbox、break 和图标仅在标题左侧

我想使用覆盖,但只在有中断时在开头使用tcolorbox。这不起作用,如图所示。有办法解决这个问题吗?

笔记:使用overlay first并不能解决问题,因为徽标仅在第一次tcolorbox损坏时打印一次。

在此处输入图片描述

\documentclass[12pt]{article}

\usepackage[skins,many,minted,breakable]{tcolorbox}
\usepackage{fontawesome5}
\usemintedstyle{bw}
\renewcommand{\ttdefault}{pcr}

% Source: https://tex.stackexchange.com/a/124688/6880
\newcommand{\mynewminted}[3]{%
  \newminted[#1]{#2}{#3}%
  \tcbset{myminted/#1/.style={minted language=#2,minted options={#3}}}}

\mynewminted{for-coding-python}{python}{tabsize=4,fontsize=\footnotesize}

\newtcblisting[
    auto counter,
    number within=section,
    list inside=mypyg
]{coding-python}[1]{%
    listing only,
    title= #1,
    list entry={\protect\numberline{\thetcbcounter}#1},
    enhanced,
    coltitle     = black,
    colbacktitle = black!10!white,
    colback      = white,
    toptitle     = 1.5mm,
    bottomtitle  = 1.5mm,
    center title,
    breakable,
%   drop fuzzy shadow,
    myminted/for-coding-python,
    overlay first= {%
        \begin{tcbcliptitle}
            \node[
                anchor     = north west,
                inner ysep = 1.75mm,
                inner xsep = 2mm
            ] at (frame.north west){\Large\faPython};
        \end{tcbcliptitle}
    }
}

\begin{document}

\begin{coding-python}{TTT}
if i == 0:
    print("OK")

elif:
    print("KO")
\end{coding-python}

\null\vspace{12.5cm}

\begin{coding-python}{TTT}
if i == 0:
    print("OK")

elif:
    print("KO")
\end{coding-python}

\end{document}

答案1

这是解决问题的一种方法。这需要使用overlay unbroken app机器overlay first apphooks

\documentclass[12pt]{article}

\usepackage[skins,many,minted,breakable,hooks]{tcolorbox}
\usepackage{fontawesome5}
\usemintedstyle{bw}
\renewcommand{\ttdefault}{pcr}

% Source: https://tex.stackexchange.com/a/124688/6880
\newcommand{\mynewminted}[3]{%
  \newminted[#1]{#2}{#3}%
  \tcbset{myminted/#1/.style={minted language=#2,minted options={#3}}}}

\mynewminted{for-coding-python}{python}{tabsize=4,fontsize=\footnotesize}

\newtcblisting[
    auto counter,
    number within=section,
    list inside=mypyg
]{coding-python}[1]{%
    listing only,
    title        = #1,
    list entry   ={\protect\numberline{\thetcbcounter}#1},
    enhanced,
    coltitle     = black,
    colbacktitle = black!10!white,
    colback      = white,
    toptitle     = 1.5mm,
    bottomtitle  = 1.5mm,
    center title,
    breakable,
%   drop fuzzy shadow,
    myminted/for-coding-python,
    overlay unbroken app = {%
        \begin{tcbcliptitle}
            \node[
                anchor     = north west,
                inner ysep = 1.75mm,
                inner xsep = 2mm
            ] at (frame.north west){\Large\faPython};
        \end{tcbcliptitle}
    },
    overlay first app = {%
        \begin{tcbcliptitle}
            \node[
                anchor     = north west,
                inner ysep = 1.75mm,
                inner xsep = 2mm
            ] at (frame.north west){\Large\faPython};
        \end{tcbcliptitle}
    },
}

\begin{document}

\begin{coding-python}{TTT}
if i == 0:
    print("OK")

elif:
    print("KO")
\end{coding-python}

\begin{coding-python}{TTT}
if i == 0:
    print("OK")

elif:
    print("KO")
\end{coding-python}

\null\vspace{8.5cm}

\begin{coding-python}{TTT}
if i == 0:
    print("OK")

elif:
    print("KO")
\end{coding-python}

\null\vspace{14cm}

\begin{coding-python}{TTT}
if i == 0:
    print("OK")

elif:
    print("KO")
\end{coding-python}

\end{document}

这给出了以下预期输出。

在此处输入图片描述

相关内容