Is there a way to modify the code that minted
uses to draw the background to have it up to the middle of the page, or a custom length?
I think it should be done with a \newcommand
or something like that since I want to keep the default style for large pieces of code, and the customized background length for small pieces of code.
\documentclass{article}
\usepackage{minted}
\usemintedstyle[c++]{manni}
\usepackage{xcolor}
\definecolor{codebackground}{RGB}{240, 240, 235}
\newlength{\msize}
\setlength{\msize}{\dimexpr(\paperwidth-\textwidth)/2\relax}
\begin{document}
\hspace*{\msize} Stop background here?\par
\hspace*{\msize} $ \downarrow $
\begin{minted}[bgcolor=codebackground]{c}
int main() {
printf("hello, world");
return 0;
}
\end{minted}
\end{document}
Here is the code that minted
uses, taken from its documentation
\newenvironment{minted@colorbg}[1]{%
\setlength{\OuterFrameSep}{0pt}%
\colorlet{shadecolor}{#1}%
\let\minted@tmp\FV@NumberSep
\edef\FV@NumberSep{%
\the\numexpr\dimexpr\minted@tmp+\number\fboxsep\relax sp\relax}%
\medskip
\begin{snugshade*}}
{\end{snugshade*}%
\medskip\noindent}
minted
environment in a minipage, see tex.stackexchange.com/a/161126.