请问,我应该如何设置列表框,例如底部的线(不是直线)和侧面的虚线。谢谢
\documentclass[12pt,a4paper]{report}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage[a-2u]{pdfx}
\usepackage[czech]{babel}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{%
\parbox{\textwidth}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}\vskip-4pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
\lstset{frame=lrb,xleftmargin=\fboxsep,xrightmargin=-\fboxsep}
\renewcommand{\lstlistingname}{Soubor}
\newcommand{\listingsfont}{\ttfamily}
\begin{document}
\lstinputlisting[caption=\textbf{Vstupní soubor \texttt{.SPD} programu SPEL (pro první čáru)}, label=c_1, basicstyle=\footnotesize\linespread{0.2}\listingsfont]{spd.txt}
\end{document}
我很感谢@BambOo 的帮助和他的代码。现在我在编译此代码时遇到了问题。可能是软件包有问题 - 缺少everyshi.sty。我在 MiKTex 控制台中找不到它。我使用 TexMaker。非常感谢。
\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}
\renewcommand{\lstlistingname}{Soubor}
\newcommand{\listingsfont}{\ttfamily}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\newtcbinputlisting[]{\mylisting}[2][]{listing file={#2},title=Listing,colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,listing only,#1}
\begin{document}
\mylisting[]{spd.txt}
\end{document}
答案1
如果您想要对列表图形选项进行精细的定义,您可以使用 nicetcolorbox
包,它有一个listings
定义\newtcbinputlisting
宏的库,请查看tcolorbox
第 298 页第 15 节的文档。
\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{%
\parbox{\textwidth}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}\vskip-4pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
\lstset{xleftmargin=\fboxsep,xrightmargin=-\fboxsep}
\renewcommand{\lstlistingname}{Soubor}
\newcommand{\listingsfont}{\ttfamily}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\newtcbinputlisting[]{\mylisting}[2][]{listing file={#2},title=Listing,colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,listing only,#1}
\begin{filecontents*}{spd.txt}
HJD-2400000 RV weight ...
55836.5692 -13.1464 1.00 ...
\end{filecontents*}
\begin{document}
\lstinputlisting[caption=\textbf{Vstupní soubor \texttt{.SPD} programu SPEL (pro první čáru)}, label=c_1, basicstyle=\footnotesize\linespread{0.2}\listingsfont]{spd.txt}
\mylisting[]{spd.txt}
\end{document}
编辑
要授权打破列表,请将其添加\tcbuselibrary{breakable}
到您的序言中,然后\usepackage{tcolorbox}
添加breakable
\newtcbinputlisting[]{\mylisting}[2][]{...
编辑
最终版本包括breakable
和caption
定义。
\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{%
\parbox{\textwidth}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}\vskip-4pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
\lstset{xleftmargin=\fboxsep,xrightmargin=-\fboxsep}
\renewcommand{\lstlistingname}{Soubor}
\newcommand{\listingsfont}{\ttfamily}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\tcbuselibrary{breakable}
\newtcbinputlisting[auto counter] % <-- to activate the counter
{\mylisting}[2][]{
listing file={#2}, % <-- argument in {} of \mylisting is the filename
title=Listing,colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,listing only,
breakable, % <-- table can span multiple pages
title={Soubor \thetcbcounter: #1}} % <-- argument in [] of \mylisting is the title with counter
\begin{filecontents*}{spd.txt}
HJD-2400000 RV weight ...
55836.5692 -13.1464 1.00 ...
\end{filecontents*}
\begin{document}
\mylisting[SPD]{spd.txt}
\end{document}