内联代码列表延伸到右边距

内联代码列表延伸到右边距

我正在尝试使用列表包。但是,内联代码块跨越了几行,因此listings必须在代码中插入几个换行符。到目前为止,一切都按计划进行。

但是,listings似乎错了\textwidth,或者至少它插入换行符太晚了。在我看来,最好牺牲段落的对齐,使某些行太短,而不是让某些行溢出到右边距。

<in在下面的例子中,我更希望看到和之间的线断开TArgument。我该怎么做?

不良列表换行

\documentclass[a4paper]{article}
\usepackage{color,listings}

\setlength{\textwidth}{120mm}

\lstset{language=[Sharp]C,
    showspaces=false,
    showtabs=false,
    linewidth=\textwidth{},
    breaklines=true,
    showstringspaces=false,
    breakatwhitespace=false,
    escapeinside={(*@}{@*)},
    commentstyle=\color{green},
    keywordstyle=\color{blue},
    stringstyle=\color{red},
    basicstyle=\ttfamily
}

\begin{document}

By writing this sentence, we will get a feeling for the textwidth of this document.
Then we will talk about some type definition:
\lstinline$delegate TResult here.we.have.a.looooong.typename.containing.some.Calcualtion<in TArgument, out TResult>(TArgument argument)$.
Now that that's out of the way, we can continue writing about other nonsensical subjects which helps reveal the textwidth once again.

\end{document}

答案1

使用

\begin{sloppypar}
By writing this sentence, we will get a feeling for the textwidth of this document.
Then we will talk about some type definition:
\lstinline$delegate TResult here.we.have.a.looooong.typename.containing.some.Calcualtion<in TArgument, out TResult>(TArgument argument)$.
Now that that's out of the way, we can continue writing about other nonsensical subjects which helps reveal the textwidth once again.
\end{sloppypar}

不过,我更愿意使用这个选项breakatwhitespace

相关内容