我有一个精心设计的配置:
\renewcommand\theFancyVerbLine{\small\arabic{FancyVerbLine}}
\newminted{cpp}{
linenos=true,
xleftmargin=2em,
breaklines,
fontsize=\small,
}
还有一个 tcolorbox 配置:
\newtcolorbox{box-note}{
sharpish corners, % better drop shadow
boxrule = 0pt,
toprule = 4.5pt, % top rule weight
enhanced,
drop fuzzy shadow = black!35,
fontupper=\sffamily
}
一起使用它们意味着我必须写:
\begin{box-note}
\begin{cppcode}
#include <iostream>
int main() {
std::cout << "Hello World!\n";
}
\end{cppcode}
\end{box-note}
这个功能很好用,看起来也很棒,但是我每次都要重复这两个环境,这很烦人。有没有办法把这两个环境结合起来?
我试过了\newenvironment
但是铸币似乎爆炸了。
答案1
tcolorbox
有内置minted
支持。您可以这样做:
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins,minted}
\renewcommand\theFancyVerbLine{\small\arabic{FancyVerbLine}}
\newtcblisting{boxcppnote}{
sharpish corners, % better drop shadow
boxrule = 0pt,
toprule = 4.5pt, % top rule weight
enhanced,
drop fuzzy shadow = black!35,
fontupper=\sffamily,
listing only,
minted language=cpp,
minted options={
linenos=true,
xleftmargin=2em,
breaklines,
fontsize=\small,}
}
\begin{document}
\begin{boxcppnote}
#include <iostream>
int main() {
std::cout << "Hello World!\n";
}
\end{boxcppnote}
\end{document}