环境(对齐、铸造等)前的间距不一致,前面有空行和没有空行

环境(对齐、铸造等)前的间距不一致,前面有空行和没有空行

在 minted 和 align 环境之前有一个空行似乎会对布局产生很大的影响。我更希望 latex 始终强制执行一致的布局,而不管\baselineksip我是否有空行。这可能吗?

我已经实现了 verbatim 和 itemize 的一致性,但我在 minted 和 align 环境中遇到了困难,请参阅带有示例的图片:

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

我在这里包含了我的乳胶,我已经尝试过这样做但失败了:

\documentclass[
12pt,%
oneside,%
a4paper%
]{memoir}
\setlength{\parskip}{\baselineskip}%
\setlength{\parindent}{0pt}%
\setlength{\partopsep}{-\baselineskip}
\setlength{\topsep}{0pt}

%% Language setup
 \usepackage{babel}% Language setup

%% Math setup
 \usepackage[fleqn]{amsmath}% Advanced math (before fonts), with fleqn option to align equations to left
 \usepackage{amsfonts,amssymb,amsthm}              % extra math fonts
 \renewcommand{\theequation}{\roman{equation}}     % roman numbering for equations in align environment

%% Font setup
 \usepackage{lmodern}
 \usepackage[T1]{fontenc}
 \usepackage{textcomp}% Additional text character
 \usepackage{bm}% Bold math symbols (after fonts)
 \usepackage{verbatim}

%% Graphics and Color
\usepackage{graphicx}% Graphicx
\usepackage{color}% Color setup

%% Code Highlighting
\usepackage{minted}
\usemintedstyle{tango}

%% Drawing
\usepackage{tikz}
\usetikzlibrary{positioning}

%% Extra Symbols
%mathbin can be used to create other binary operators that are also well layed out, see https://www.overleaf.com/learn/latex/Spacing_in_math_mode

%% Margins
\usepackage{geometry}
 \geometry{
 a4paper,
 left=25mm,
 right=25mm,
 top=25mm,
 bottom=25mm
 }

%% Spacing

\usepackage{enumitem}
\setlist{itemsep=.5\baselineskip, parsep=0pt, topsep=-.5\baselineskip, partopsep=0pt} % remove the extra spaces before and after itemize and set the remaining space between items to be half of the space between paragraphs.

%% etoolbox allows the use of apptocmd and patchcmd below
\usepackage{etoolbox}

% Remove parenthesis around Definition, Example, etc's optional title.
% For example, the parenthesis found here:
% Definition 3.2.1 (Regular Expression Tree).
\patchcmd{\thmhead}{(#3)}{#3}{}{}

% Remove extra lines before and after verbatim
\makeatletter
\preto{\@verbatim}{\topsep=0pt \partopsep=0pt }
\makeatother

%% Hyperlinks
\usepackage{hyperref}

\title{Consistent Spacing Around Environments}

\begin{document}

%% Spacing before and after align environment for equations

% These parameters must be set after
% https://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics#Adjusting_vertical_white_space_around_displayed_math
\setlength{\abovedisplayskip}{-\baselineskip}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{-\baselineskip}
\setlength{\belowdisplayshortskip}{0pt}
\setlength{\mathindent}{0pt}

%% Chapters

\chapter{verbatim is consistent}

First verbatim with empty line is consistent with second one:

\begin{verbatim}
<html>
  <head>
    <title>My Title</title>
  </head>
  <body>
    <p>First Paragraph</p>
    <p>Second Paragraph</p>
  </body>
</html>
\end{verbatim}

Followed by an empty line.

Second verbatim without empty line is consistent with top one:
\begin{verbatim}
<html>
  <head>
    <title>My Title</title>
  </head>
  <body>
    <p>First Paragraph</p>
    <p>Second Paragraph</p>
  </body>
</html>
\end{verbatim}
Followed by no empty line.

\chapter{Minted has inconsistencies}

First minted environment with an empty line (this is what I want for both cases):

\begin{minted}{coq}
Inductive regex :=
  | empty_set : regex
  | empty_string : regex
  | symbol : char -> regex
  | concat : regex -> regex -> regex
  | or : regex -> regex -> regex
  .
\end{minted}

Followed by an empty line.

Second minted environment without an empty line has excessive space:
\begin{minted}{coq}
Inductive regex :=
  | empty_set : regex
  | empty_string : regex
  | symbol : char -> regex
  | concat : regex -> regex -> regex
  | or : regex -> regex -> regex
  .
\end{minted}
Followed by no empty line, but again excessive space.

\chapter{Align has inconsistencies}

First align environment with empty line (This is what I want for both cases):

\begin{alignat*}{3}
e,f & = \\ 
&      &&\emptyset && \text{ the empty set}; \\
&\mid && \epsilon && \text{ the empty string}; \\
&\mid && a        && \text{ a $\in$ $\Sigma$}; \\
&\mid && e, f     && \text{ the concatenation of } e \text{ and } f; \\
&\mid && e \mid f && \text{ the union of } e \text{ and } f;
\end{alignat*}

Another empty line here.

Second align environment without empty line (clearly this is bad, I want it to look like the one above without the user needing the add an empty line):
\begin{alignat*}{3}
e,f & = \\ 
&      &&\emptyset && \text{ the empty set}; \\
&\mid && \epsilon && \text{ the empty string}; \\
&\mid && a        && \text{ a $\in$ $\Sigma$}; \\
&\mid && e, f     && \text{ the concatenation of } e \text{ and } f; \\
&\mid && e \mid f && \text{ the union of } e \text{ and } f;
\end{alignat*}
No empty line here either.

\chapter{itemize is consistent}

First itemize with empty line

\begin{itemize}
    \item call
    \item return
    \item internal
\end{itemize}

Followed by empty line.

Second itemize without empty line
\begin{itemize}
    \item call
    \item return
    \item internal
\end{itemize}
Followed by no empty line.


\end{document}

相关内容