5

I have to write an article with many blocks embedding equations and code and decided to use the package minted.

I would like to reduce the spacing (margins) before and after each minted block, just keeping a simple line spacing between them.

\RequirePackage{luatex85}
\documentclass[11pt, a4paper, spanish]{article}
\usepackage[left=3.5cm, right=3.4cm, top=4.7cm, bottom=4.1cm]{geometry} 
\renewcommand{\baselinestretch}{1.54}
\usepackage{parskip}   % separación entre parrafos
\parskip=12pt
\setlength{\parindent}{2em} 
\usepackage{polyglossia}    
\setmainlanguage{spanish}
\usepackage[no-math]{fontspec}
\setmainfont{TeXGyrePagellaX}
\usepackage{float}
\usepackage{minted}
\renewcommand\listingscaption{Resultados}
\usepackage{indentfirst}
\usepackage[usenames,dvipsnames]{xcolor}
\definecolor{bg}{rgb}{0.92,0.97,1}
\begin{document}

\section{First}
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
  sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
  Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris 
  nisi ut aliquip ex ea commodo consequat.
\begin{listing}[H]
\begin{minted}[fontsize=\small, bgcolor=bg]{text}
    E=m·c^2
    some code
\end{minted}
    \caption{MyCaption.}
    \label{mylabel}
\end{listing}   
Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. 
\begin{minted}[fontsize=\small, bgcolor=bg, escapeinside=||,
  mathescape=true]{text}
    |$E=m·c^2$|
\end{minted}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim 
 ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut 
aliquip ex ea commodo consequat.
\end{document}

I already asked the question and received a solution from @egreg Modify space before and after minted text

 \AtBeginEnvironment{minted}{\setlength{\parskip}{0pt}}

But my question has become a more complex because I also need to use captions and labels, included in my second minted example above. So my code needs to be embedded within listings. And his solution doesn't work.

How can I have minted blocks with captions and keep the top and bottom margins reduced? I would also like to reduce the distance between the minted block and the caption, usually bellow, or even insert the caption on the top as a title bar.

skan
  • 1,008
  • What if I just use a captionof{listing}{mycaption} just below my minted code? What is the dissadvantage of this? – skan Sep 10 '19 at 22:49

0 Answers0