4

Having this example (note the use of tufte-handout document class):

\documentclass[12pt,english,nohyper]{tufte-handout}

\usepackage[]{color}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{alltt}
\usepackage{longtable}
\usepackage{geometry}

\begin{document}

\centerline{\Large\bf A title here}

\lipsum[2]

\bigskip{}

% Auto-generated ------------------------------------------
\begin{longtable}{r|lr|r}
  \hline
mpg & cyl & disp & hp \\ 
  \hline
21.00 & 6.00 & 160.00 & 110.00 \\ 
  21.00 & 6.00 & 160.00 & 110.00 \\ 
  22.80 & 4.00 & 108.00 & 93.00 \\ 
  21.40 & 6.00 & 258.00 & 110.00 \\ 
  18.70 & 8.00 & 360.00 & 175.00 \\ 
  18.10 & 6.00 & 225.00 & 105.00 \\ 
  14.30 & 8.00 & 360.00 & 245.00 \\ 
  24.40 & 4.00 & 146.70 & 62.00 \\ 
  22.80 & 4.00 & 140.80 & 95.00 \\ 
  19.20 & 6.00 & 167.60 & 123.00 \\ 
   \hline
\hline
\caption{Table caption.}
\end{longtable}
% Auto-generated ------------------------------------------

\lipsum[2]

\end{document}

The resulting output is like:

enter image description here

Is it possible to center the table with respect to the page? That would mean moving it to the right, even if it overtakes the margin. Moving it to the right a fixed distance without actually calculating the exact page center would be enough (i.e.: move the table 2.5cm to the right).

The table code would be auto-generated, so if there is a way to do so writing some code around it (without actually touching the table code), that would be great.

2
  • you can try \begingroup\setlength{\hsize}{\dimexpr\paperwidth-2in\relax} your tabular \endgroup
    – touhami
    Jul 20, 2015 at 20:39
  • @touhami: that works. Could you add it as an answer? :-)
    – Peque
    Jul 20, 2015 at 20:42

2 Answers 2

2

copied from a very similar question on SO, the following code should work:

\begin{fullwidth}
\makeatletter\setlength\hsize{\@tufte@fullwidth}\makeatother
...
\end{fullwidth}
4

One possibility using a \makebox and a minipage (which means no page breaks are allowed now):

enter image description here

The code:

\documentclass[12pt,english,nohyper,draft]{tufte-handout}

\usepackage[]{color}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{alltt}
\usepackage{longtable}
\usepackage{geometry}

\begin{document}

\centerline{\Large\bf A title here}

\lipsum[2]

\bigskip{}

% Auto-generated ------------------------------------------
\noindent\hspace*{-\dimexpr\oddsidemargin+1in\relax}\makebox[\paperwidth]{\begin{minipage}{\paperwidth}%
\begin{longtable}{r|lr|r}
  \hline
mpg & cyl & disp & hp \\ 
  \hline
21.00 & 6.00 & 160.00 & 110.00 \\ 
  21.00 & 6.00 & 160.00 & 110.00 \\ 
  22.80 & 4.00 & 108.00 & 93.00 \\ 
  21.40 & 6.00 & 258.00 & 110.00 \\ 
  18.70 & 8.00 & 360.00 & 175.00 \\ 
  18.10 & 6.00 & 225.00 & 105.00 \\ 
  14.30 & 8.00 & 360.00 & 245.00 \\ 
  24.40 & 4.00 & 146.70 & 62.00 \\ 
  22.80 & 4.00 & 140.80 & 95.00 \\ 
  19.20 & 6.00 & 167.60 & 123.00 \\ 
   \hline
\hline
\caption{Table caption.}
\end{longtable}%
% Auto-generated ------------------------------------------
\end{minipage}}\hspace*{-\paperwidth}

\lipsum[2]

\end{document}

You must log in to answer this question.

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