如您所见,创建的彩色框backgroundcolor
非常紧凑。如何增加“填充”,即框与其内容之间的空间?
这似乎有关联,但是我没有颜色框周围的框架,并且那里的建议也没有解决问题。
包裹framed
可以放在阴影框中(参见下面的评论),因此一种可能性是重新定义lstlisting
。有人这样做过吗?
\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{graphicx}
\usepackage{fancyvrb}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{framed}
\xdefinecolor{shadecolor}{rgb}{0.97,0.97,0.97}
\lstset{% setup listings
language=R,% set programming language
backgroundcolor=\color{yellow}% background color
}
\begin{document}
\noindent Just some text.
%\begin{shaded*}
\begin{lstlisting}[caption={A first example}, label=list:ex]
x <- c(1, 3, 2)
id <- function(x){
x # just a dummy
}
3 <= 4
3 != 4
!TRUE
y <- "foo"
(pv <- sum(x * x^x))
y ~ x + a
\end{lstlisting}
%\end{shaded*}
\end{document}
答案1
您可以使用framexleftmargin=<len>
来调整左边距。要调整顶部和底部,也有类似的选项,但似乎您还需要指定frame=tb
,以便在顶部和底部添加额外的填充。framerule=0pt
如果不需要,包括将删除规则。
代码:
\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{graphicx}
\usepackage{fancyvrb}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{framed}
\xdefinecolor{shadecolor}{rgb}{0.97,0.97,0.97}
\lstset{% setup listings
language=R,% set programming language
backgroundcolor=\color{yellow},% background color
framexleftmargin=16pt,
framextopmargin=6pt,
framexbottommargin=6pt,
frame=tb, framerule=0pt,
}
\begin{document}
\noindent Just some text.
%\begin{shaded*}
\begin{lstlisting}[caption={A first example}, label=list:ex]
x <- c(1, 3, 2)
id <- function(x){
x # just a dummy
}
3 <= 4
3 != 4
!TRUE
y <- "foo"
(pv <- sum(x * x^x))
y ~ x + a
\end{lstlisting}
%\end{shaded*}
\end{document}