Cambiar el tamaño del código Python en un documento LaTeX

Cambiar el tamaño del código Python en un documento LaTeX

Estoy intentando ingresar mi código Python en un documento usandoesteplantilla que utiliza ellistadospaquete. Sin embargo, quiero cambiar el tamaño de la fuente del código, es decir, cualquier mención \texttt{}del lstlistingentorno.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{fourier}

\usepackage[scaled]{beramono}
\usepackage{listings}
\lstset{
  language=Python, showstringspaces=false, formfeed=\newpage, tabsize=4,
  commentstyle=\itshape, basicstyle=\ttfamily, morekeywords={models, lambda, forms}
  fontsize=\footnotesize
}
\newcommand{\code}[2]{
  \hrulefill
  \subsection*{#1}
  \lstinputlisting{#2}
  \vspace{2em}
}

\begin{document}

This is the code from my file \texttt{mycode.py}:

\begin{lstlisting}
def factorial(n):
   """The factorial of a number the slow way"""

   # comments are printed in italic
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)
\end{lstlisting}


\end{document}

Intenté ponerlo fontsize=\footnotesizeen diferentes lugares del preámbulo, pero no funcionó. ¿Alguna sugerencia?

Respuesta1

Añadir :\footnotesizebasicstyle

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{fourier}

\usepackage[scaled]{beramono}
\usepackage{listings}
\lstset{
  language=Python,
  showstringspaces=false,
  formfeed=\newpage,
  tabsize=4,
  commentstyle=\itshape,
  basicstyle=\ttfamily\footnotesize,
  morekeywords={models, lambda, forms},
}
\newcommand{\code}[2]{%
  \hrulefill
  \subsection*{#1}%
  \lstinputlisting{#2}%
  \vspace{2em}%
}

\begin{document}

This is the code from my file \texttt{mycode.py}:

\begin{lstlisting}
def factorial(n):
    """The factorial of a number the slow way"""

    # comments are printed in italic
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)
\end{lstlisting}


\end{document}

ingrese la descripción de la imagen aquí

Sin embargo, también deberías reducir un poco más el tamaño de Bera Mono; en este caso, \footnotesizeno parece necesario.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{fourier}

\usepackage[scaled=0.8]{beramono}
\usepackage{listings}
\lstset{
  language=Python,
  showstringspaces=false,
  formfeed=\newpage,
  tabsize=4,
  commentstyle=\itshape,
  basicstyle=\ttfamily\footnotesize,
  morekeywords={models, lambda, forms},
}
\newcommand{\code}[2]{%
  \hrulefill
  \subsection*{#1}%
  \lstinputlisting{#2}%
  \vspace{2em}%
}

\begin{document}

This is the code from my file \texttt{mycode.py}:

\begin{lstlisting}
def factorial(n):
    """The factorial of a number the slow way"""

    # comments are printed in italic
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)
\end{lstlisting}


\end{document}

ingrese la descripción de la imagen aquí

información relacionada