How to get rid of space between section and equation
Use \noindent
before \begin{equation}
:
\section{Section}
\noindent\begin{equation*}
q = q_0 + q_1i + q_2j + q_3k = (q_0,q_1,q_2,q_3)
\end{equation*}
The reason: TeX operates in vertical mode after \section
. If display math starts in vertical mode, the horizontal mode is opened immediately and the line with \parindent
is preceded. But you can avoid this line when there is no \parindent
. This can be done by \noindent
.
You can insert \noindent
before each \begin{equation}
: if the horizontal mode is opened already the \noindent
does nothing. You can create your macro which generates \noindent\begin{equation}
or re-define \begin{equation}
.
For a cheatsheet, I believe it's better to redefine \section
and \subsection
.
\documentclass[8pt]{extarticle}
\usepackage[paper=a5paper]{geometry}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{amssymb}
\renewcommand{\section}[1]{%
\par
\stepcounter{section}%
\everypar{\textbf{\thesection\ #1}\quad\everypar{}}%
}
\renewcommand{\subsection}[1]{%
\par
\stepcounter{subsection}%
\everypar{\textbf{\thesubsection\ #1}\quad\everypar{}}%
}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}
\setlength{\lineskip}{0pt}
\AtBeginDocument{%
\setlength\abovedisplayskip{0pt}%
\setlength\belowdisplayskip{0pt}%
\setlength\abovedisplayshortskip{0pt}%
\setlength\belowdisplayshortskip{0pt}%
}
\begin{document}
\section{Section}
\begin{equation*}
q = q_0 + q_1i + q_2j + q_3k = (q_0,q_1,q_2,q_3)
\end{equation*}
\section{Section}
Some text for explaining the following equation
\begin{equation*}
q = q_0 + q_1i + q_2j + q_3k = (q_0,q_1,q_2,q_3)
\end{equation*}
More text follows the equation
\end{document}
Two ways to solve your problem:
\documentclass[8pt]{extarticle}
\usepackage[paper=a5paper]{geometry}
\usepackage[english]{babel}
%\usepackage{parskip}
%\setlength{\parindent}{0pt}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{titlesec}
\titlespacing{\section}{0pt}{0pt}{0pt}
\titlespacing{\subsection}{0pt}{0pt}{0pt}
\titlespacing{\subsubsection}{0pt}{0pt}{0pt}
\def\mycommand{\setlength{\abovedisplayskip}{0pt}%
\setlength{\belowdisplayskip}{0pt}%
\setlength{\abovedisplayshortskip}{0pt}%
\setlength{\belowdisplayshortskip}{0pt}}
\AtBeginDocument{\mycommand}
\let\oldnormalsize\selectfont
\def\selectfont{\oldnormalsize\mycommand}
\newenvironment{myeq}{\vspace{-10pt}\par\begin{equation*}}{\end{equation*}\vspace{-10pt}}
\newsavebox{\mybox}
\newlength{\mylength}
\def\myinleq#1{\savebox\mybox{$#1$}\settowidth{\mylength}{\usebox{\mybox}}\hspace{0.5\dimexpr\linewidth-\mylength-2\parindent\relax\relax}$#1$}
\begin{document}
\section{Section}
\begin{myeq}
q = q_0 + q_1i + q_2j + q_3k = (q_0,q_1,q_2,q_3)
\end{myeq}
\begin{myeq}
q_2 = q_0 + q_1i + q_2j + q_3k = (q_0,q_1,q_2,q_3)
\end{myeq}%emptyline needed here
\myinleq{q_3 = q_0 + q_1i + q_2j + q_3k = (q_0,q_1,q_2,q_3)}
\section{Section}
\noindent Some text
\begin{equation*}
q = q_0 + q_1i + q_2j + q_3k = (q_0,q_1,q_2,q_3)
\end{equation*}
More text
\end{document}