TeX - LaTeX Asked by Walter Schulze on February 7, 2021
Having an empty line before minted and align environments seems to make a big difference in layout. I would prefer to have latex always enforce a consistent layout with only a baselineksip
whether I have an empty line or not. Is this possible?
I have achieved consistency for verbatim and itemize, but I am struggling with minted and align environments, see pictures with examples:
I include here my latex, where I have already attempt to do this and failed:
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=.5baselineskip, parsep=0pt, topsep=-.5baselineskip, 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}
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP