考虑 MWE
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage{listings}
\lstset{
columns=[l]flexible,
breaklines,
% fontadjust,
keepspaces,
basicstyle={\sffamily}, % \ttfamily
}
\begin{document}
\begin{lstlisting}
bla(M) = f(Q, C)
{P}
\end{lstlisting}
\end{document}
我得到了可怕的间隔
通过注释\usepackage[T1]{fontenc}
第二行是固定的(括号不同)
或者,我可以手动修复字距调整,只需滥用该literate
选项即可
\begin{lstlisting}[
literate={
{Q}{{\kern -.25ex Q\kern .25ex}}1
{M}{{\kern -.2ex M\kern .2ex}}1
{C}{{\kern -.2ex C\kern .2ex}}1
{\}}{{\kern .4ex\}}}1
{\{}{{\{\kern -.4ex}}1
}]
bla(M) = f(Q, C)
{P}
\end{lstlisting}
获取
我怎样才能彻底修复字距调整?软件包之间的沟通错误在哪里发生?
答案1
对列使用另一种设置。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage{listings}
\lstset{
columns=[l]flexible,
breaklines,
% fontadjust,
keepspaces,
basicstyle={\sffamily}, % \ttfamily
}
\begin{document}
\begin{lstlisting}
bla(M) = f(Q, C)
{P} = f
\end{lstlisting}
\lstset{columns=fullflexible}
\begin{lstlisting}
bla(M) = f(Q, C)
{P} = f
\end{lstlisting}
\lstset{columns=spaceflexible}
\begin{lstlisting}
bla(M) = f(Q, C)
{P} = f
\end{lstlisting}
\lstset{columns=fixed}
\begin{lstlisting}
bla(M) = f(Q, C)
{P} = f
\end{lstlisting}
\end{document}