[Tex/LaTex] In minted, how to reduce the blank space between the line number and the code

beamermintedpython

The following is example beamer file:

\documentclass[notheorems,serif,11pt]{beamer}
\usepackage{algorithm}
\usepackage{float}
\usepackage{minted}
\renewcommand{\listingscaption}{Python code}
\newminted{python}{
    fontsize=\footnotesize, 
    escapeinside=||,
    mathescape=true,
    numbersep=5pt,
    linenos=true,
    gobble=2,
    framesep=3mm} 
\begin{document}

\begin{frame}[fragile]{Mesh Data Strucrure}
        \begin{listing}[H]
        \begin{pythoncode}
        import numpy as np
        point = np.array(
            [(0.0, 0.0),
             (1.0, 0.0),
             (1.0, 1.0),
             (0.0, 1.0)], dtype=np.float)
        cell = np.array([
                (1, 2, 0), 
                (3, 0, 2)], dtype=np.int)
        N = point.shape[0] # the number of triangle points
        NC = cell.shape[0] # the number of triangle cells
        \end{pythoncode}
        \caption{The basic data structure of triangle mesh.}
    \end{listing}
\end{frame}

\end{document}

Finally, I get the following result in my slide:

enter image description here

My problem is that the blank space between the line number and code is too wide, and I want to reduce it. So how to do it? Thanks very much!

Best Answer

The autogobble option is the way to go. Here is the excerpt from the manual:

Remove (gobble) all common leading whitespace from code. Essentially a version of gobble that automatically determines what should be removed. Good for code that originally is not indented, but is manually indented after being pasted into a LaTeX document.

By utilizing this,

\documentclass[notheorems,serif,11pt]{beamer}
\usepackage{algorithm}
\usepackage{float}
\usepackage{minted}
\renewcommand{\listingscaption}{Python code}
\newminted{python}{
    fontsize=\footnotesize, 
    escapeinside=||,
    mathescape=true,
    numbersep=5pt,
    linenos=true,
    autogobble,
    framesep=3mm} 
\begin{document}

\begin{frame}[fragile]{Mesh Data Strucrure}
        \begin{listing}[H]
        \begin{pythoncode}
        import numpy as np
        point = np.array(
            [(0.0, 0.0),
             (1.0, 0.0),
             (1.0, 1.0),
             (0.0, 1.0)], dtype=np.float)
        cell = np.array([
                (1, 2, 0), 
                (3, 0, 2)], dtype=np.int)
        N = point.shape[0] # the number of triangle points
        NC = cell.shape[0] # the number of triangle cells
        \end{pythoncode}
        \caption{The basic data structure of triangle mesh.}
    \end{listing}
\end{frame}
\end{document}

will produce

MWE

Related Question