![如何在列表中插入美观的波浪号?](https://linux22.com/image/236821/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%88%97%E8%A1%A8%E4%B8%AD%E6%8F%92%E5%85%A5%E7%BE%8E%E8%A7%82%E7%9A%84%E6%B3%A2%E6%B5%AA%E5%8F%B7%EF%BC%9F.png)
如何在 中插入一个居中的波浪符号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}