# Automatically change the text width for all table environments using memoir

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{tabular}{ll}
1 & 2\\
3 & 4
\end{tabular}

\caption{Lorem ipsum dolor sit amet, ...}
\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[%
#1%
}%
{\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?

-

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

\renewenvironment{table}[1][ht]%
{\originaltable[#1]% \begin{table}[ht]


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:

\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{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}​

-
Thanks! I guess it was \table I was confused about in the end. –  DGrady Oct 1 '12 at 23:10
@DGrady don't forget to upvote Werner using the up arrow; this gives him 10 reputation points –  cmhughes Oct 1 '12 at 23:12