我已经定义了列表。如何创建列表列表?我的意思是类似于\listoftables
。谢谢
\documentclass[12pt,a4paper]{report}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\tcbuselibrary{listings}
\newtcbinputlisting[auto counter]{\mylisting}[2][]{listing file={#2},title=Listing,colback=white,colframe=gray!75!black,fonttitle=\bfseries,listing only,breakable,title=Soubor \thetcbcounter: #1}
\renewcommand{\lstlistingname}{Soubor}
\newcommand{\listingsfont}{\ttfamily}
\begin{document}
\lstinputlisting{code.txt}
\end{document}
答案1
这里是tcolorbox
生成“某物”列表的方法,这里是带有设置list type=...
和的列表列表list inside
。
默认使用title=...
来插入条目的名称。
\tbclistof[\chapter*]{lol}{\lstlistingname}
是tcolorbox
- 的说法\listof....
\documentclass[12pt,a4paper]{report}
\usepackage{xcolor}
%\usepackage{listings}
\usepackage{caption}
\usepackage[most]{tcolorbox}
\newtcbinputlisting[auto counter,list inside=lol,list type={lstlisting}]{\mylisting}[2][]{%
listing file={#2},
title=Listing,
colback=white,
colframe=gray!75!black,
fonttitle=\bfseries,
listing only,
breakable,
title=Soubor \thetcbcounter: #2,
#1
}
\renewcommand{\lstlistingname}{Soubor}
\newcommand{\listingsfont}{\ttfamily}
\begin{document}
\tcblistof[\chapter*]{lol}{\lstlistingname}
\clearpage
\mylisting{helloworldexample.c}
\end{document}
文件helloworldexample.c
如下
#include<stdio.h>
int main(int argc,char **argv)
{
printf("Hello World!\n");
return(0);
}
更新
\documentclass[12pt,a4paper]{report}
\usepackage{xcolor}
%\usepackage{listings}
\usepackage{caption}
\usepackage[most]{tcolorbox}
\newtcbinputlisting[auto counter,list inside=lol,list type={lstlisting}]{\mylisting}[3][]{%
listing file={#3},
title=Listing,
colback=white,
colframe=gray!75!black,
fonttitle=\bfseries,
listing only,
breakable,
title={Soubor \thetcbcounter: #2},
#1
}
\renewcommand{\lstlistingname}{Soubor}
\newcommand{\listingsfont}{\ttfamily}
\begin{document}
\tcblistof[\chapter*]{lol}{\lstlistingname}
\clearpage
\mylisting{Some caption}{helloworldexample.c}
\end{document}
答案2
您可以使用\lstlistoflisting
该包引入的listings
:
\documentclass[12pt,a4paper]{report}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\tcbuselibrary{listings}
\newtcbinputlisting[auto counter]{\mylisting}[2][]{listing file={#2},title=Listing,colback=white,colframe=gray!75!black,fonttitle=\bfseries,listing only,breakable,title=Soubor \thetcbcounter: #1}
\renewcommand{\lstlistingname}{Soubor}
\newcommand{\listingsfont}{\ttfamily}
\begin{document}
\lstlistoflistings
\begin{lstlisting}[caption=test]
content of the listing
\end{lstlisting}
\end{document}
来自清单手册:
\lstlistoflistings
打印列表。每个条目的优先级依次为简短标题、标题、文件名或列表名称,[...]
如果你想将列表的标题从“列表”更改为其他内容,你可以使用\renewcommand{\lstlistlistingname}{<new title>}