3

I'd like to redefine the table environment in a document I'm writing so that the tables and captions are wider than the text block. I'm using the memoir class, and an example given in the manual is

\documentclass{memoir}

\begin{document}

Lorem ipsum dolor sit amet, ...

\begin{table}
\begin{adjustwidth*}{-1in}{-1in}

\begin{tabular}{ll}
1 & 2\\
3 & 4
\end{tabular}

\caption{Lorem ipsum dolor sit amet, ...}
\end{adjustwidth*}
\end{table}

Lorem ipsum dolor sit amet, ...

\end{document}

This behaves just as I'd like. The next step for me is to make this change automatically for all tables in my document. It seems that the \renewenvironment command is the right way to approach this, and I tried making this change:

\documentclass{memoir}

\let\originaltable\table
\let\originalendtable\endtable
\renewenvironment{table}[1][ht]{%
    \originaltable[%
    \begin{adjustwidth*}{-1in}{-1in}%
    #1%
    \end{adjustwidth*}]%
    }%
    {\originalendtable}

\begin{document}

Lorem ipsum dolor sit amet, ...

\begin{table}
\begin{tabular}{ll}
1 & 2\\
3 & 4
\end{tabular}

\caption{Lorem ipsum dolor sit amet, ...}
\end{table}

Lorem ipsum dolor sit amet, ...

\end{document}

This compiles without error, but the adjustwidth* environment doesn't seem to have any effect. I must be misunderstanding how to use \renewenvironment; does anyone have a suggestion for getting this to work?

David Carlisle
  • 757,742
DGrady
  • 532

1 Answers1

7

You need to use the following (re)definition for table:

\renewenvironment{table}[1][ht]%
  {\originaltable[#1]% \begin{table}[ht]
   \begin{adjustwidth*}{-1in}{-1in}}%
  {\end{adjustwidth*}\originalendtable}% \end{table}

The first argument #1 is the optional argument for \begin{table}, which you now pass to \origingaltable.

When dealing with functions that use optional arguments, you can err on the side of caution by using the letltxmacro package:

enter image description here

\documentclass{memoir}% http://ctan.org/pkg/memoir
\usepackage{letltxmacro}% http://ctan.org/pkg/letltxmacro
\LetLtxMacro{\originaltable}{\table}
\LetLtxMacro{\originalendtable}{\endtable}
\renewenvironment{table}[1][ht]%
  {\originaltable[#1]% \begin{table}[ht]
   \begin{adjustwidth*}{-1in}{-1in}
  }%
  {\end{adjustwidth*}\originalendtable}% \end{table}
\begin{document}

Lorem ipsum dolor sit amet, ...

\begin{table}
\begin{tabular}{ll}
1 & 2\\
3 & 4
\end{tabular}

\caption{Lorem ipsum dolor sit amet, ...}
\end{table}

Lorem ipsum dolor sit amet, ...

\end{document}​
Werner
  • 603,163