2

I want to use minted code extract within tcolorbox, but it fails to properly set the parskip of the first box. I already use parskip=false inside the tcolorbox, but it doesn't solve the issue.

enter image description here

\documentclass[twoside,10pt]{book}
\usepackage{wrapfig}
\usepackage{geometry} 
\geometry{paperwidth=7in, paperheight=9in, bindingoffset=0.35in, left=0.7in, right=0.7in, top=1in, bottom=0.8in}
\usepackage{float}
\setlength{\parskip}{0.05 in}

\usepackage{minted}
\usepackage{csquotes}
\usepackage{upquote}%straight quotes in minted
\setminted{fontsize=\small, breaklines=true, breakbefore=., breakafter={,,+,~,\space,:}, showspaces, space=~, frame=single, numbers=left, numbersep=5pt, highlightcolor={red!25}, fontfamily=tt}
\renewcommand{\theFancyVerbLine}{\sffamily\tiny\arabic{FancyVerbLine}}
\AtBeginEnvironment{minted}{\needspace{1\baselineskip}}

\newlength{\fancyvrbtopsep}
\newlength{\fancyvrbpartopsep}
\makeatletter
\FV@AddToHook{\FV@ListParameterHook}{\topsep=\fancyvrbtopsep\partopsep=\fancyvrbpartopsep}
\makeatother
\setlength{\fancyvrbtopsep}{1pt} 
\setlength{\fancyvrbpartopsep}{1pt}

\addtolength{\headheight}{0.5pt}
\setlength{\footskip}{0.35in}

\usepackage[most]{tcolorbox}

\newtcolorbox{Python}[1][]{
parbox=false,
parskip=0.05in,
colback=white,
colframe=black!50!white,
coltitle=white,
enlarge top by=0.5\baselineskip,
enlarge bottom by=0\baselineskip,
fonttitle=\bfseries,breakable,enhanced jigsaw,
title=Python~#1}
\newenvironment{mycolorbox}[1][]
  {\if\detokenize{#1}\relax\relax
      \begin{tcolorbox}
    \else
      \begin{tcolorbox}[#1]
    \fi
  \parskip=5\baselineskip \advance\parskip by 0pt plus 2pt
  \parindent=0pt
}
  {\end{tcolorbox}}
\begin{document}
\begin{Python}[dummy text]
dummy text
\begin{minted}{python}
dummy code
\end{minted}
dummy text
\begin{minted}{python}
dummy code
\end{minted}
\end{Python}
\end{document}
1
  • Had the same issue. Only solution I was able to employ was to use keys before and after to set whitespace before and after tcolorbox, but it is not perfectly reliable workaround. Commented Jul 29, 2020 at 10:29

1 Answer 1

2

I find replacing parbox=false by before upper={\setlength{\parskip}{.05in}} solves the problem.

Additionally, you can use

\fvset{
  listparameters={\topsep=\fancyvrbtopsep\partopsep=\fancyvrbpartopsep}
}

instead of

\makeatletter
\FV@AddToHook{\FV@ListParameterHook}{\topsep=\fancyvrbtopsep\partopsep=\fancyvrbpartopsep}
\makeatother
1
  • Changing 'parbox=false' by 'before upper={\setlength{\parskip}{.05in}}' worked! Thank you so much :)
    – Nicolas
    Commented Jul 29, 2020 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .