I want to make a tcolorbox with minted Python code similar to this answer, including the size/aspect-ratio of the box, but with an additional requirement. I would like the rendered tcolorbox to take up the entire PDF document, notwithstanding some white space near the rounded corners. Or rather, I would like the tcolorbox to be of a similar size as if it were going to be placed in a document, but have all the white space around it tightened at or close to its border. Using that linked answer as an example, I would like the output be a PDF that contains this:

enter image description here

I seem to have eliminated the margins and the top whitespace with the geometry package by setting top=0mm and margin=0mm, but I am not sure how to remove the rest of the whitespace. I tried bottom=0mm but that did not work.

But there is still whitespace below.

With these isolated little code snippets I intend to put them into different slides and documents using the \includegraphcs command from graphicx. This in part to avoid perplexing behaviour that I suspect is coming from so many disparate packages being included in the preamble, but it would also allow me to reuse and share little snippets of code for document preparation.

I am using Texmaker with PdfLaTeX, if that matters. Is there a way to do this?

  • This GitHub blog post looks promising, although prima facie it seems like steps have to be taken outside of LaTeX.
    – Galen
    Mar 6 at 19:11

1 Answer 1


I am not sure if this is what you are looking for.


  listing engine=minted,
  listing only,
  minted style=colorful,
  minted language=python,
  minted options={numbersep=3mm,texcl=true,#1},
  overlay={\begin{tcbclipinterior}\fill[black!25] (frame.south west)
            rectangle ([xshift=5mm]frame.north west);\end{tcbclipinterior}},

\begin{pythoncode}[linenos=true,]{colback=red!5!white,colframe=red!75!black,title=My nice heading}
# indent your Python code to put into an email
import glob
# glob supports Unix style pathname extensions
python_files = glob.glob('*.py')
for file_name in sorted(python_files):
    print '    ------' + file_name

    with open(file_name) as f:
        for line in f:
            print '    ' + line.rstrip()

  • "I am not sure if this is what you are looking for." Maybe so, but you nailed it! (+1)
    – Galen
    Mar 7 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.