I have some troubles with spacing when using minipages to keep some content together.
\documentclass[a4paper,10pt,notitlepage]{article}
\usepackage{geometry}
\geometry{
a4paper,
head=20mm,
left=20mm,
right=10mm,
top=25mm,
bottom=25mm,
foot=8mm
}
\usepackage[default,scale=0.95]{opensans} %Schriftart FEHLER
\usepackage{tabularx}
\usepackage{booktabs} % use package booktabs for easy creating tables
\usepackage{caption}
\usepackage{subcaption}
\usepackage[table]{xcolor}
\usepackage{setspace}
\usepackage{floatflt,epsfig}
\usepackage{blindtext}
\usepackage[flushleft]{threeparttable} % to have a dedicated notes section after tables
\usepackage{titlesec}
\setlength{\fboxsep}{0pt}%
\setlength{\fboxrule}{1pt}%
\setlength{\abovecaptionskip}{7pt}
\setlength{\belowcaptionskip}{7pt}
\setlength{\textfloatsep}{10pt}
\linespread{1.0}
\setlength{\parindent}{0pt} % verhindert Absatzeinrueckung nach Bildern
\usepackage[framemethod=tikz]{mdframed}
% CAPTION STYLE
\DeclareCaptionFormat{labelstyle}{% <- needed
\setlength\fboxsep{3pt}% <- needed
\colorbox{blue}{{#1}}#2#3%
}
\definecolor{blue}{HTML}{336699}
\captionsetup[table]{singlelinecheck=false, labelfont={color=white}} % Rechtsbündige Tabellen und Bildbeschreibung
\captionsetup[figure]{format=labelstyle, labelfont={color=white},
justification=raggedright,% <- only needed if longer captions should not be justified
singlelinecheck=false% <- added
}
% SECTION STYLE
% -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
\titleformat{\section}
{\Large\bfseries\color{blue}}
{\thesection}{1em}{} %\titleformat{\section}{\Large\bfseries\color{blue}}{\thesection}{1em-Abstand}
\titleformat{\subsection}
{\large\bfseries\color{blue}}
{\thesubsection}{1em}{} %\titleformat{\section}{\Large\bfseries\color{blue}}{\thesection}{1em-Abstand}
\titleformat{\subsubsection}
{\bfseries\color{blue}}
{\thesubsubsection}{1em}{} %\titleformat{\section}{\Large\bfseries\color{blue}}{\thesection}{1em-Abstand}
% -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
\newcommand{\astroltable} {
\captionsetup{type=table, format=labelstyle}
\arrayrulecolor{blue}
% \aboverulesep = 0mm
% \belowrulesep = 0mm
}
\newenvironment{tableenv}[2]{
\everypar{}
\def\tablecaption{#1}
\def\tablelabel{tab:#2}
\begin{center}
\begin{footnotesize}
\astroltable
\begin{threeparttable}
}{
\end{threeparttable}
\caption{\tablecaption}
\label{\tablelabel}
\end{footnotesize}
\end{center}}
\begin{document}
\section{A section}
\begin{minipage}{\textwidth}
\subsection{A subsection}
\blindtext
\begin{tableenv}{blubb}{blubb}
\begin{tabularx}{\textwidth}{p{0.2\textwidth}p{0.25\textwidth}Xp{0.075\textwidth}p{0.075\textwidth}p{0.075\textwidth}p{0.075\textwidth}}
\toprule
\textbf{City} & \textbf{Country} & \textbf{min.} & \textbf{typ.} & \textbf{max.} & \textbf{Rate} \\ \midrule
New York & US and A & - & 1.0 & - & n/a \\ \bottomrule
\end{tabularx}
\end{tableenv}
\end{minipage}
\strut
\blindtext
\begin{tableenv}{blubb2}{blubb2}
\begin{tabularx}{\textwidth}{p{0.2\textwidth}p{0.25\textwidth}Xp{0.075\textwidth}p{0.075\textwidth}p{0.075\textwidth}p{0.075\textwidth}}
\toprule
\textbf{City} & \textbf{Country} & \textbf{min.} & \textbf{typ.} & \textbf{max.} & \textbf{Rate} \\ \midrule
New York & US and A & - & 1.0 & - & n/a \\ \bottomrule
\end{tabularx}
\end{tableenv}
\blindtext
\end{document}
One problem is the missing space above Table 1, this is introduced with the use of the titlesec package and seems to be caused if the minipage starts with a sectiontitle. Is there a way to correct this?
The other problem is the space between the caption of Table 1 and the following text which is different from Table 2.


\parskipI can address the 2nd issue, but it causes the skip beforeTable 2behave the same way asTable 1then no matter if I use thetitlesecpackage or not. – po.pe Mar 04 '20 at 08:56\strutat the start of the paragraph won't affect the spacing there as the usual baselineskip is in effect). The page won't break after a section heading or within the table, s do you need the minipage at all? – David Carlisle Mar 04 '20 at 09:23minipageto keep the text and the table together. What would be a proper way of grouping Latex elements (paragraphs, tables, figures etc.)? Manually adding\pagebreaksis not what I want to end up with in a 200 pages document. – po.pe Mar 04 '20 at 09:55