\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbuselibrary{listings, breakable, skins}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{fontawesome5}
\usepackage[T1]{fontenc}
\usepackage[ttdefault=true]{AnonymousPro}
\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\renewcommand*\thelstnumber{\makebox[3em][r]{\ifnum\value{lstnumber}<10 0\fi\the\value{lstnumber}}}
% create non-copy numbers (source - https://tex.stackexchange.com/a/57160)
\usepackage[space=true]{accsupp}
\newcommand{\copyablespace}{\BeginAccSupp{method=hex,unicode,ActualText=00A0}\hphantom{x}\EndAccSupp{}}
\newcommand\donotcopy[1]{% line number printing mechanism
\BeginAccSupp{ActualText={}}#1\EndAccSupp{}%
}
\usepackage{caption}
\usepackage{etoolbox}
\newtcblisting[auto counter]{code}[4][]{
enhanced,
attach boxed title to bottom right={
yshift=\baselineskip + 1mm,xshift=-2.5mm
},
boxed title style={
size=small,colback=gray!50,
colframe=gray!50,
% sharp corners=downhill,
% arc=.5cm,
top=-1pt,bottom=-1pt,left=-1pt,right=-1pt
},
fonttitle=\scriptsize\color{violet}\itshape\ttfamily,
colframe=gray!20,
top=\smallskipamount,
bottom=\smallskipamount,
sharp corners=downhill,
arc=.5cm,
overlay={
\begin{tcbclipinterior}
\fill[gray!25](frame.south west)
rectangle ([xshift=5mm]frame.north west);
\end{tcbclipinterior}},
% listing remove caption=false,
listing only,
listing options={
numbers=left,
numberstyle=\ttfamily\tiny\donotcopy,
captionpos=t,
language=#3,
xleftmargin=0.5em,
basicstyle=\fontfamily{AnonymousPro}\selectfont,
keywordstyle=\bfseries\color{pblue},
stringstyle=\bfseries\itshape\color{green!40!black},
commentstyle=\bfseries\itshape\color{black!50},
showspaces=false,
showtabs=false,
breaklines=true,
columns=fullflexible,
basicstyle=\ttfamily,
literate={*}{{\char42}}1
{-}{{\char45}}1
{\ }{{\copyablespace}}1,
showstringspaces=false,
tabsize=1,
caption={#4},
emphstyle={\bfseries\color{pblue}},
},
title=#2,
#1
}
\begin{document}
\begin{code}{\faJava \ \raisebox{0.1\height}{Hello.Java}}{Java}{Porzione di codice che riporta il tipo enumerazione nel file standard.h di bitcoin core.}
String s = "Hello World";
Animation from_top = AnimationUtils.loadAnimation(this, R.anim.from_top);
imageView.setAnimation(from_top);
// change activity with fade animation
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
overridePendingTransition(R.anim.fade_in,R.anim.fade_out);
finish();
}
}, SPLASH_TIMEOUT);
\end{code}
%
\end{document}
目前看起来像...
我希望当前的标题框成为第二个可选覆盖(或其他更合适的东西?)我该怎么做?
编辑
我发现可以在覆盖层中放置多个东西,例如,将覆盖层更改为......
overlay={
\begin{tcbclipinterior}
\fill[gray!25](frame.south west)
rectangle ([xshift=5.0mm]frame.north west);
\end{tcbclipinterior}
\node[anchor=north east, draw, very thick,tcbcolframe,fill=tcbcolback] at ([xshift=-2.5mm, yshift=\baselineskip]frame.south east){(#2)};
}
我最终得到了一个看起来像的盒子......
我现在只需要帮助重新设计这个盒子。
答案1
我最终得到了我想要的格式......
\newtcblisting[auto counter]{code}[4][]{
enhanced,
top=\smallskipamount,
bottom=\smallskipamount,
sharp corners=downhill,
arc=0.5cm,
colframe=gray!20,
attach boxed title to top left={
% yshift=-\tcboxedtitleheight - \smallskipamount,
xshift=-2mm
},
boxed title style={
size=small,
colback=white,
colframe=white,
boxrule=0pt,
top=0pt,
bottom=0pt,
right=0pt,
left=0pt
},
fonttitle=\color{black},
overlay={
\begin{tcbclipinterior}
\fill[gray!25](frame.south west)
rectangle ([xshift=5.0mm]frame.north west);
\end{tcbclipinterior}
\node[inner sep=0.75mm, rounded corners=0.5mm, anchor=north east, ,fill=gray!50] at ([xshift=-2.5mm, yshift=\baselineskip]frame.south east){\scriptsize\color{violet}\itshape\ttfamily#2};
},
listing only,
listing options={
numbers=left,
numberstyle=\ttfamily\tiny\donotcopy,
captionpos=t,
abovecaptionskip=0pt,
belowcaptionskip=\medskipamount,
language=#3,
xleftmargin=0.5em,
basicstyle=\fontfamily{AnonymousPro}\selectfont,
keywordstyle=\bfseries\color{pblue},
stringstyle=\bfseries\itshape\color{green!40!black},
commentstyle=\bfseries\itshape\color{black!60},
showspaces=false,
showtabs=false,
breaklines=true,
showstringspaces=false,
tabsize=1,
emphstyle={\bfseries\color{pblue}},
columns=fullflexible,
literate={\ }{{\copyablespace}}1,
},
title=\ifx #4\empty\empty\else\ \textbf{Code Snippet~\thetcbcounter.} #4\fi,
#1
}
最终产生...