如何在 中插入一个居中的波浪符号lstlisting
?我找到了另一个关于波浪符号但我无法应用它,因为那里描述的方法只在lstlisting
按lstlisting
字面显示所有文本之外有效。有什么想法吗?
这是目前波浪号在我的文档中的样子 - 它位于字体的最顶部,我希望它位于中间(像~
这样)。
以下是该片段的 LaTeX:
\section{Remove duplicate, consecutive lines (emulate "uniq")}
\begin{lstlisting}
awk 'a !~ $0; { a = $0 }'
\end{lstlisting}
Variables in Awk don't need to be initialized or declared before they are being used.
答案1
\documentclass{minimal}
\usepackage{listings}
\lstset{
literate={~} {$\sim$}{1}
}
\begin{document}
\begin{lstlisting}
awk 'a !~ $0; { a = $0 }'
\end{lstlisting}
Variables in Awk don't need to be initialized or declared before they are being used.
\end{document}
答案2
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[scaled=0.85]{beramono}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[basicstyle=\ttfamily]
awk 'a !~ $0; { a = $0 }'
\end{lstlisting}
\end{document}
答案3
上述提示也适用于 T1 编码和courier
包:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{courier}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[basicstyle=\ttfamily]
awk 'a !~ $0; { a = $0 }'
\end{lstlisting}
\end{document}