Verbatim 中的背景颜色

Verbatim 中的背景颜色

我必须在下面的代码中使用黄色背景来表示数据值。

\usepackage
\begin{Verbatim}[commandchars=\\\{\}]
\color{blue}DATA \color{black}Heart;
\color{blue}INPUT \color{black}X Y @@;
\color{blue}DATALINES\color{black};
28 70 23 68 52 90 42 75 27 68
29 80 43 78 34 70 40 80 28 72
;
\color{blue}RUN\color{black};

\color{blue}PROC REG DATA\color{black}=Heart;
\color{blue}MODEL \color{black}Y=X;
\color{blue}RUN\color{black};

\end{Verbatim}

任何帮助都将受到高度赞赏。

答案1

您的问题没有说明您正在使用幻想VRB包?我没有在包中看到背景颜色选项,但对于简短的片段,请使用环境SaveVerbatim并将其保存到框中。然后将内容放入颜色框中

\documentclass{article}
\usepackage{fancyvrb}
\usepackage{color}
\begin{document}
\begin{SaveVerbatim}[commandchars=\\\{\}]{SVerbEnv}
\color{blue}DATA \color{black}Heart;
\color{blue}INPUT \color{black}X Y @@;
\color{blue}DATALINES\color{black};
28 70 23 68 52 90 42 75 27 68
29 80 43 78 34 70 40 80 28 72
;
\color{blue}RUN\color{black};

\color{blue}PROC REG DATA\color{black}=Heart;
\color{blue}MODEL \color{black}Y=X;
\color{blue}RUN\color{black};
\end{SaveVerbatim}
\fcolorbox{black}{yellow}{\BUseVerbatim{SVerbEnv}}
\end{document}

您也可以使用框架获取多页内容的包

\documentclass{article}
\usepackage{fancyvrb}
\usepackage{framed}
\usepackage{color}
\definecolor{shadecolor}{cmyk}{0,0,1,0} %yellow
\begin{document}
\begin{shaded}
\begin{Verbatim}[commandchars=\\\{\}]
\color{blue}DATA \color{black}Heart;
\color{blue}INPUT \color{black}X Y @@;
\color{blue}DATALINES\color{black};
28 70 23 68 52 90 42 75 27 68
29 80 43 78 34 70 40 80 28 72
;
\color{blue}RUN\color{black};

\color{blue}PROC REG DATA\color{black}=Heart;
\color{blue}MODEL \color{black}Y=X;
\color{blue}RUN\color{black};
\end{Verbatim}
\end{shaded}
\end{document}

对于数据线,只需将其放入\colorbox

\documentclass{article}
\usepackage{fancyvrb}
\usepackage{color}
\begin{document}
\begin{Verbatim}[commandchars=\\\{\}]
\color{blue}DATA \color{black}Heart;
\color{blue}INPUT \color{black}X Y @@;
\color{blue}DATALINES\color{black};
\colorbox{yellow}{28 70 23 68 52 90 42 75 27 68}
\colorbox{yellow}{29 80 43 78 34 70 40 80 28 72}
\colorbox{yellow}{;                            }
\color{blue}RUN\color{black};

\color{blue}PROC REG DATA\color{black}=Heart;
\color{blue}MODEL \color{black}Y=X;
\color{blue}RUN\color{black};
\end{Verbatim}
\end{document}

相关内容