为什么\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}