TransWikia.com

One tcolorbox with alternative color in different lines

TeX - LaTeX Asked by user9047095 on February 8, 2021

This is what I want to get

origin style

This is what I already have

tcolorbox style

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
defthu@def@fontsize#1#2{%
    expandafternewcommandcsname #1endcsname[1][1.3]{%
        fontsize{#2}{##1dimexpr #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}{%
    sffamilytextcolor[rgb]{0.5,0.5,1.0}{%
        scriptsizeoldstylenums{%
            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){ttfamilyfaFileText 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}

How to draw different line in different color?

One Answer

You can use the ifodd test on the counter FancyVerbLine. Place the snippet below between makeatletter and makeatother.

renewcommand{theFancyVerbLine}{%
    ifoddc@FancyVerbLine%
        sffamilytextcolor[rgb]{0.5,0.5,1.0}{scriptsizeoldstylenums{arabic{FancyVerbLine}}}%
    else%
        sffamilytextcolor[rgb]{1.0,0.5,0.5}{scriptsizeoldstylenums{arabic{FancyVerbLine}}}%
    fi%
}

Answered by NBur on February 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP