minted
minted copied to clipboard
bgcolor incompatible when using xleftmargin and/or xrightmargin
Hi all. The bug is pretty obvious from the images. Any workaround?
w/o margins:
w/ margins:
Can you provide the source for your example?
Sure.
\documentclass[]{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{minted}
\setminted{%
frame=single,
bgcolor=lightgray
}
%opening
\title{}
\author{}
\begin{document}
\begin{minted}[]{c}
hello world
\end{minted}
\begin{minted}[xleftmargin=0.1\textwidth,xrightmargin=0.1\textwidth]{c}
hello world
\end{minted}
\end{document}
Result:
Does anyone get any solutions?
Try this:
\documentclass{article}
\usepackage{minted}
\setminted{
frame=single,
}
\makeatletter
\renewenvironment{minted@snugshade*}[1]{%
\def\FrameCommand##1{\hskip\@totalleftmargin
%% old code
% \colorbox{#1}{##1}%
%% new code
\hskip\FV@XLeftMargin
\colorbox{#1}{\hskip-\FV@XLeftMargin##1\hskip-\FV@XRightMargin}%
\hskip\FV@XRightMargin
%% end new code
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
\MakeFramed{\advance\hsize-\width
\@totalleftmargin\z@ \linewidth\hsize
\advance\labelsep\fboxsep
\@setminipage}%
}{\par\unskip\@minipagefalse\endMakeFramed}
\makeatother
\begin{document}
\begin{minted}[bgcolor=lightgray]{c}
hello world
\end{minted}
\begin{minted}[xleftmargin=0.1\textwidth,xrightmargin=0.2\textwidth]{c}
hello world
\end{minted}
\begin{minted}[
bgcolor=lightgray,
xleftmargin=0.1\textwidth,
xrightmargin=0.2\textwidth
]{c}
hello world
\end{minted}
\end{document}
Note in general tcolorbox
's minted
library provides more powerful hence better control on decorating minted
environment output.
Wonderful! Thanks so much for your help!