我希望我的 SAS 代码中前一句和后一句之间的距离大致相同。我将其放在 with
tcolorbox
and
before skip=0pt plus 2pt minus 2pt
中
after skip=4pt plus 2pt minus 2pt
(也许有更好的方法,我不知道)。
我不希望一个data
步骤跨页面(将其放在
tcolorbox
我可以实现的范围内)但我希望
data
可以分为两个不同的步骤。
我的方法有效,但是一个步骤的结束和另一个步骤的开始之间有太多空格。我知道我可以使用 来\vspace{-2pt}
解决这个问题,但没有办法自动完成?
\documentclass[a4paper,12pt, twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3.5cm,lmargin=4cm,rmargin=3cm,marginparwidth=2.5cm}
\usepackage{fancyhdr}
\frenchspacing
\setlength{\parskip}{1ex}
\usepackage[all]{nowidow}
\usepackage{ragged2e}
\raggedbottom
\usepackage{upquote}% per avere gli apici dritti nelle stringhe
\usepackage[most]{tcolorbox}
\tcbuselibrary{listings}
\tcbset{colback=blue!4!white,colframe=blue,
fonttitle=\bfseries,
before skip = 16pt,
parbox=false,
before upper={\parindent0pt},
}
\usepackage{listings}
\newcommand{\stilestringa}{\color[rgb]{0.639,0.082,0.082}\ttfamily}
\newcommand{\stilecomandoa}{\color{blue}\ttfamily}
\newcommand{\stilecomandob}{\color{blue!50}\ttfamily}
\newcommand{\stilecommenti}{\color[RGB]{77,159,53}\ttfamily}
\newcommand{\stilewarnings}{\color[RGB]{93,138,168}\ttfamily}
\newcommand{\stileerrori}{\color{red}\ttfamily}
\newcommand{\sasinline}[1]{\lstinline[style=saslst, basicstyle=\ttfamily]!#1!}
\newcommand{\sasstringemph}[1]{\stilestringa \emph{#1}}
\newcommand{\sasutente}[1]{\emph{#1}}
\lstdefinestyle{saslst}{
columns=flexible,
language=SAS,
morekeywords=[1]{quit, proc, let, macro, mend},
morekeywords=[2]{access, obs, firstobs, format, append, sort, sql, transpose, compare, in, when, otherwise, select},
morecomment=[f]{*},
morecomment=[s]{/*}{*/},
morecomment=[n]{/*}{*/},
morestring=[b]{"},
escapechar=|,
otherkeywords={!,!=,~,$,\&,_,<,>=,=<,>,\%, =},
keywordstyle={[1]\stilecomandoa},
keywordstyle={[2]\stilecomandob},
commentstyle=\stilecommenti,
stringstyle=\stilestringa,
showstringspaces=false,
keepspaces=true,
sensitive=false,
breaklines=true,
breakindent=0pt,
inputencoding=utf8/latin1
}
\newtcblisting{sas}{%
listing only,
before skip=0pt plus 2pt minus 2pt,
after skip=4pt plus 2pt minus 2pt,
top=0pt,
bottom=0pt,
enhanced,
opacityfill=0,
left=0mm,
boxsep=0pt,
boxrule=0pt,
listing engine=listings,
listing options={style=saslst,
basicstyle=\small\ttfamily
}
}
\begin{document}
Here is a single \sasinline{data} step:
\begin{sas}
data classe;
set sashelp.class;
when age=11;
run;
\end{sas}
Here there is too much space
between \sasinline{/* END OF ONE STEP */}
and \sasinline{/* START OF ANOTHER STEP */}:
\begin{sas}
data classe;
set sashelp.class;
when age=11;
run;
/* END OF ONE STEP */
\end{sas}
\begin{sas}
/* START OF ANOTHER STEP */
data classe;
set sashelp.class;
when age=11;
run;
\end{sas}
This is what I would like to achieve automatically:
\begin{sas}
data classe;
set sashelp.class (obs=4);
run;
/* END OF ONE STEP */
\end{sas}
\vspace{-2pt}\begin{sas}
/* START OF ANOTHER STEP */
data classe;
set sashelp.class (obs=4, firstobs=10);
run;
\end{sas}
\end{document}
答案1
根据 Christian Hupfer 的建议,我认为我找到了一个解决方案,添加:
aboveskip=-4pt plus 2pt minus 2pt,
belowskip=-4pt plus 2pt minus 2pt,
至listing options
:
\documentclass[a4paper,12pt, twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3.5cm,lmargin=4cm,rmargin=3cm,marginparwidth=2.5cm}
\usepackage{fancyhdr}
\frenchspacing
\setlength{\parskip}{1ex}
\usepackage[all]{nowidow}
\usepackage{ragged2e}
\raggedbottom
\usepackage{upquote}% per avere gli apici dritti nelle stringhe
\usepackage[most]{tcolorbox}
\tcbuselibrary{listings}
\tcbset{colback=blue!4!white,colframe=blue,
fonttitle=\bfseries,
% before skip = 16pt,
parbox=false,
before upper={\parindent0pt},
}
\usepackage{listings}
\newcommand{\stilestringa}{\color[rgb]{0.639,0.082,0.082}\ttfamily}
\newcommand{\stilecomandoa}{\color{blue}\ttfamily}
\newcommand{\stilecomandob}{\color{blue!50}\ttfamily}
\newcommand{\stilecommenti}{\color[RGB]{77,159,53}\ttfamily}
\newcommand{\stilewarnings}{\color[RGB]{93,138,168}\ttfamily}
\newcommand{\stileerrori}{\color{red}\ttfamily}
\newcommand{\sasinline}[1]{\lstinline[style=saslst, basicstyle=\ttfamily]!#1!}
\newcommand{\sasstringemph}[1]{\stilestringa \emph{#1}}
\newcommand{\sasutente}[1]{\emph{#1}}
\lstdefinestyle{saslst}{
columns=flexible,
language=SAS,
aboveskip=-4pt plus 2pt minus 2pt,
belowskip=-4pt plus 2pt minus 2pt,
morekeywords=[1]{quit, proc, let, macro, mend},
morekeywords=[2]{access, obs, firstobs, format, append, sort, sql, transpose, compare, in, when, otherwise, select},
morecomment=[f]{*},
morecomment=[s]{/*}{*/},
morecomment=[n]{/*}{*/},
morestring=[b]{"},
escapechar=|,
otherkeywords={!,!=,~,$,\&,_,<,>=,=<,>,\%, =},
keywordstyle={[1]\stilecomandoa},
keywordstyle={[2]\stilecomandob},
commentstyle=\stilecommenti,
stringstyle=\stilestringa,
showstringspaces=false,
keepspaces=true,
sensitive=false,
breaklines=true,
breakindent=0pt,
inputencoding=utf8/latin1
}
\newtcblisting{sas}{%
listing only,
% before skip=0pt plus 2pt minus 2pt,
% after skip=4pt plus 2pt minus 2pt,
% code={\vspace{-2pt}},
% top=-2pt,
% bottom=-2pt,
enhanced,
opacityfill=0,
left=0mm,
boxsep=0pt,
boxrule=0pt,
listing engine=listings,
listing options={style=saslst,
basicstyle=\small\ttfamily
}
}
\begin{document}
\noindent Here is a single \sasinline{data} step:
\begin{sas}
data classe;
set sashelp.class;
when age=11;
run;
\end{sas}
\noindent Here there is too much space
between \sasinline{/* END OF ONE STEP */}
and \sasinline{/* START OF ANOTHER STEP */}:
\begin{sas}
data classe;
set sashelp.class;
when age=11;
run;
/* END OF ONE STEP */
\end{sas}
\begin{sas}
/* START OF ANOTHER STEP */
data classe;
set sashelp.class;
when age=11;
run;
\end{sas}
\noindent This seems to work \textasciicircum\textasciicircum\textasciicircum
\end{document}