LaTeX中逐字环境中的文本颜色

时间:2014-06-24 03:58:00

标签: latex

如何在逐字环境中更改文本某些部分的颜色。我有这样的事情:

\tiny\begin{verbatim}
HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Expires: Mon, 1 Aug 2011 09:00:00 GMT
Connection: close
Access-Control-Max-Age: 0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE
Access-Control-Allow-Headers: Content-Type
Content-type: application/json
[{"error":{"type":1,"address":"/","description":"unauthorized user"}}] <--- This text needs to be red
\end{verbatim}
\normalsize

我需要将此行设为红色:

[{"error":{"type":1,"address":"/","description":"unauthorized user"}}]

1 个答案:

答案 0 :(得分:2)

fancyvrb似乎非常适合这项任务:

enter image description here

\documentclass{article}
\usepackage{fancyvrb,xcolor}

\begin{document}

This is some preceding text.

\begin{Verbatim}[fontsize=\small,commandchars=\\\(\)]
HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Expires: Mon, 1 Aug 2011 09:00:00 GMT
Connection: close
Access-Control-Max-Age: 0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE
Access-Control-Allow-Headers: Content-Type
Content-type: application/json
(\color(red)"error":{"type":1,"address":"/","description":"unauthorized user"}}])
\end{Verbatim}

This is some following text.
\end{document}

由于逐字要求中未出现\(),因此将其用作控制序列和参数文字分隔符。