答案1
添加keepspaces
:
\documentclass{article}
\usepackage{listings}
\begin{document}
\lstset{
basicstyle=\ttfamily,
}
\lstinline{'foo' | 'bar'}
\lstset{
morestring=[b]',
basicstyle=\ttfamily,
}
\lstinline{'foo' | 'bar'}
\lstset{
morestring=[b]',
basicstyle=\ttfamily,
keepspaces,
}
\lstinline{'foo' | 'bar'}
\end{document}