我使用带有单框的 listings 包,当我在代码中放置长注释时,注释的颜色会影响框的颜色。注释行周围的框为绿色。我希望框始终为黑色。
\documentclass{article}
\usepackage{tikz}
\usepackage{listings}
\begin{document}
\lstset{language=C++,
basicstyle=\ttfamily,
keywordstyle=\color{blue}\ttfamily,
commentstyle=\color{green}\ttfamily,
frame=single,
breaklines=true,
}
\begin{lstlisting}
void foo()
{
for (int i=0 ; i<VALUES_SIZE ; i++)
{
int x=i*2;//some very long comments about actual code in this line
int y=i*2;//some really very very very long comments about actual code in this line spreading over two or three long lines
}
}
\end{lstlisting}
\end{document}
答案1
變成rulecolor
黑色。
\documentclass{article}
\usepackage{tikz}
\usepackage{listings}
\begin{document}
\lstset{language=C++,
basicstyle=\ttfamily,
keywordstyle=\color{blue}\ttfamily,
commentstyle=\color{green}\ttfamily,
frame=single,
rulecolor=\color{black}, %%% <--- here
breaklines=true,
}
\begin{lstlisting}
void foo()
{
for (int i=0 ; i<VALUES_SIZE ; i++)
{
int x=i*2;//some very long comments about actual code in this line
int y=i*2;//some really very very very long comments about actual code in this line spreading over two or three long lines
}
}
\end{lstlisting}
\end{document}