Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

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}​
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.