Edit I completely rewrote the question thanks to @pluton's comment.
I have a couples of documents which have to fit on two pages. Some of them are short, so nothing needs to be done. But for some others, I need to squeeze vertical spacing.
To do so, I created a variable \mylength
which I manually adjust for each document. I would like \mylength
to be the spacing above and below any environment, particularly equation
and the custom environments defi
and theo
.
Following @pluton comment, I integrated \addvspace
. I still have some problems.
This is the result for \mylength
equals to 0pt
. It is meant to check the minimal spacing. The output is almost fine, except:
- the vertical space surrounding the
equation
which, for some reason I don't understand, behaves as if there were text above and below (see above equation (2), above (4), below (5) [I am aware that two equations should not written as so], above (6).
With \mylength
equals to 0pt
:
Now, if I change \mylength
from 0pt
to 8pt
, the result has several problems:
- with no suprise, the space around
equation
is still wrong - the spacing between two
defi
is wrong theo
is not centered when surrounded bydefi
(see Theorem 4)
With \mylength
equals to 8pt
:
Code:
\documentclass[9pt,a4paper]{article}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\usepackage[margin=1.cm,top=1.2cm,bottom=1.3cm,headsep=14pt]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{environ}
\usepackage{tikz}
\usepackage{framed}
\usepackage{amsmath,amsfonts,amssymb}
%%%%%%%%% ENVIRONMENTS %%%%%%%%%%
\newenvironment{mycenter}% to control space after and before environment
{\addvspace{\mylength}\centering}% \begin{mycenter}[<len>]
{\par\addvspace{\mylength}}% \end{mycenter}
\NewEnviron{theo}[1]{%
\begin{mycenter}
\begin{tikzpicture}
\node[rectangle, rounded corners, inner sep=5pt,minimum width=\textwidth,
text=black, text opacity=1,
draw=orange, ultra thick, draw opacity=1,
fill=orange, fill opacity=.3]
(box){%
\begin{minipage}{.95\textwidth}
\textbf{#1}\qquad\BODY
\end{minipage}};
\end{tikzpicture}
\end{mycenter}
}
% for adjustwidth environment
\usepackage[strict]{changepage}
% for definitions
\definecolor{defishade}{rgb}{0.97,0.97,.99}
\newenvironment{defi}{%
\vspace{-1.2mm} % UGLY MANUAL ADJUSTEMENT
\par\addvspace{\mylength}
\setlength{\topsep}{0pt}
\def\FrameCommand{%
\hspace{1pt}%
{\color{black!70}\vrule width 2pt}%
{\color{defishade}\vrule width 4pt}%
\colorbox{defishade}%
}%
\MakeFramed{\advance\hsize-\width\FrameRestore}%
\noindent\hspace{-4.55pt}% disable indenting first paragraph
% \vspace{-8pt}
\begin{adjustwidth}{0pt}{7pt}%
\vspace{1.5pt}\vspace{2pt}%
\textcolor{black!70}{ \textbf{Definition}\qquad}
}
{%
\vspace{2pt}
\end{adjustwidth}\endMakeFramed%
\vspace{.5mm}
\addvspace{\mylength}
}
\begin{document}\thispagestyle{empty}
\def\mylength{0pt}
\setlength{\belowdisplayskip}{\mylength} \setlength{\belowdisplayshortskip}{\mylength}
\setlength{\abovedisplayskip}{\mylength} \setlength{\abovedisplayshortskip}{\mylength}
\paragraph{Environment theo} First, let's check this environment.
\begin{theo}{Theorem} If blah blah blah then
\begin{equation}
1+1=2
\end{equation}
\end{theo}
Everything's fine here.
\begin{theo}{Theorem} If blah blah blah then nothing.
\end{theo}%
\begin{theo}{Theorem} If blah blah blah then nothing.
\end{theo}%
Everything's fine here.
\begin{theo}{Theorem} If blah blah blah then nothing.
\end{theo}%
\begin{equation}1-1=0\end{equation}
\textcolor{red}{\bf Why is the distance between the above equation and the theorem so large?}
\paragraph{Environment defi} Now, let's check this second environment.
\begin{defi}Below, it's OK for \verb?0pt? and \textcolor{red}{too large} for \verb?8pt?.\end{defi}
\begin{defi}Nothing special.\end{defi}
Spacing is OK for 0pt but not centered (vertically) as between the two first theorems for 10pt.\begin{defi}Here, it's OK.\end{defi}
\begin{theo}{Theorem 2} If blah blah blah then
\begin{equation}
1+1=2
\end{equation}
\end{theo}
\begin{equation}
2+3=5 \text{ when two environments are following eachother, the vertical spacing adds up.}
\end{equation}
\begin{equation}
1+1=2
\end{equation}%
%qsdfqsdf
\begin{defi}\textcolor{red}{\bf Why is the distance between the above equation and the present, and previous definitions, so large?}
\end{defi}
\begin{theo}{Theorem 4} \textcolor{red}{Theorem is not centered between two definitions for 8pt.}
\end{theo}%
\begin{defi}\textcolor{red}{Space too large below for 10pt.}\end{defi}
\begin{equation}
1+1=2%
\end{equation}%
%sdfqssddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
\begin{defi}Kombucha is a bloh bloh bloh.\end{defi}
\end{document}
\def\mylength{10pt}
.10pt
is constant.\addvspace
command: forkosh.com/latex/ltx-198.html