1

I'm searching for a MWE to get equal distances between text and all environments in my document.

Equal distances mean in this case:

  1. Distance between text and the upper border of the environment

  2. Distance between caption and text

In the attached MWE, you can see that there are always other distances. So how can I fix it?

\documentclass[fontsize=12pt,twoside=false,]{scrbook}
\usepackage[ngerman]{isodate,babel}
\usepackage{listings}
\usepackage{float}
\usepackage{caption}
\usepackage{hhline}
\usepackage{ltablex}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{blindtext} % Just for the MWE

\DeclareCaptionType{equ}[][]
\setlength\parindent{0pt}
\begin{document}

%Listing with and without minipage environment
\blindtext
\begin{minipage}[t]{\linewidth}
\begin{lstlisting}[captionpos=b,caption={[Listing]{Listing}}]
Code Code Code
\end{lstlisting}
\end{minipage}
\blindtext
\blindtext
\begin{lstlisting}[captionpos=b,caption={[Listing]{Listing}}]
Code Code Code
\end{lstlisting}
\blindtext
\newpage
%Tabularx environment
\blindtext
\begin{tabularx}{\textwidth}{|l|p{33mm}|l|>{\arraybackslash}X|}
\hline
\endfirsthead
Test & Test & Test & Test\\ 
\hline 
\caption[Tabularx]{Tabularx}
\end{tabularx}
\blindtext
\newpage
%Figure environment
\blindtext
\begin{figure}[H]
\centering
\includegraphics[width=3cm]{example-image}
\caption{Figure}
\end{figure}
\blindtext
\newpage
%Equation environment
\blindtext
\begin{equ}[!ht]
\begin{equation}
a=b+c
\end{equation}
\caption{Caption of the equation}
\end{equ}
\blindtext
\end{document}

enter image description here

enter image description here

enter image description here

enter image description here

This question seems to be similar to this one, but asks for more environments.

PascalS
  • 826
  • Could you please make your code compilable? Currently, it isn't since Example.json is not available. – leandriis Oct 03 '19 at 13:41
  • @leandriis Sorry, did it now! – PascalS Oct 03 '19 at 13:47
  • Fixing this vertical distances is not good idea. They normally contain stretchable glue which enables that (La)TeX can nice format of document pages. – Zarko Oct 04 '19 at 13:57
  • @Zarko Okay... but could you give me a hint how to achieve the same spaces for listings with and without a minipage? – PascalS Oct 04 '19 at 13:59
  • That is my biggest issue so far... – PascalS Oct 04 '19 at 14:00
  • Why you like to enclose listings in minipage? Do you have some special reason? From MWE i don't see this. I wouldn't put listing in minipage. – Zarko Oct 04 '19 at 14:15
  • I need the minipage to prevent line breaks within the listings. – PascalS Oct 04 '19 at 14:17
  • This is (typographically) wrong approach. Listing is deliberately designed so that can be split over more pages. If it is inside minipage , minipage can leave a lot of empty spaces on previous page (when is moved to the next page) . However i such a cases you cam manually correct vertical distances, for example as: \begin{minipage}t]\linewidth}\vspace{-0.5\baselineskip} \begin{lstlisting}[captionpos=b,caption={[Listing]{Listing}}] Code Code Code \end{lstlisting} \end{minipage} – Zarko Oct 04 '19 at 14:23
  • Thanks for your reply even if it is the wrong approach :) I have often used the way you suggested but I would like to know the exact value for the \vspace{} command. Is there a macro with defines the space skip of the minipage? – PascalS Oct 04 '19 at 14:28
  • or simply left out option [t] at minipage. You will have to wait for an expert to answer your . – Zarko Oct 04 '19 at 14:32
  • Perfect! Thats a way in the right direction! Now the spaces are to small but equal! – PascalS Oct 04 '19 at 14:41

0 Answers0