![tcolorbox & parskip & minted](https://linux22.com/image/418360/tcolorbox%20%26%20parskip%20%26%20minted.png)
我想在 tcolorbox 中使用 minted code extract,但它无法正确设置第一个框的 parskip。我已经parskip=false
在 tcolorbox 中使用了,但它没有解决问题。
\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
我发现parbox=false
用替换before upper={\setlength{\parskip}{.05in}}
可以解决问题。
此外,您还可以使用
\fvset{
listparameters={\topsep=\fancyvrbtopsep\partopsep=\fancyvrbpartopsep}
}
代替
\makeatletter
\FV@AddToHook{\FV@ListParameterHook}{\topsep=\fancyvrbtopsep\partopsep=\fancyvrbpartopsep}
\makeatother