
Estou tentando inserir meu código Python em um documento usandoessemodelo que usa olistagenspacote. No entanto, quero alterar o tamanho da fonte do código, ou seja, qualquer menção \texttt{}
ao lstlisting
ambiente.
\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}
Tentei colocar fontsize=\footnotesize
lugares diferentes no preâmbulo, mas não funcionou. Alguma sugestão?
Responder1
Adicionar \footnotesize
à basicstyle
:
\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}
No entanto, você também deve reduzir um pouco mais o Bera Mono; neste caso, \footnotesize
não parece necessário.
\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}