You ought to modify the commands \LT@output
and \LT@start
from the package. The following works for the longtable
version [2004/02/01 v4.11]
. The biggest problem is that you cannot put \shadowbox
directly around \box255
which stores the page contents. Second problem is that the shadowbox would go around the text before the table at its first page. I made the shadowbox a bit narrower (1.5% from both left and right) to get a better look on the last page.
\documentclass{article}
\usepackage{longtable} % version
\makeatletter
\newlength{\LT@startpagetotal}
\def\LT@start{%
\let\LT@start\endgraf
\endgraf\penalty\z@\vskip\LTpre
\dimen@\pagetotal
\advance\dimen@ \ht\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
\advance\dimen@ \dp\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
\advance\dimen@ \ht\LT@foot
\dimen@ii\vfuzz
\vfuzz\maxdimen
\setbox\tw@\copy\z@
\setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
\setbox\tw@\vbox{\unvbox\tw@}%
\vfuzz\dimen@ii
\advance\dimen@ \ht
\ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
\advance\dimen@\dp
\ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
\advance\dimen@ -\pagegoal
\ifdim \dimen@>\z@\vfil\break\fi
\global\@colroom\@colht
\ifvoid\LT@foot\else
\advance\vsize-\ht\LT@foot
\global\advance\@colroom-\ht\LT@foot
\dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@
\maxdepth\z@
\fi
\ifvoid\LT@firsthead\relax
\LT@startpagetotal-\ht\LT@head\relax% MODIFIED %
\copy\LT@head
\else
\LT@startpagetotal-\ht\LT@firsthead\relax% MODIFIED %
\box\LT@firsthead
\fi\nobreak
\advance\LT@startpagetotal\pagetotal\relax% MODIFIED %
\output{\LT@output}}
\def\LT@output{%
\ifnum\outputpenalty <-\@Mi
\ifnum\outputpenalty > -\LT@end@pen
\LT@err{floats and marginpars not allowed in a longtable}\@ehc
\else
\setbox\z@\vbox{\unvbox\@cclv}%
\ifdim \ht\LT@lastfoot>\ht\LT@foot
\dimen@\pagegoal
\advance\dimen@-\ht\LT@lastfoot
\ifdim\dimen@<\ht\z@
\setbox2\hbox to 0.97\textwidth{\box\@cclv\hss}%% MODIFIED %
\ht2\dimexpr\ht2-\LT@startpagetotal\relax% MODIFIED %
\setbox1\hbox{\shadowbox{\box2}}%% MODIFIED %
\ht1\dimexpr\ht1+\LT@startpagetotal\relax% MODIFIED %
\global\LT@startpagetotal0pt\relax% MODIFIED %
\setbox\@cclv\vbox{\box1\copy\LT@foot\vss}%% MODIFIED %
\@makecol
\@outputpage
\setbox\z@\vbox{\box\LT@head}%
\fi
\fi
\global\@colroom\@colht
\global\vsize\@colht
\setbox2\hbox to 0.97\textwidth{\kern-0.015\textwidth\vbox% MODIFIED %
{\unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}\hss}%% MODIFIED %
\ht2\dimexpr\ht2-\LT@startpagetotal\relax% MODIFIED %
\setbox1\hbox{\shadowbox{\box2}}%% MODIFIED %
\ht1\dimexpr\ht1+\LT@startpagetotal\relax% MODIFIED %
\global\LT@startpagetotal0pt\relax% MODIFIED %
\noindent\box1\relax%
\fi
\else
\setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot}%% MODIFIED %
\setbox2\hbox to 0.97\textwidth{\kern-0.015\textwidth\box\@cclv\hss}%% MODIFIED %
\ht2\dimexpr\ht2-\LT@startpagetotal\relax% MODIFIED %
\setbox1\hbox{\shadowbox{\box2}}%% MODIFIED %
\ht1\dimexpr\ht1+\LT@startpagetotal\relax% MODIFIED %
\global\LT@startpagetotal0pt\relax% MODIFIED %
\setbox\@cclv\vbox{\box1\vss}%% MODIFIED %
\@makecol
\@outputpage
\global\vsize\@colroom
\copy\LT@head\nobreak
\fi}
\makeatother
\usepackage{fancybox}
\usepackage{lipsum}
\begin{document}
\lipsum[1-7]
%\tracingmacros=1
%\tracingonline=1
\begin{longtable}{|c|c|}\hline
FIRST&HEAD\\\hline\endfirsthead
\hline RUNNING&HEAD\\\hline\endhead
RUNNING&FOOT\\\hline\endfoot
LAST&FOOT\\\hline\endlastfoot
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
\end{longtable}
\lipsum[8-11]
\begin{longtable}{|c|c|}\hline
FIRST&HEAD\\\hline\endfirsthead
\hline RUNNING&HEAD\\\hline\endhead
RUNNING&FOOT\\\hline\endfoot
LAST&FOOT\\\hline\endlastfoot
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
Test&Test\\ \hline
\end{longtable}
\lipsum[12-15]
\end{document}
How does the modification work:
We do two things: The macro \LT@output
is the output routine for the longtable
. This routine takes care of the page typesetting. Here we take the page contents (which is internally stored in \box255
=\box\@cclv
) and put \shadowbox
around it, just not exactly, we have to fool around with \hbox
and \vbox
at different places to get the desired result. The problem is that for the first page of the longtable
, this puts the text above the table into the box, which is frowned upon. Hence we modify \LT@start
to measure the \pagetotal
of the page when the table begins to be typeset. We do it after the table head is set so that we don't have to deal with the \depth
of the previous contents. The length \LT@startpageottal
is used to store this measure. Once we know how high is the text above the table, we make \shadowbox
assume that the contents of the box are less high by this amount.
mdframed
can be an option for you? – user11232 Apr 17 '12 at 5:50mdframed
). I am pretty suspicious of this being the real nature of an assignment: I think a lot of experienced LaTeX users would struggle to do this in the way you put it! – Joseph Wright♦ Apr 17 '12 at 6:35mdframed
would clash with the one oflongtable
. So this wouldn't be an option as well. I wonder iftabu
allows something like this. – Martin Scharrer♦ Apr 17 '12 at 7:05