我用来verbatim
在我的文档中放置一些示例代码:
\begin{verbatim}
[start] printf{"Start command received"};
[stop] printf{"Stop command received"};
\end{verbatim}
我希望 Latex 保留标签,但我得到的输出却是这样的:
[start] printf{"Start command received"};
[stop] printf{"Stop command received"};
如您所见,制表符已转换为空格。这是否违背了在里面写东西的整个目的verbatim
?是这样的正常行为对verbatim
环境有什么影响?
PS 我正在使用 TexLive 2014 和 TexStudio 2.8.8
答案1
使用fancyvrb
:
\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
Some text to surround the verbatim
\begin{Verbatim}[obeytabs]
[start] printf{"Start command received"};
[stop] printf{"Stop command received"};
\end{Verbatim}
Some text to surround the verbatim
\begin{Verbatim}[obeytabs,tabsize=4]
[start] printf{"Start command received"};
[stop] printf{"Stop command received"};
\end{Verbatim}
Some text to surround the verbatim
\end{document}
(注意:真正的输入文件有制表符,但 StackExchange 似乎将它们转换为空格。)