
다음을 사용하여 문서에 Python 코드를 입력하려고 합니다.이것템플릿을 사용하는 템플릿목록패키지. 그러나 코드 글꼴의 크기, 즉 언급된 내용 \texttt{}
과 lstlisting
환경을 변경하고 싶습니다.
\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}
fontsize=\footnotesize
서문의 다른 위치에 넣으려고 시도했지만 작동하지 않았습니다. 어떤 제안이 있으십니까?
답변1
\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}
그러나 Bera Mono의 규모도 좀 더 줄여야 합니다. 이 경우에는 \footnotesize
필요하지 않은 것 같습니다.
\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}