It was hard for me to find a proper title (feel free to change it) for my question which I want to introduce with an example:
Situation
In my document I sometimes use tabu
s directly in the document without nesting them in a table
-environment.
\documentclass[a4paper, 11pt]{scrbook}
\usepackage{blindtext}
\usepackage{tabu, booktabs}
\begin{document}
\section{TEST}
\blindtext
\\ \\
This is how I want my table to look like:
\ \\
{\centering
\begin{tabu} to 0.9\textwidth {X[l,2] X[l,2] X[l,3]} \toprule \rowfont{\bfseries}
Test1 & Test2 & Test3 \\ \midrule
Test1 & Test2 & Test3 \\
Test1 & Test2 & Test3 \\ \bottomrule
\end{tabu}\par} \medskip \ \\
\blindtext
\end{document}
Now, I wanted to create a new environment to help me building this table and I tried something like this:
\newenvironment{texttab}[1]
{\ \\ \centering%
\begin{tabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}%
{\end{tabu}\par \medskip \ \\}
where #1
gives the tabu
-specifications of course. It kind of works, but if you run the following MWE (adding and testing the new environment)
\documentclass[a4paper, 11pt]{scrbook}
\usepackage{blindtext}
\usepackage{tabu, booktabs}
\newenvironment{texttab}[1]
{\ \\ \centering%
\begin{tabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{tabu}\par \medskip \ \\}
\begin{document}
\section{TEST}
\blindtext
\\ \\
This is how I want my table to look like: % no new environment
\ \\
{\centering
\begin{tabu} to 0.9\textwidth {X[l,2] X[l,2] X[l,3]} \toprule \rowfont{\bfseries}
Test1 & Test2 & Test3 \\ \midrule
Test1 & Test2 & Test3 \\
Test1 & Test2 & Test3 \\ \bottomrule
\end{tabu}\par} \medskip \ \\
\blindtext
\begin{texttab}{X[l,2] X[l,2] X[l,3]} % WITH NEW ENVIRONMENT
Test1 & Test2 & Test3 \\ \midrule
Test1 & Test2 & Test3 \\
Test1 & Test2 & Test3 \\ \bottomrule
\end{texttab}
\blindtext
\end{document}
you will see that there is an indentation at the begin of the blindtext after the second table. Even adding \noindent
into the new environment like this
\newenvironment{texttab}[1]
{\ \\ \centering%
\begin{tabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
{\end{tabu}\par \medskip \ \\ \noindent} % added \noindent here
doesn't help as it still leaves some space (which I could remove with \!\!
, but...).
This wouldn't be a problem if I could use the {
and }
that enclose {\centering
and \par}
in the very first code example.
However, I cannot put them into the definition of the new environment as this will cause delimiter-problems...
I don't want to use the center
-environment due to unwanted vertical spaces (which seems kinda hilarious at this point of writing...)
\newenvironment{texttab}[1]
{{\\centering% % } missing!
\begin{tabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}%
{\end{tabu}\par} \medskip \ \\} % { missing!
Questions
- Is there a way to, either, get rid of those "uncontrollable spaces" that appear in the running version, or, make the last piece
of code workable? (I don't want to use a
minipage
here, as I maybe want to make it breakable withlongtabu
.) Then, sticking with the (for now) working "new environment": Why doesn't
\newenvironment{texttab}[2] {\ \\ \centering% \begin{#1tabu} to 0.9\textwidth {#2} \toprule \rowfont{\bfseries}} {\end{#1tabu}\par \medskip \ \\}
work, so that I could easily change the
tabu
into alongtabu
by setting the first argumentlong
?Should I rather try to pack all this into a new command with several arguments?
Do you think that maybe the whole idea is...stupid?
\ \\
construction for leaving vertical space;\par\medskip
is surely better.