0

I'm trying to use two minipages inside an lstnewenvironment and I'm struggling with top- aligning the two minipages.

\lstnewenvironment{code}
{   
    \lstset{
        language=Python, 
        mathescape=true, 
        backgroundcolor=\color{cellbackground}, 
        numbers=right,
        numbersep=5pt,
        resetmargins=true,
        rulecolor=\color{cellbackground}
    }
    \addtocounter{inputcounter}{1}
    \minipage[t]{0pt}
    \footnotesize\ttfamily\llap{{\color{incolor}In [\theinputcounter]:\hspace{3pt}\boxspacing}}
    \endminipage%
    \minipage[t]{\pagewidth}
}{
    \endminipage
}

But when I use the new environment, the output looks like this:

enter image description here

Is there any way to make the In [1]: and the 2 + 2 lines aligned (on the same baseline)?

hbot
  • 117

1 Answers1

0

It seems there is a similar question asked here.

The answer is setting:

aboveskip=-1.4\medskipamount

on the lstnewenvironment, which moves the actual listing environment up, relative to the first minipage.

The entire lstnewenvironment becomes:

\lstnewenvironment{pfainput}
{   
    \lstset{
        language=Python, 
        aboveskip=-1.4\medskipamount,
        mathescape=true, 
        backgroundcolor=\color{cellbackground}, 
        numbers=right,
        numbersep=5pt,
        resetmargins=true,
        rulecolor=\color{cellbackground}
    }
    \addtocounter{inputcounter}{1}
    \minipage[t]{0pt}
    \footnotesize\ttfamily\llap{{\color{incolor}In [\theinputcounter]:\hspace{3pt}\boxspacing}}
    \endminipage
    \minipage[t]{\pagewidth}
}{
    \endminipage
}

I'll wait for other answers, but for now, this seems to do the trick.

hbot
  • 117