リスト環境では、aboveskip、belowskip を使用してセクション タイトルの下にスペースを挿入しないでください。

リスト環境では、aboveskip、belowskip を使用してセクション タイトルの下にスペースを挿入しないでください。

パッケージを使用してlistingsドキュメントにソース コードを配置していたところ、テキストとlstlisting環境の間のスペースが小さすぎることに気付きました。そこで、\aboveskipおよび\belowskipプロパティを変更しました。

問題は、私が言及したスペースに加えて、セクション ヘッダーとlstlisting環境の間のスペースにも影響が及び、それが役に立たず、煩わしいことです。また、ドキュメントの外観も良くありません。

また、環境と改ページ間または新しいページの先頭のスペースで同じ動作が行われるかどうかもわかりません (行われるのでしょうか?)。または、LaTeX がそのスペースを自動的に消去するかどうかもわかりません (実際にそこにもスペースが挿入されている場合)。

私の質問は、スペースが挿入されるのを防ぎ\aboveskip\belowskipセクション ヘッダー、ページ区切り、およびページの先頭の間のスペースに影響を与えるにはどうすればよいかということです。

これには以下は含まれません\aboveskip:

ここに画像の説明を入力してください

\aboveskip=1.5cmこれは、(セクション タイトルの下の「不要な」スペースを示すために過剰な数値が使用されています)次のとおりです。

ここに画像の説明を入力してください

\documentclass[12pt]{article}

\usepackage{parskip}

\setlength{\parindent}{0cm}

\usepackage{fontspec}

\usepackage[english,greek]{babel}

\usepackage[fleqn]{amsmath}

\usepackage{unicode-math}

\usepackage{listings}

\setmainfont
[
  Ligatures=TeX,
  Extension=.otf,
  UprightFont=*,
  BoldFont=*Bold,
  ItalicFont=*It,
  BoldItalicFont=*BoldIt,
  Mapping=tex-text
]{GFSArtemisia}

\setsansfont[Mapping=tex-text]{GFSArtemisia.otf}

\setmathfont{latinmodern-math.otf}

\setmathfont[range=\varnothing]{Asana-Math.otf}

\setmathfont[range=\int]{latinmodern-math.otf}

\begin{document}

\lstset
{
    aboveskip=1.5cm,
    frame=tb,
    rulecolor=\color{black},
    basicstyle=\ttfamily\color{BrickRed},
    columns=flexible,
    morecomment=[s][\color{NavyBlue}]{/*}{*/}
}

\section*{Section Title}

\begin{lstlisting}

Source code here.

\end{lstlisting}

Text here!

\begin{lstlisting}

More source code here.

\end{lstlisting}

More text here!

\end{document}

答え1

この要件は少し奇妙に思えますが、とにかく、テストしたい内容に基づいて値を任意の次元に拡張することができます。ここでは、\if@nobreaktrue「見出しに従う」の近似値として使用します。これは、見出しの後の改ページを回避するために LaTeX が使用する内部スイッチです。

\documentclass[12pt]{article}

\usepackage{parskip}

\setlength{\parindent}{0cm}

\usepackage{fontspec}

\usepackage[english,greek]{babel}

\usepackage[fleqn]{amsmath}

\usepackage{unicode-math}

\usepackage{listings}

\setmainfont
[
  Ligatures=TeX,
  Extension=.otf,
  UprightFont=*,
  BoldFont=*Bold,
  ItalicFont=*It,
  BoldItalicFont=*BoldIt,
  Mapping=tex-text
]{GFSArtemisia}

\setsansfont[Mapping=tex-text]{GFSArtemisia.otf}

\setmathfont{latinmodern-math.otf}

\setmathfont[range=\varnothing]{Asana-Math.otf}

\setmathfont[range=\int]{latinmodern-math.otf}

\begin{document}

\makeatletter
\lstset
{
    aboveskip={\if@nobreak 0pt\else 1.5cm\fi},
    frame=tb,
    rulecolor=\color{black},
    basicstyle=\ttfamily\color{BrickRed},
    columns=flexible,
    morecomment=[s][\color{NavyBlue}]{/*}{*/}
}
\makeatother
\section*{Section Title}

\begin{lstlisting}

Source code here.

\end{lstlisting}

Text here!

\begin{lstlisting}

More source code here.

\end{lstlisting}

More text here!

\end{document}

関連情報