我正在尝试添加一个环境,以便将代码列表保留在一个页面上,如“如何防止 lstlisting 在页面之间分割代码?“。
当我的列表位于页面底部时,页码将显示在环境内。如何强制页码显示在环境之外?
下面是一个示例。在这种情况下,环境占据了整个页面。如果可能的话,当页码会导致到达页面边界时,我希望完全删除页码。
\documentclass{scrreprt}
\usepackage{bera}
\usepackage{listings}
\usepackage[usenames,dvipsnames]{xcolor}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\definecolor{pred}{rgb}{0.9,0,0}
\definecolor{pgrey}{rgb}{0.46,0.45,0.48}
\lstset{
basicstyle=\normalfont\ttfamily,
numbers=left,
numberstyle=\scriptsize,
stepnumber=1,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
frame=lines,
backgroundcolor=\color{background},
showspaces=false,
showtabs=false,
breaklines=true,
showstringspaces=false,
breakatwhitespace=true,
commentstyle=\color{pgreen},
keywordstyle=\color{pblue},
stringstyle=\color{pred},
basicstyle=\ttfamily,
moredelim=[il][\textcolor{pgrey}]{$$},
moredelim=[is][\textcolor{pgrey}]{\%\%}{\%\%}
}
\lstnewenvironment{code}[1][]%
{
\noindent
\minipage{\linewidth}
\vspace{0.5\baselineskip}
\lstset{basicstyle=\ttfamily\footnotesize,frame=single,#1}}
{\endminipage}
\begin{document}
\begin{figure}[H]
\begin{code}[language=Java]
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
public class SesSmtpCredentialGenerator {
private static final String KEY_ENV_VARIABLE = "AWS_SECRET_ACCESS_KEY"; // Put your AWS secret access key in this environment variable.
private static final String MESSAGE = "SendRawEmail"; // Used to generate the HMAC signature. Do not modify.
private static final byte VERSION = 0x02; // Version number. Do not modify.
public static void main(String[] args) {
// Get the AWS secret access key from environment variable AWS_SECRET_ACCESS_KEY.
String key = System.getenv(KEY_ENV_VARIABLE);
if (key == null)
{
System.out.println("Error: Cannot find environment variable AWS_SECRET_ACCESS_KEY.");
System.exit(0);
}
// Create an HMAC-SHA256 key from the raw bytes of the AWS secret access key.
SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "HmacSHA256");
try {
// Get an HMAC-SHA256 Mac instance and initialize it with the AWS secret access key.
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(secretKey);
// Compute the HMAC signature on the input data bytes.
byte[] rawSignature = mac.doFinal(MESSAGE.getBytes());
// Prepend the version number to the signature.
byte[] rawSignatureWithVersion = new byte[rawSignature.length + 1];
byte[] versionArray = {VERSION};
System.arraycopy(versionArray, 0, rawSignatureWithVersion, 0, 1);
System.arraycopy(rawSignature, 0, rawSignatureWithVersion, 1, rawSignature.length);
// To get the final SMTP password, convert the HMAC signature to base 64.
String smtpPassword = DatatypeConverter.printBase64Binary(rawSignatureWithVersion);
System.out.println(smtpPassword);
}
catch (Exception ex) {
System.out.println("Error generating SMTP password: " + ex.getMessage());
}
}
}
\end{code}
\caption{Java implementation of SES password algorithm\label{fig:ses-password}}
\end{figure}
\end{document}