我listings
在我的硕士论文中使用该包来列出源代码。
当设置为 时,如何设置lstlisting
环境的框架厚度?当设置为 以外的值时,命令不起作用...frameround
tttt
frameround
nnnn
framerule
这是我的\lstset
命令:
\lstset{
backgroundcolor=\color{green!5},
rulecolor=\color{green!40!black},
frameround=tttt,
%framerule=1.5pt, % frame thickness, not compatible with frameround=tttt
basewidth=0.50em,
frame=single,
}
答案1
我建议使用tcolorbox
和它的框架管理功能。然后环境在后台tcblistings
使用。listings
各个选项可以在环境定义中设置,也可以\tcbset{...}
直接作为参数设置。(我已经展示了直接设置和方法,但屏幕截图仅显示了第一种方法的输出)tcblistings
\newtcblisting
\newtcblisting
\documentclass{book}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}
% Defining a special listing box with green background a dark green border color.
\newtcblisting{mygreencode}[1]{%
boxsep=1pt,
boxrule=2pt,
arc=3mm,
auto outer arc,
colframe=green!40!
black,colback=green!5,
listing options={language=C},
listing only,
#1
}
\begin{document}
\begin{tcblisting}{boxsep=1pt,boxrule=2pt,arc=3mm, auto outer arc,colframe=green!40!black,colback=green!5,listing options={language=C},listing only}
#include <stdio.h>
int main( int argc, char **argv )
{
printf("Hello World!\n");
return (0);
}
\end{tcblisting}
\begin{mygreencode}{}
#include <stdio.h>
int main( int argc, char **argv )
{
printf("Hello World!\n");
return (0);
}
\end{mygreencode}
\end{document}
答案2
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[scaled=0.85]{beramono}
\usepackage{xcolor,listings}
\lstnewenvironment{Ccode}{%
\thicklines
\lstset{
backgroundcolor=\color{green!5},
rulecolor=\color{green!40!black},
frameround=tttt,
frame=single,
language=C,
basicstyle=\ttfamily\small,
basewidth=0.50em,
keywordstyle=\bfseries,
}}{}
\begin{document}
\begin{Ccode}
#include <stdio.h>
int main( int argc, char **argv ){
printf("Hello World!\n");
return (0);
}
\end{Ccode}
\end{document}