当我使用间距来minipages
将一些内容放在一起时,我遇到了一些麻烦。
\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}
一个问题是上面的 缺少空格Table 1
,这是使用titlesec
包时引入的,似乎是由于minipage
以 开头而导致的sectiontitle
。有办法纠正这个问题吗?
另一个问题是 的标题Table 1
和后面的文本之间的空格与 不同Table 2
。
答案1
我认为您遇到的问题与环境的使用没有那么密切的关系。相反,我认为这些问题似乎与宏和环境minipage
的定义存在缺陷有关。您将环境定义为包含 7 列,但实际上只使用了 6 列,这也没有多大帮助。\astroltable
tableenv
tabularx
以下屏幕截图所示的布局是否更接近满足您的目标?
\documentclass[a4paper,10pt,notitlepage]{article}
\usepackage{geometry}
\geometry{a4paper,
head=20mm,foot=8mm,
left=20mm,right=10mm,
top=25mm,bottom=25mm,
}
\usepackage[default,scale=0.95]{opensans}
\usepackage{tabularx,booktabs}
\usepackage{caption,subcaption}
% CAPTION STYLE
\DeclareCaptionFormat{labelstyle}{%
\setlength\fboxsep{3pt}%
\colorbox{myblue}{{#1}}#2#3}
\captionsetup[table]{singlelinecheck=false,
labelfont={color=white}}
\captionsetup[figure]{format=labelstyle,
labelfont={color=white},
justification=raggedright,
singlelinecheck=false}
\usepackage{titlesec}
% SECTION STYLE
\titleformat{\section}{%
\Large\bfseries\color{myblue}}{\thesection}{1em}{}
\titleformat{\subsection}{%
\large\bfseries\color{myblue}}{\thesubsection}{1em}{}
\titleformat{\subsubsection}{%
\bfseries\color{myblue}}{\thesubsubsection}{1em}{}
\usepackage[table]{xcolor}
\definecolor{myblue}{HTML}{336699}
\usepackage{setspace}
%%%%\linespread{1.0} % better: "\singlespacing"
%%%%\usepackage{floatflt,epsfig} % shouldn't be needed
\usepackage{blindtext}
\usepackage[flushleft]{threeparttable}
\usepackage[framemethod=tikz]{mdframed}
\setlength{\fboxsep}{0pt}%
\setlength{\fboxrule}{1pt}%
\setlength{\abovecaptionskip}{7pt}
\setlength{\belowcaptionskip}{10pt}
\setlength{\textfloatsep}{10pt}
\setlength{\parindent}{0pt}
\newcommand{\astroltable}{%
\captionsetup{type=table, format=labelstyle,
skip=0.75\baselineskip} % <-- new (default is 1\baselineskip)
\arrayrulecolor{myblue}}
\newenvironment{tableenv}[2]{% quite a few changes here
\par\medskip
\def\tablecaption{#1}
\def\tablelabel{tab:#2}
\footnotesize % \footnotesize is a macro, not an environment
\astroltable
\begin{threeparttable}
}{%
\caption{\tablecaption}
\label{\tablelabel}
\end{threeparttable} % place this *after* \caption and \label
}
\begin{document}
\section{A section}
\subsection{A subsection}
\begin{minipage}{\textwidth}
\blindtext
\begin{tableenv}{blubb}{blubb}
\begin{tabularx}{\textwidth}{%
p{0.2\textwidth} p{0.3\textwidth} *{4}{X}}
\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}
\blindtext
\begin{tableenv}{blubb2}{blubb2}
\begin{tabularx}{\textwidth}{%
p{0.2\textwidth} p{0.3\textwidth} *{4}{X}}
\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}