列表集中的换行符

列表集中的换行符

我使用 lstset 打印代码。我的问题是,我的代码对于一页来说太长了,所以被截断了。但我只想要新页面而不是这种截断。我尝试escapechar使用参数“$”,但这不起作用。

\documentclass[11pt,a4paper]{scrartcl}
\setlength{\parindent}{0pt}

\lstset{
    basicstyle  =   \footnotesize,
    keywordstyle    = \color{keywordcolor}\bfseries,
    stringstyle     = \color{strings},
    identifierstyle = \color{black},
    commentstyle    = \color{commentgreen},
    breaklines=true,
    numbersep=-10pt,
    stepnumber=1,
    showspaces=false,
    escapechar=§,
    showstringspaces=false,
    showtabs=false,
    frame=single,  
    rulecolor=\color{black},
    tabsize=4,              
    captionpos=t,           
    breaklines=true,
    breakatwhitespace=false,
    numbers=left,
    extendedchars=\true,
    emph=[3]{href},
    emphstyle=[3]{\color{keywordcolor}},
    backgroundcolor=\color{bggrey} 
}

\begin{document}

\begin{minipage}{\textwidth} 
\lstset{language=bash,caption={My bash script},label=DescriptiveLabel}
\lstinputlisting[language=bash]{bash.sh}
\end{minipage}

\end{document}

但是这个只是在页面末尾截断了我的代码,就是这样 - 没有新页面(而且,在我的 bash.sh 中,恰好在此时有参数“$”表示中断)。这是我的问题的屏幕截图:

例子

答案1

以下是可分解列表的一些代码(部分来自tcolorbox文档)。它定义了环境codeblock

列表(可破坏)

\documentclass[11pt,a5paper,parindent=false]{scrartcl}

\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable,listings}

\lstset{
    basicstyle  =   \footnotesize,
    keywordstyle    = \color{keywordcolor}\bfseries,
    stringstyle     = \color{strings},
    identifierstyle = \color{black},
    commentstyle    = \color{commentgreen},
    breaklines=true,
    numbersep=3pt,
    stepnumber=1,
    showspaces=false,
    escapechar=§,
    showstringspaces=false,
    showtabs=false,
    rulecolor=\color{black},
    tabsize=4,              
    captionpos=t,           
    breaklines=true,
    breakatwhitespace=false,
    numbers=left,
    extendedchars=\true,
    emph=[3]{href},
    emphstyle=[3]{\color{keywordcolor}}
}

\newtcblisting[use counter=lstlisting]{codeblock}[3][]{%
        enhanced,noparskip,breakable,colback=LightGray!50,colframe=DarkSlateGray,opacitybacktitle=.8,%
        sharp corners=downhill,attach boxed title to top center = {yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},%
        boxed title style = {size=small,boxrule=0.5mm,frame code={\path[tcb fill frame] ([xshift=-4mm]frame.west)
                -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
                -- (frame.south east) -- (frame.south west) -- cycle;},
            interior code={\path[tcb fill interior] ([xshift=-2mm]interior.west)
                -- (interior.north west) -- (interior.north east)
                -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
                -- cycle;}
        },fonttitle=\bfseries,title={\strut\lstlistingname~\thelstlisting:~#2},%
        title after break={\centering\footnotesize\itshape\strut\lstlistingname~\thelstlisting~--~cont.},%
        listing only,label=#3,#1%
    }


\begin{document}
\lstset{language=bash,caption={My bash script},label=DescriptiveLabel}
\begin{codeblock}[]{Title}
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
foo(x)
\end{codeblock}
\end{document}

相关内容