TransWikia.com

tcolorbox & parskip & minted

TeX - LaTeX Asked on October 1, 2021

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}{sffamilytinyarabic{FancyVerbLine}}
AtBeginEnvironment{minted}{needspace{1baselineskip}}

newlength{fancyvrbtopsep}
newlength{fancyvrbpartopsep}
makeatletter
FV@AddToHook{FV@ListParameterHook}{topsep=fancyvrbtopseppartopsep=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.5baselineskip,
enlarge bottom by=0baselineskip,
fonttitle=bfseries,breakable,enhanced jigsaw,
title=Python~#1}
newenvironment{mycolorbox}[1][]
  {ifdetokenize{#1}relaxrelax
      begin{tcolorbox}
    else
      begin{tcolorbox}[#1]
    fi
  parskip=5baselineskip advanceparskip 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}

One Answer

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

Additionally, you can use

fvset{
  listparameters={topsep=fancyvrbtopseppartopsep=fancyvrbpartopsep}
}

instead of

makeatletter
FV@AddToHook{FV@ListParameterHook}{topsep=fancyvrbtopseppartopsep=fancyvrbpartopsep}
makeatother

Correct answer by muzimuzhi Z on October 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP