5

I'm writing a document with long and wide tables spilling over the margin area in a two side document class. I'm using the Marco Daniel's fullwidth package.

Using longtable (and even longtabu) the tables correctly 'runs' over the margin but, the headings and footers unexpectedly disappears. This is a MWE:

\documentclass[twoside,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage[inner=1in, width=345pt]{geometry}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}  
\usepackage{fullwidth}

\newlength{\tablewidth}
\setlength{\tablewidth}{\textwidth}
\addtolength{\tablewidth}{1in}

\begin{document}
\lipsum[1-2] 

\begin{fullwidth}[outermargin=-1in]
  \begin{longtable}{p{0.5\tablewidth}p{0.5\tablewidth}}
    \toprule
    Loren & Ipsum\\
    \midrule
    \endhead
    \lipsum[1] & \lipsum[2]\\ \midrule
    \lipsum[3] & \lipsum[4]\\ \midrule
    \lipsum[5] & \lipsum[6]\\ 
    \bottomrule
  \end{longtable}
\end{fullwidth}

\lipsum[5]

\begin{longtable}{p{0.5\tablewidth}p{0.5\tablewidth}}
  \toprule
  This & Works\\
  \midrule
  \endhead
  \lipsum[1] & \lipsum[2]\\ \midrule
  \lipsum[3] & \lipsum[4]\\ \midrule
  \lipsum[5] & \lipsum[6]\\ 
  \bottomrule
\end{longtable}
\end{document}

I'm also tried Marco's mdframded solution posted here, but headings still doesn't appear.

Any ideas?

Thanks in advance.

1
  • 1
    fullwidth does nothing here. It seems that you are looking for a new feature of longtable.
    – touhami
    Jan 26, 2016 at 13:11

1 Answer 1

4
+200

Here is a solution. We don't use fullwidth package since it can do nothing here.

The idea is to patch \LT@output command (special output used by longtable) we move the table to the left, in fact we need to do that only for even page but we make it possible for odd pages too.

\documentclass[twoside,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage[inner=1in, width=345pt]{geometry}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array} 


\newlength{\tablewidth}
\setlength{\tablewidth}{\textwidth}
\addtolength{\tablewidth}{1in}

%%--------------------------
\usepackage{etoolbox}

\newcommand{\LTemove}{1in}%  move longtable in even pages
\newcommand{\LTomove}{0in}%  move longtable in odd pages

\makeatletter
\patchcmd{\LT@output}%
{\global\vsize\@colht}%
{\global\vsize\@colht%
\ifodd\c@page\moveleft\LTomove\else\moveleft\LTemove\fi}{}{}

\patchcmd{\LT@output}%
{\setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}}%
{\setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
\setbox\@cclv\vbox{\ifodd\c@page\moveleft\LTomove\else\moveleft\LTemove\fi\box\@cclv}}{}{}
\makeatother
%%------------
\begin{document}
\lipsum[1-2] 
 \begin{longtable}{p{0.5\dimexpr\tablewidth-4\tabcolsep\relax}p{0.5\dimexpr\tablewidth-4\tabcolsep\relax}}
    \toprule
    Loren & Ipsum\\
    \midrule
    \endhead
    \lipsum[1] & \lipsum[2]\\ \midrule
    \lipsum[3] & \lipsum[4]\\ \midrule
    \lipsum[5] & \lipsum[6]\\ 
    \bottomrule
  \end{longtable}
\lipsum[5]


\begin{longtable}{p{0.5\dimexpr\tablewidth-4\tabcolsep\relax}p{0.5\dimexpr\tablewidth-4\tabcolsep\relax}}
  \toprule
  This & Works\\
  \midrule
  \endhead
  \lipsum[1] & \lipsum[2]\\ \midrule
  \lipsum[3] & \lipsum[4]\\ \midrule
  \lipsum[5] & \lipsum[6]\\ 
  \bottomrule
\end{longtable}
\end{document}

enter image description here


enter image description here

2
  • If a table starts in the middle of a page, this seems to move the entire page rather than just the table. Any way to avoid that?
    – nioq
    Sep 26, 2019 at 14:08
  • using this solution in book class with twoside option produces correct results on odd pages while on even pages the table goes inside the right margin. anyway to make it work for the book class?
    – Damitr
    Mar 10, 2023 at 13:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .