设置自定义新环境的垂直间距

设置自定义新环境的垂直间距

我定义了一个code环境,其中的minted环境按顺序排列,以跨越多个页面。问题是标题离框架旁边的文本太近了code。我该如何增加它并默认应用它?

这是 MRE

\documentclass[corpo=11pt,twoside,tipotesi=magistrale,greek]{toptesi}

\usepackage[a-2b]{pdfx}

\usepackage{geometry}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{listings}
\usepackage[newfloat]{minted}
\usemintedstyle{bw}
\setminted{
    linenos,
    breaklines,
    breakanywhere,
    % framesep=4mm,
    % bgcolor=lbg,
}
\AtBeginEnvironment{minted}{%
\renewcommand{\fcolorbox}[4][]{#4}}

\newenvironment{code}{\captionsetup{type=listing}}{}
\SetupFloatingEnvironment{listing}{name=Listato}

\usepackage{lipsum}

\begin{document}\errorcontextlines=9

\lipsum[1]

\begin{code}
    \begin{minted}{json}
    {
        "@context": [
            "https://www.w3.org/ns/did/v1"
        ],
        "id": "did:ott:POLYARUCUR9ANFHKACMBZIBONMMTDXBRYG9CCGRZTOE9QLDOQKFVTNAOWSPXGIPPQDNQDPFWVT9KSERQN",
        "created": "2021-10-25T18:43:48.074918",
        "authenticationMethod": {
            "id": "did:ott:POLYARUCUR9ANFHKACMBZIBONMMTDXBRYG9CCGRZTOE9QLDOQKFVTNAOWSPXGIPPQDNQDPFWVT9KSERQN#keys-1",
            "type": "RsaVerificationKey2018",
            "controller": "did:ott:POLYARUCUR9ANFHKACMBZIBONMMTDXBRYG9CCGRZTOE9QLDOQKFVTNAOWSPXGIPPQDNQDPFWVT9KSERQN",
            "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0n12lUROi9VVZoFDan1O...\n-----END PUBLIC KEY-----\n"
        },
        "assertionMethod": {
            "id": "did:ott:POLYARUCUR9ANFHKACMBZIBONMMTDXBRYG9CCGRZTOE9QLDOQKFVTNAOWSPXGIPPQDNQDPFWVT9KSERQN#keys-2",
            "type": "RsaVerificationKey2018",
            "controller": "did:ott:POLYARUCUR9ANFHKACMBZIBONMMTDXBRYG9CCGRZTOE9QLDOQKFVTNAOWSPXGIPPQDNQDPFWVT9KSERQN",
            "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzYhPXrHwvGE9bq8hTzA1...\n-----END PUBLIC KEY-----\n"
        },
        "services": []
    }
    \end{minted}
    \caption{Esempio di DID document in formato JSON.}
    \label{lst:did-doc}
\end{code}

\lipsum[1]

\end{document}

我指的空间在下图中突出显示

在此处输入图片描述

我还希望我所尝试实现的目标从印刷角度来看是否良好。

答案1

用于\newenvironment{code}{\captionsetup{type=listing}}{\par\addvspace{13pt plus2pt minus1pt}}在环境末尾添加一些可拉伸的空间。

A

答案2

我认为您应该使用\newfloat而不是\newenvironment

\documentclass[corpo=11pt,twoside,tipotesi=magistrale,greek]{toptesi}
\usepackage[T1]{fontenc}
\usepackage{fix-cm}

\usepackage[a-2b]{pdfx}

\usepackage{geometry}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{listings}
\usepackage[newfloat]{minted}
\usemintedstyle{bw}
\setminted{
    linenos,
    breaklines,
    breakanywhere,
    % framesep=40mm,
    % bgcolor=lbg,
}
\AtBeginEnvironment{minted}{\renewcommand{\fcolorbox}[4][]{#4}}

\DeclareFloatingEnvironment[
  fileext=lml,
  listname={Elenco dei listati},
  name=Listato,
  placement=htp,
]{code}
\captionsetup[code]{
   position=below,
   aboveskip=0pt,
%   belowskip=6pt,
}

\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{code}
    \begin{minted}{json}
    {
        "@context": [
            "https://www.w3.org/ns/did/v1"
        ],
        "id": "did:ott:POLYARUCUR9ANFHKACMBZIBONMMTDXBRYG9CCGRZTOE9QLDOQKFVTNAOWSPXGIPPQDNQDPFWVT9KSERQN",
        "created": "2021-10-25T18:43:48.074918",
        "authenticationMethod": {
            "id": "did:ott:POLYARUCUR9ANFHKACMBZIBONMMTDXBRYG9CCGRZTOE9QLDOQKFVTNAOWSPXGIPPQDNQDPFWVT9KSERQN#keys-1",
            "type": "RsaVerificationKey2018",
            "controller": "did:ott:POLYARUCUR9ANFHKACMBZIBONMMTDXBRYG9CCGRZTOE9QLDOQKFVTNAOWSPXGIPPQDNQDPFWVT9KSERQN",
            "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0n12lUROi9VVZoFDan1O...\n-----END PUBLIC KEY-----\n"
        },
        "assertionMethod": {
            "id": "did:ott:POLYARUCUR9ANFHKACMBZIBONMMTDXBRYG9CCGRZTOE9QLDOQKFVTNAOWSPXGIPPQDNQDPFWVT9KSERQN#keys-2",
            "type": "RsaVerificationKey2018",
            "controller": "did:ott:POLYARUCUR9ANFHKACMBZIBONMMTDXBRYG9CCGRZTOE9QLDOQKFVTNAOWSPXGIPPQDNQDPFWVT9KSERQN",
            "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzYhPXrHwvGE9bq8hTzA1...\n-----END PUBLIC KEY-----\n"
        },
        "services": []
    }
    \end{minted}
    \caption{Esempio di DID document in formato JSON.}
    \label{lst:did-doc}
\end{code}

\lipsum[1]

\end{document}

在此处输入图片描述

请记住,如果您用意大利语书写,fontencT1必须使用此选项。fix-cm建议使用 Also,这样您就不会收到大量的字体警告。

删除该\errorcontextlines=9行,或者,如果您确实需要它,请将其放在最开头。无论如何,请将其从此处的示例中删除。

相关内容