![调整文本大小并保持颜色框大小相同](https://linux22.com/image/395068/%E8%B0%83%E6%95%B4%E6%96%87%E6%9C%AC%E5%A4%A7%E5%B0%8F%E5%B9%B6%E4%BF%9D%E6%8C%81%E9%A2%9C%E8%89%B2%E6%A1%86%E5%A4%A7%E5%B0%8F%E7%9B%B8%E5%90%8C.png)
嗨,我有一个灰色框,里面有我的 Python 代码,我想减小代码的大小,但保持灰色框的大小不变。这是我的 Latex 代码:
\lstset
{ %Formatting for code in appendix
language={Python},
basicstyle=\fontsize{9}{9}\ttfamily,
numbers=left,
stepnumber=1,
showstringspaces=false,
keywordstyle=\color{blue},
commentstyle=\color{magenta},
stringstyle=\color{ForestGreen},
tabsize=4,
breaklines=true,
breakatwhitespace=false,
}
\fcolorbox{gray}{gray!15}{
\lstinputlisting[language=Python]{./Code/get_zip_files.py}
如果不指定字体大小,输出如下所示:
使用我在顶部提到的代码(包括字体大小),它看起来像这样:
如您所见,框变小了。有没有办法让框保持相同的大小,同时减小字体大小?
答案1
最好是建立框架并listings
提供以下机制:
backgroundcolor=\color{gray!15},
rulecolor=\color{gray},
frame=tlrb
\documentclass{article}
\usepackage{listings,xcolor}
\lstset
{ %Formatting for code in appendix
language={Python},
basicstyle=\fontsize{9}{9}\ttfamily,
numbers=left,
stepnumber=1,
showstringspaces=false,
keywordstyle=\color{blue},
commentstyle=\color{magenta},
stringstyle=\color{green},
tabsize=4,
breaklines=true,
breakatwhitespace=false,
backgroundcolor=\color{gray!15},
rulecolor=\color{gray},
frame=tlrb
}
\begin{document}
\noindent
A full line of text before the sample code.
A full line of text before the sample code.
A full line of text before the sample code.
\begin{lstlisting}[language=Python]
import requests
path = 'A:/Thesis_project/SBP/'
\end{lstlisting}
\end{document}