2

I would like to have my SAS code with more or less the same distances between the previous sentence and the following one. I did it putting it in a tcolorbox with before skip=0pt plus 2pt minus 2pt and after skip=4pt plus 2pt minus 2pt (perhaps there are better methods I don't know).

I don't want one data step be separated across pages (putting it within a tcolorbox I can achieve that) but I want that two different data steps could be divided.

What I did works but there is too much space between the end of one step and the start of another. I know I can use \vspace{-2pt} to solve this, but there's no way to do it automatically?

\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}

enter image description here

  • Does before lower={\setlength{\parskip}{50pt}} help? (or any other ...pt value`) – user31729 Sep 17 '17 at 10:17
  • @ChristianHupfer Unfortunately not, it remains too much space. – CarLaTeX Sep 17 '17 at 10:20
  • It was a guess only yet... – user31729 Sep 17 '17 at 10:20
  • Quick and dirty: code={\vspace{-2pt}} – user31729 Sep 17 '17 at 10:27
  • 1
    Try negative values for top and bottom, but I think the real cause is aboveskip and belowskip from listings – user31729 Sep 17 '17 at 10:40
3

Following Christian Hupfer's advice, I think I've found a solution adding:

aboveskip=-4pt plus 2pt minus 2pt,
belowskip=-4pt plus 2pt minus 2pt,

to the 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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.