增加浮动页面的边距

增加浮动页面的边距

我的文章有几个部分,每个部分都有一个相当大的(约 22 行)代码列表,解释该特定部分的概念。

我确实想让列表浮动,因为如果将它们拆分到另一页,它们看起来会很糟糕。但是,LaTeX 决定,当我使用浮动时,一页只能容纳一个代码列表。通过增加顶部和底部边距,我应该能够每页容纳至少两个浮动,但我显然只想更改包含浮动的页面的边距。我该怎么做?

编辑:我的(重新编写的)MWE:

% !TeX spellcheck = af_ZA
\documentclass[]{article}

\usepackage{listings}
\usepackage[font=bf,skip=\baselineskip]{caption}
\usepackage{xcolor}
\begin{document}

%--------------------------------------
% All document settings
\definecolor{code_grey}{gray}{0.9}
\lstset
{
    language=c++,
    frame=single,
    backgroundcolor=\color{code_grey},
    numbers=left,   
    breaklines=true,
    tabsize=1,
    basicstyle=\ttfamily,
    columns=flexible,
    captionpos=b,   
    xleftmargin=-.15\textwidth,
    xrightmargin=-.15\textwidth,
    float,
}
\renewcommand{\lstlistingname}{\textbf{Kodelys}}
\captionsetup[lstlisting]{font={footnotesize, it}}
\renewcommand{\figurename}{\textbf{Figuur}}
\captionsetup[figure]{font={footnotesize, it}}

\section{Die verskillende soorte plagiaat in programkode}
Some paragraph

\lstinputlisting
[
    label=plag_original,
    linerange=1-22,
    caption=The first listing,
    float=p
]{code.cpp}

\subsection{Woord-vir-woord kopie}
Another paragraph

\subsection{Kodekommentaar verandering}
The last paragraph

\lstinputlisting
[
    label=plag_method2,
    linerange=1-22,
    caption=The second listing - it must preferably share the same page with the first listing!,
    float=p
]
{code.cpp}

\end{document}

并且code.cpp- 我之所以包括这一点,是因为我尝试过的许多解决方案都不起作用\lstinoutlisting

// Original
void BubbleSort(vector<int> &num)
{
    int i, j, flag = 1;// set flag to 1 to start first pass
    int temp;// holding variable
    int numLength = num.length( ); 
    for(i = 1; (i <= numLength) && flag; i++)
    {
        flag = 0;
        for (j=0; j < (numLength -1); j++)
        {
            if (num[j+1] > num[j])// ascending order simply changes to <
            {
                temp = num[j];// swap elements
                num[j] = num[j+1];
                num[j+1] = temp;
                flag = 1;// indicates that a swap occurred.
            }
        }
    }
    return;//arrays are passed to functions by address; nothing is returned
}

相关内容