【问题标题】:Text color in Verbatim environment in LaTeXLaTeX中逐字环境中的文本颜色
【发布时间】:2014-06-24 03:58:00
【问题描述】:

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

\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"}}]

【问题讨论】:

  • 同样的问题和好的答案是here

标签: latex


【解决方案1】:

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

\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}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-25
    • 1970-01-01
    相关资源
    最近更新 更多