
내 문서에 소스 코드를 배치하기 위해 패키지를 사용하고 있었는데 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
"제목 따르기"에 대한 근사치로 사용합니다. 이는 제목 뒤 페이지 나누기를 방지하기 위해 라텍스가 사용하는 내부 스위치입니다.
\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}