# Command takes effect before environment

Is it possible to add a \vspace{-\baselineskip} inside, .e.g., longtable (or other environment} to take effect before the environment starts? MWE which has no effect.

\documentclass{article}
\usepackage{longtable}
\usepackage{blindtext}

\begin{document}

\blindtext

\begin{longtable}{ll}
\vspace{-\baselineskip} \\ % this has no effect
% why \\ are really needed since caption has them?
\caption{testing table} \\
\hline
aaaa & bbbb \\
cccc & dddd \\
\hline
\end{longtable}

\end{document}


There is a MWE with the problem of having a messed reference in the LOT.

\documentclass[captions=tableheading]{scrartcl}

\usepackage{blindtext}

\usepackage{hyperref}
\usepackage{tabu,longtable}
\usepackage[referable]{threeparttablex}
\usepackage{booktabs}
\usepackage{caption}

\usepackage{etoolbox}
\makeatletter
\chardef\TPT@@@asteriskcatcode=\catcode*
\catcode*=11
\expandafter\patchcmd\csname\string\threeparttable\endcsname
{\TPT@hookin{tabular}}
{\TPT@hookin{tabular}\TPT@hookin{tabu}} % allow threeparttable with tabu
{}{}
\catcode*=\TPT@@@asteriskcatcode
\makeatother

\makeatletter % fix referencing of LOT while using longtabu
\newcounter{dummy}
\newcommand{\setdummy}{\refstepcounter{dummy} \\}
\let\oldlongtabu\longtabu\def\dummytabu{\vspace{-\baselineskip}\oldlongtabu} % correct the \\ in \setdummy
\def\enddummytabu{\endlongtabu}
\def\dummycap{\setdummy\caption}
\makeatother

\begin{document}

\listoftables

\bigskip

\blindtext

% LOT reference does not work
\begin{ThreePartTable}
\begin{TableNotes}
\footnotesize
\item[a] \label{tn:aa} A note
\item[b] Another note
\end{TableNotes}
\begin{longtabu}{ll}
\caption{A long table 1}
\label{tab:test1} \\
\toprule
Column 1 & Column 2 \\
\midrule
\toprule
Column 1 & Column 2 \\
\midrule
\cmidrule{2-2}
\multicolumn{2}{r}{\textit{continued}}
\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
% the contents of the table
A& B\tnotex{tn:aa} \\
\midrule
%\newpage % just testing page break
C\tnote{b} & D \\
\end{longtabu}
\end{ThreePartTable}

\blindtext

% LOT reference works fine
\begin{ThreePartTable}
\begin{TableNotes}
\footnotesize
\item[a] \label{tn:bb} A note
\item[b] Another note
\end{TableNotes}
\begin{longtable}{ll}
\caption{A long table 2}
\label{tab:test2} \\
\toprule
Column 1 & Column 2 \\
\midrule
\toprule
Column 1 & Column 2 \\
\midrule
\cmidrule{2-2}
\multicolumn{2}{r}{\textit{continued}}
\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
% the contents of the table
A& B\tnotex{tn:bb} \\
\midrule
%\newpage % just testing page break
C\tnote{b} & D \\
\end{longtable}
\end{ThreePartTable}

\blindtext

% LOT reference works fine (with vskip correction)
\begin{ThreePartTable}
\begin{TableNotes}
\footnotesize
\item[a] \label{tn:cc} A note
\item[b] Another note
\end{TableNotes}
\begin{dummytabu}{ll}
\dummycap{A long table 3}
\label{tab:test3} \\
\toprule
Column 1 & Column 2 \\
\midrule
\toprule
Column 1 & Column 2 \\
\midrule
\cmidrule{2-2}
\multicolumn{2}{r}{\textit{continued}}
\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
% the contents of the table
A& B\tnotex{tn:cc} \\
\midrule
%\newpage % just testing page break
C\tnote{b} & D \\
\end{dummytabu}
\end{ThreePartTable}

\blindtext

\end{document}

-
\baselineskip is zero in a tabular. Use some other length, then e.g. \vspace{-1cm} or \\[-1cm] will work. Or move the \vspace before the longtable. –  Ulrike Fischer Sep 3 '12 at 17:20
But when I use \\ inside tabular, what is the actual skip of \\? I thought it was \baselineskip. For example, if used a \macro{}\ just after longtable what is the actual value of \\? –  cacamailg Sep 3 '12 at 17:23
The defaut size of a row is height + depth of \@arstrutbox. –  Ulrike Fischer Sep 3 '12 at 17:25
How can I store that value in a variable? like let\tmpvar\@arstrutbox –  cacamailg Sep 3 '12 at 17:30
That's not a value but a box. You can find its definition/content in latex.ltx. –  Ulrike Fischer Sep 3 '12 at 17:59

Just use

\begin{ThreePartTable}
\begin{TableNotes}
\footnotesize
\item[a] \label{tn:aa} A note
\item[b] Another note
\end{TableNotes}
\begin{longtabu}{ll}
\noalign{\phantomsection}
\caption{A long table 1}
\label{tab:test1} \\
\toprule
...


@cacamailg I tried to patch some command in order to get this automatically, but scrartcl, longtable, caption and ltcaption juggle with \caption and its internal versions and the moment of the final redefinition is hard to find. –  egreg Sep 4 '12 at 14:37
longtable inserts a vskip of the length \LTpre (defaulting to \bigskipammount) before the table so to change the vertical space before the table alter this length with \setlength or \addtolength. Using \vspace in the position you show puts it in the first cell of the first row which is a l entry so a horizontal box in which a vertical skip does nothing. So the effect is just to add a blank line before the table despite nominally specifying a negative skip.
The problem is that I want to add a macro just after the begin{longtable} like \macro{}. I need that to correct the referring system. Since I need to put \macro{} \ I need before the longtable to remove the extra vertical space. So what I wanted is to include that correction inside the macro. I did it like that: \makeatletter \newcounter{dummy} \AtBeginDocument{ \newdimen\dummyskip \dummyskip\baselineskip} \newcommand{\setdummy}{ \vspace{-\dummyskip} \refstepcounter{dummy}\addtocounter{dummy}{-1} \\} \makeatother I'm just not if there is side effect. –  cacamailg Sep 3 '12 at 19:03
just after \begin{longtable} isn't a place to add code that is where lontable is parsing its optional and mandatory arguments. The only sensible place to add code would be before longtable \let\oldlongtable\longtable\def\longtable{\mymacro\oldlongtable} would make \mymacro be executed before each table. I'm not sure what effect you intend with the \refstepcounter{dummy} setting a ref at begin document can have some side effects on vertical space in some circumstances, but I'm not sure why you are making a ref to that point. The \vspace{-\dummyskip} will have no effect at that point. –  David Carlisle Sep 3 '12 at 19:50
thanks for clarification. I am trying to use threeparttablex (which is based on threeparttable) and longtabu (because I want tablewidth with textwidh). longtabu uses longtable. with longtable the reference in LOT is ok (threeparttablex + longtable), but with lontabu it points to section that does not exist. With \refstepcounter{dummy} it point to the correct table, but I do not understant why. If I could I would avoid to use it. –  cacamailg Sep 4 '12 at 0:13
@cacamailg Maybe \phantomsection is better than \refstepcounter{dummy}`. –  egreg Sep 4 '12 at 13:05