我在多列环境中使用 minted,想要删除第一列开头的间距。我找到了答案belowskip
,正在寻找相同的代码aboveskip
:
编辑: 木子木之-z 提供了一个很好的答案。这允许漂亮的两列列表:
\documentclass[aspectratio=1610]{beamer}
\usepackage{fancyvrb}
\usepackage{xpatch}
\usepackage{minted}
\makeatletter
% new fancyvrb options "above space" and "below vspace"
\define@key{FV}{above vspace}[\topsep]{\def\FancyVerbAboveVspace{#1}}
\define@key{FV}{below vspace}[\topsep]{\def\FancyVerbBelowVspace{#1}}
% redefine existing option "vspace"
\define@key{FV}{vspace}[\topsep]{%
\def\FancyVerbAboveVspace{#1}\def\FancyVerbBelowVspace{#1}}
% init
\fvset{vspace}
% patch fancyvrb internals
\xpatchcmd\FV@ListVSpace
{\@topsepadd=\FancyVerbVspace}
{\@topsepadd=\FancyVerbAboveVspace}
{}{\PatchFailed}
\xpatchcmd\FV@EndList
{\@endparenv}
{\@topsepadd\dimexpr\@topsepadd-\FancyVerbAboveVspace
+\FancyVerbBelowVspace\relax
\@endparenv}
{}{\PatchFailed}
\minted@def@optfv{vspace}
\minted@def@optfv{above vspace}
\minted@def@optfv{below vspace}
\makeatother
\usepackage{tikz}
\usepackage{multicolrule}
\begin{document}
\begin{frame}{Codebox}
\definecolor{codebg}{rgb}{.1, .1, .1}
\setbeamercolor{blackcodebox}{fg=white,bg=codebg}
\begin{beamercolorbox}[rounded=true]{blackcodebox}
\small Comet ML\vspace{4pt}
\hrule
\setlength\multicolsep{1pt} % no multicol top margin
\SetMCRule{line-style=solid-circles,color=white,width=2pt}
\begin{multicols}{2}
\setlength{\parskip}{0pt}
foo
\usemintedstyle{monokai}
\inputminted[tabsize=2,breaklines,fontsize=\scriptsize,python3=true,%
below vspace=0pt,above vspace=0pt]{python}{example.py}
bar
\end{multicols}
\end{beamercolorbox}
\end{frame}
\end{document}
答案1
fancyvrb
有一个未记录的选项vspace
,用于控制上方和下方跳过。此选项具有默认值和初始值\topsep
,自 2009 年起受支持。fancyvrb
v3.0 2018/11/01
下面的例子中添加了两个选项above vspace
。现在below vspace
- 以上总计跳过
<above vspace> + \parskip (+ \partopsep)
- 总计以下跳过
<below vspace> + \parskip (+ \partopsep)
看https://latexref.xyz/list.html关于如何在正常列表中计算上方和下方跳过。
\documentclass{article}
\usepackage{fancyvrb}
\usepackage{lipsum}
\usepackage{xpatch}
\makeatletter
% new fancyvrb options "above space" and "below vspace"
\define@key{FV}{above vspace}[\topsep]{\def\FancyVerbAboveVspace{#1}}
\define@key{FV}{below vspace}[\topsep]{\def\FancyVerbBelowVspace{#1}}
% redefine existing option "vspace"
\define@key{FV}{vspace}[\topsep]{%
\def\FancyVerbAboveVspace{#1}\def\FancyVerbBelowVspace{#1}}
% init
\fvset{vspace}
% patch fancyvrb internals
\xpatchcmd\FV@ListVSpace
{\@topsepadd=\FancyVerbVspace}
{\@topsepadd=\FancyVerbAboveVspace}
{}{\PatchFailed}
\xpatchcmd\FV@EndList
{\@endparenv}
{\@topsepadd\dimexpr\@topsepadd-\FancyVerbAboveVspace
+\FancyVerbBelowVspace\relax
\@endparenv}
{}{\PatchFailed}
\makeatother
\parindent=0pt
\begin{document}
\newcommand\controlGroup[1]{\par
\subsection*{#1}
\begin{minipage}[t]{.45\textwidth}
\lipsum[1][1]
\begin{flushleft}\ttfamily
content \% trivlist env\\
content \% control group
\end{flushleft}
\lipsum[1][1]
\end{minipage}
\qquad\ignorespaces
}
\controlGroup{Default}
\begin{minipage}[t]{.45\textwidth}
\lipsum[1][1]
\begin{Verbatim}
content % by default, above skip =
content % below skip = \topsep
\end{Verbatim}
\lipsum[1][1]
\end{minipage}
\controlGroup{\texttt{vspace=0pt}}
\begin{minipage}[t]{.45\textwidth}
\lipsum[1][1]
\begin{Verbatim}[vspace=0pt]
content
content
\end{Verbatim}
\lipsum[1][1]
\end{minipage}
\controlGroup{\texttt{above vspace=0pt}}
\begin{minipage}[t]{.45\textwidth}
\lipsum[1][1]
\begin{Verbatim}[above vspace=0pt]
content
content
\end{Verbatim}
\lipsum[1][1]
\end{minipage}
\controlGroup{\texttt{below vspace=0pt}}
\begin{minipage}[t]{.45\textwidth}
\lipsum[1][1]
\begin{Verbatim}[below vspace=0pt]
content
content
\end{Verbatim}
\lipsum[1][1]
\end{minipage}
\end{document}
以下三行添加minted
接口:
\minted@def@optfv{vspace}
\minted@def@optfv{above vspace}
\minted@def@optfv{below vspace}