使用 \lstinline 换行

使用 \lstinline 换行

为什么\lstinline不能像 那样正确换行\begin{lstlisting}? 使用 时,文本超出了文档边框\lstinline

谢谢你!

\documentclass{scrreprt}

\usepackage{listings}

\lstset
{
    breaklines=true,
    breakatwhitespace=true,
    frame=lines,
    basicstyle=\ttfamily,
}

\begin{document}

    \begin{lstlisting}            
someverylongcode, whichneedssomelinebreak hereandthere, becauseotherwiseitwouldgooverthedocumentborder
    \end{lstlisting}

\lstinline[language=C]!someverylongcode, whichneedssomelinebreak hereandthere, becauseotherwiseitwouldgooverthedocumentborder!

\end{document}

答案1

\lstinline可以换行,但不会拉伸空格,因此它只能在\raggedright\sloppy上下文中起作用:

\documentclass{scrreprt}

\usepackage{listings}

\lstset
{
    breaklines=true,
}

\begin{document}

\lstinline[language=C]!someverylongcode, whichneedssomelinebreak hereandthere, becauseotherwiseitwouldgooverthedocumentborder!

\raggedright
\lstinline[language=C]!someverylongcode, whichneedssomelinebreak hereandthere, becauseotherwiseitwouldgooverthedocumentborder!

\end{document}

在此处输入图片描述

相关内容