\documentclass[a4paper]{report} \usepackage{listings} \lstset{basicstyle=\ttfamily} \begin{document} This is lstlisting: \begin{lstlisting} : paxos.learn ( addr n v -- Ethernet packet ) 2 paxos.pack32 ( addr n v -- addr payload ) paxos.eth_type.learn ( addr payload -- addr payload ethtype ) swap paxos.eth_packet ; ( addr payload ethtype -- ethernet_packet ) \end{lstlisting} This is verbatim (and what I want): \begin{verbatim} : paxos.learn ( addr n v -- Ethernet packet ) 2 paxos.pack32 ( addr n v -- addr payload ) paxos.eth_type.learn ( addr payload -- addr payload ethtype ) swap paxos.eth_packet ; ( addr payload ethtype -- ethernet_packet ) \end{verbatim} \end{document}
效果图:我们发现两个显示的内容空格的地方有较大差异。 修正这一代码的方法即:
\documentclass[a4paper]{report} \usepackage{listings} \begin{document} \lstset{ basicstyle=\ttfamily, columns=fullflexible, keepspaces=true, } \verb|basicstyle=\ttfamily, columns=fullflexible, keepspaces=true| \begin{lstlisting} : paxos.learn ( addr n v -- Ethernet packet ) 2 paxos.pack32 ( addr n v -- addr payload ) paxos.eth_type.learn ( addr payload -- addr payload ethtype ) swap paxos.eth_packet ; ( addr payload ethtype -- ethernet_packet ) \end{lstlisting} This is verbatim (and what I want): \begin{verbatim} : paxos.learn ( addr n v -- Ethernet packet ) 2 paxos.pack32 ( addr n v -- addr payload ) paxos.eth_type.learn ( addr payload -- addr payload ethtype ) swap paxos.eth_packet ; ( addr payload ethtype -- ethernet_packet ) \end{verbatim} \end{document}
效果图:选自:http://tex.stackexchange.com/questions/172702/how-can-i-make-lstlisting-look-exactly-like-verbatim
发表评论 取消回复