7

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!

4
  • 2
    I can't give you a clear answer without an MWE, but autogobble option seems to be of help.
    – yudai-nkt
    Jul 19 '17 at 5:24
  • @CarLaTex yes, you are right. I should give more information. I have updated the question.
    – Huayi Wei
    Jul 19 '17 at 5:54
  • As @yudai-nkt said, if you put autogobble instead of gobble=2 it works. (To yudai-nkt: you could post an answer).
    – CarLaTeX
    Jul 19 '17 at 5:57
  • Yes, I have tested it. It works! Thanks very much! @yudai-nkt
    – Huayi Wei
    Jul 19 '17 at 5:58
6

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

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.