一个 tcolorbox,在不同行中有替代颜色

一个 tcolorbox,在不同行中有替代颜色

这就是我想要得到的

起源风格

这就是我已经拥有的

tcolorbox 样式

\documentclass{article}
\usepackage{geometry}
\geometry{left=2.5cm,right=2cm,top=2.5cm,bottom=2.5cm}
\usepackage{fontawesome}
\usepackage{varwidth}
% tcolorbox
\usepackage[dvipsnames, svgnames]{xcolor}
\definecolor{mpurple}{RGB}{48,10,36}
\definecolor{mgray}{RGB}{70,72,67}
\definecolor{ogray}{RGB}{148,147,141}
\definecolor{oorange}{RGB}{233,101,56}
\definecolor{termimal}{RGB}{80,78,70}
\definecolor{linux}{RGB}{0,39,51}
\definecolor{cvgrayc}{RGB}{247,247,247}
\definecolor{cvgray}{RGB}{220,220,220}
\definecolor{cvgrayb}{RGB}{153,153,153}
\definecolor{cvblue}{RGB}{223,238,255}

\usepackage[minted]{tcolorbox}
\tcbuselibrary{skins, listings, xparse, breakable}

%% fontsize definition
\makeatletter
\def\thu@def@fontsize#1#2{%
    \expandafter\newcommand\csname #1\endcsname[1][1.3]{%
        \fontsize{#2}{##1\dimexpr #2}\selectfont%
    }%
}
\thu@def@fontsize{chuhao}{42bp}
\thu@def@fontsize{xiaochu}{36bp}
\thu@def@fontsize{yihao}{26bp}
\thu@def@fontsize{xiaoyi}{24bp}
\thu@def@fontsize{erhao}{22bp}
\thu@def@fontsize{xiaoer}{18bp}
\thu@def@fontsize{sanhao}{16bp}
\thu@def@fontsize{xiaosan}{15bp}
\thu@def@fontsize{sihao}{14bp}
\thu@def@fontsize{banxiaosi}{13bp}
\thu@def@fontsize{xiaosi}{12bp}
\thu@def@fontsize{dawu}{11bp}
\thu@def@fontsize{wuhao}{10.5bp}
\thu@def@fontsize{xiaowu}{9bp}
\thu@def@fontsize{liuhao}{7.5bp}
\thu@def@fontsize{xiaoliu}{6.5bp}
\thu@def@fontsize{qihao}{5.5bp}
\thu@def@fontsize{bahao}{5bp}
\makeatother

% redefine the line number font
\renewcommand{\theFancyVerbLine}{%
    \sffamily\textcolor[rgb]{0.5,0.5,1.0}{%
        \scriptsize\oldstylenums{%
            \arabic{FancyVerbLine}%
        }%
    }%
}

\tcbset{skin=enhanced,
    cv/.style={
        boxrule=0.4mm,
        pad after break=-1.5ex,
        breakable,drop shadow,listing engine=minted,minted style=xcode,
        minted options={mathescape,breaklines,fontsize=\wuhao,linenos,
            numbersep=3mm},attach boxed title to top,
        colback=blue!5!white,colframe=blue!75!black,
        left=6mm,right=3mm,enhanced,
        colframe=tcbcol@back!60!black,colback=tcbcol@back!30!white,colbacktitle=cvgray,
        fonttitle=\ttfamily,coltitle=black,
         overlay broken = {\begin{tcbclipinterior}
                        \fill[cvblue] (frame.south west) rectangle ([xshift=5mm]frame.north west);
                    \end{tcbclipinterior}},
        underlay boxed title = {\begin{tcbclipinterior}\fill[cvblue] (frame.south west) rectangle ([xshift=5mm,yshift=0mm]frame.north west);\end{tcbclipinterior}}    
}}
\newcounter{cvcounter}
\DeclareTCBListing[use counter=cvcounter]{langCVOne}{ O{python} o o m }{%
    listing only,
    cv,
    minted language=#1,
    title={Program List \thecvcounter:~#4},%\thetcbcounter
    label = #2,
    overlay unbroken and first ={\begin{tcbclipinterior}
                            \node[inner sep=0pt,anchor=north east,yshift=-3pt,xshift=-5pt,text=cvgrayb] at (frame.north east){\ttfamily\faFileText\ \faCode\ \faCodeFork\ \faCopy\ \faExternalLink\ \IfNoValueTF{#3}{\MakeUppercase#1}{#3}};\end{tcbclipinterior}}}

\begin{document}
\begin{langCVOne}{FAST algorithm}
import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('7.jpg',0)

# Initiate FAST object with default values
fast = cv2.FastFeatureDetector_create(threshold=25)

# find and draw the keypoints
kp = fast.detect(img,None)
img2 = cv2.drawKeypoints(img, kp, None,color=(255,0,0))

print("Threshold: ", fast.getThreshold())
print("nonmaxSuppression: ", fast.getNonmaxSuppression())
print("neighborhood: ", fast.getType())
print("Total Keypoints with nonmaxSuppression: ", len(kp))

cv2.imwrite('fast_true.png',img2)

# Disable nonmaxSuppression
fast.setNonmaxSuppression(0)
kp = fast.detect(img,None)

print ("Total Keypoints without nonmaxSuppression: ", len(kp))

img3 = cv2.drawKeypoints(img, kp, None, color=(255,0,0))

cv2.imwrite('fast_false.png',img3)
\end{langCVOne}
\end{document}

如何用不同的颜色绘制不同的线条?

答案1

您可以\ifodd在柜台上使用测试FancyVerbLine。将下面的代码片段放在\makeatletter和之间\makeatother

\renewcommand{\theFancyVerbLine}{%
    \ifodd\c@FancyVerbLine%
        \sffamily\textcolor[rgb]{0.5,0.5,1.0}{\scriptsize\oldstylenums{\arabic{FancyVerbLine}}}%
    \else%
        \sffamily\textcolor[rgb]{1.0,0.5,0.5}{\scriptsize\oldstylenums{\arabic{FancyVerbLine}}}%
    \fi%
}

相关内容