在某种程度上,这是新的表格环境、新环境中的空格和封闭的 { },@egreg 已经很方便地回答了这个问题。
请编译此 MWE 来查看并跟踪问题:
\documentclass[a4paper, 11pt]{scrbook}
\usepackage{blindtext}
\usepackage[cm]{fullpage}
\usepackage{tabu, longtable, booktabs}
\usepackage{caption}
\newenvironment{texttab}[1]%
{\setlength{\topsep}{\baselineskip}%
\begin{center} \tabulinesep=0.6ex%
\begin{tabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{tabu}%
\end{center}}
\newenvironment{tabspaces}[1]%
{\setlength{\topsep}{\baselineskip}%
\begin{center} \tabulinesep=0.6ex%
\begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{longtabu}%
\end{center}}
\newenvironment{texttab*}[1]%
{\setlength{\topsep}{\baselineskip}%
\LTpre=0pt%
\LTpost=0pt%
\begin{center} \tabulinesep=0.6ex%
\begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{longtabu}%
\end{center}}
\begin{document}
\section{TEST}
\blindtext
%
\begin{texttab}{X[l,2] X[l,2] X[l,3]}
Test1 & Test2 & Test3 works fine \\ \midrule
Test1 & Test2 & Test3 works fine \\
Test1 & Test2 & Test3 works fine \\ \bottomrule
\end{texttab}%
%
\blindtext
%
\begin{tabspaces}{X[l,2] X[l,2] X[l,3]}
Test1 & Test2 & Test3 \\ \midrule
Test1 & Test2 & Test3 \\
Test1 & Test2 & Test3 \\ \bottomrule
\end{tabspaces}%
%
\blindtext
%
\begin{texttab*}{X[l,2] X[l,2] X[l,3]}
Test1 & Test2 & Test3 \\ \midrule
Test1 & Test2 & Test3 \\
Test1 & Test2 & Test3 \\ \bottomrule
\end{texttab*}%
%
\blindtext
\end{document}
我创建了三个新环境:texttab
、tabspaces
和texttab*
。它们在文本中实现tabu
s (不嵌入浮动体)。根据之前提到的问题,我为普通tabu
s ( texttab
) 或longtabu
s ( texttab*
) 创建了两个环境。tabspaces
仅用于演示。
现在,如果你看一下tabspaces
环境(示例中的第二个表),你会看到它产生了上方和下方的垂直空间太多环境。
我尝试在 -environment 中使用命令\LTpre=0pt
和\LTpost=0pt
(由 -package 提供longtable
)texttab*
- 你看,下面仍然有太多空间!
它是从哪里来的?我该如何摆脱它?
笔记: \tabulinesep=0.6ex
似乎会影响这些空间!尽管如此,删除它并不能改变垂直空间仍然与我的(令人满意的)环境中的垂直空间不同的事实texttab
。
答案1
\LTpre
设置和\LTpost
对环境没有影响的原因texttab*
是您0pt
在该环境的定义中将它们重置为。我删除了这两行并全局设置了一些粗略的值,这些值给出的间距与 产生的间距相似texttab
。
\documentclass[a4paper, 11pt]{scrbook}
\usepackage{blindtext}
\usepackage[cm]{fullpage}
\usepackage{tabu, longtable, booktabs}
\usepackage{caption}
\setlength{\LTpre}{0pt}\setlength{\LTpost}{-17pt}%
\newenvironment{texttab}[1]%
{\setlength{\topsep}{\baselineskip}%
\begin{center} \tabulinesep=0.6ex%
\begin{tabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{tabu}%
\end{center}}
\newenvironment{tabspaces}[1]%
{\setlength{\topsep}{\baselineskip}%
\begin{center} \tabulinesep=0.6ex%
\begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{longtabu}%
\end{center}}
\newenvironment{texttab*}[1]%
{\setlength{\topsep}{\baselineskip}%
\begin{center} \tabulinesep=0.6ex%
\begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{longtabu}%
\end{center}}
\begin{document}
\section{TEST}
\blindtext
%
\begin{texttab}{X[l,2] X[l,2] X[l,3]}
Test1 & Test2 & Test3 works fine \\ \midrule
Test1 & Test2 & Test3 works fine \\
Test1 & Test2 & Test3 works fine \\ \bottomrule
\end{texttab}%
%
\blindtext
%
\begin{tabspaces}{X[l,2] X[l,2] X[l,3]}
Test1 & Test2 & Test3 \\ \midrule
Test1 & Test2 & Test3 \\
Test1 & Test2 & Test3 \\ \bottomrule
\end{tabspaces}%
%
\blindtext
%
\begin{texttab*}{X[l,2] X[l,2] X[l,3]}
Test1 & Test2 & Test3 \\ \midrule
Test1 & Test2 & Test3 \\
Test1 & Test2 & Test3 \\ \bottomrule
\end{texttab*}%
%
\blindtext
\end{document}
Qrrbrbirlbel 在下面指出,使用\centering
而不是center
环境是一种选择。我的快速尝试如下。我对 's 做了一些调整,\par
以避免上面的线条也居中......我不确定是否有更好的方法可以做到这一点。无论如何,由于 和 的行为不同,tabu
我longtabu
认为您可能必须调整第一个环境的间距以匹配后两个环境,反之亦然。
\documentclass[a4paper, 11pt]{scrbook}
\usepackage{blindtext}
\usepackage[cm]{fullpage}
\usepackage{tabu, longtable, booktabs}
\usepackage{caption}
\newenvironment{texttab}[1]%
{\par\bigskip\centering\tabulinesep=0.6ex%
\begin{tabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{tabu}\par\bigskip}
\newenvironment{tabspaces}[1]%
{\par\centering\tabulinesep=0.6ex%
\begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{longtabu}}
\newenvironment{texttab*}[1]%
{\par\centering\tabulinesep=0.6ex%
\begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{longtabu}}
\begin{document}
\section{TEST}
\blindtext
\begin{texttab}{X[l,2] X[l,2] X[l,3]}
Test1 & Test2 & Test3 works fine \\ \midrule
Test1 & Test2 & Test3 works fine \\
Test1 & Test2 & Test3 works fine \\ \bottomrule
\end{texttab}%
\blindtext
%
\begin{tabspaces}{X[l,2] X[l,2] X[l,3]}
Test1 & Test2 & Test3 \\ \midrule
Test1 & Test2 & Test3 \\
Test1 & Test2 & Test3 \\ \bottomrule
\end{tabspaces}%
%
\blindtext
%
\begin{texttab*}{X[l,2] X[l,2] X[l,3]}
Test1 & Test2 & Test3 \\ \midrule
Test1 & Test2 & Test3 \\
Test1 & Test2 & Test3 \\ \bottomrule
\end{texttab*}%
%
\blindtext
\end{document}