- 效果图

- 源代码
\documentclass{article}
\newcounter{commentCount}
\newcounter{filePrg}
\newcounter{inputPrg}
\usepackage{geometry}
\geometry{paper=letterpaper,margin=2cm}
\usepackage{ifthen}
\usepackage{fontawesome}
\usepackage[dvipsnames]{xcolor}
\usepackage{tabularx}
\newcolumntype{\CeX}{>{\centering\let\newline\\\arraybackslash}X}%
\newcommand{\TwoSymbolsAndText}[3]{%
\begin{tabularx}{\textwidth}{c\CeX c}%
#1 & #2 & #3
\end{tabularx}%
}
\usepackage{minted}
\usepackage[many]{tcolorbox}
\tcbuselibrary{listings}
\tcbuselibrary{minted}
\newtcolorbox[use counter=commentCount, number format=\arabic]{commentBox}[2]{
size=title,
arc=1.5mm,
breakable,
enhanced jigsaw,
colframe=Black,
coltitle=White,
boxrule=0.5mm,
colback=White,
coltext=Black,
title=\TwoSymbolsAndText{\faCheck}{%
\textbf{Comment \thetcbcounter}\ifthenelse{\equal{#1}{}}{}{\textbf{:} \textit{#1}}%
}{\faCheck},
label=comment:#2,
}
\newtcbinputlisting[use counter=filePrg, number format=\arabic]{\codeFromFile}[7]{%
listing engine=minted,
minted language=#1,
minted style=trac,
listing file={#2},
minted options={autogobble,linenos,breaklines,firstline=#5,lastline=#6,highlightlines=#7},
listing only,
size=title,
arc=1.5mm,
breakable,
enhanced jigsaw,
colframe=blue,
coltitle=White,
boxrule=0.5mm,
colback=white,
coltext=Black,
title=\TwoSymbolsAndText{\faCode}{%
\textbf{File program \thetcbcounter}\ifthenelse{\equal{#3}{}}{}{\textbf{:} \textit{#3}}%
}{\faCode},
label=filePrg:#4
}
\newtcblisting[use counter=inputPrg, number format=\arabic]{codeInput}[3]{
listing engine=minted,
minted language=#1,
minted options={autogobble,linenos,breaklines},
listing only,
size=title,
arc=1.5mm,
breakable,
enhanced jigsaw,
colframe=brown,
coltitle=White,
boxrule=0.5mm,
colback=white,
coltext=Black,
title=\TwoSymbolsAndText{\faCode}{%
\textbf{Input program \thetcbcounter}\ifthenelse{\equal{#2}{}}{}{\textbf{:} \textit{#2}}%
}{\faCode},
label=inputPrg:#3
}
\usepackage{cleveref}
\crefname{commentCount}{comment}{comments}
\crefname{filePrg}{file program}{file programs}
\crefname{inputPrg}{input program}{input programs}
% * Begin document
\begin{document}
% * [1] Comment Box
\begin{commentBox}{My first comment}{first}
My first comment here! \faTree
\end{commentBox}
% * [2] Code Input
\begin{codeInput}{c}{A welcome program.}{code01}
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
\end{codeInput}
% * [3] Code from file
\codeFromFile{python}{pytest.py}{Another welcome program.}{code01}{1}{25}{{5,8,11}}
% * [4] Cross reference
See \cref{comment:first} for details. Also, look for \cref{inputPrg:code01} and \cref{filePrg:code01} for further assistance.
% * End document
\end{document}
- 在minted options中设置显示行号及高亮
minted options={autogobble,linenos,breaklines,firstline=#5,lastline=#6,highlightlines=#7},