2

As a follow-up to a previous question, How to doublespace a table using setspace?, I found that the solution is not compatible with the sidewaystable environment defined in the rotating package.

I have modified the example in the answer from the previous question to demonstrate:

\documentclass{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{rotating}
\newcommand\Factor{1.9}

\makeatletter
\def\@xfloat#1[#2]{\ifhmode \@bsphack\@floatpenalty -\@Mii\else
   \@floatpenalty-\@Miii\fi\def\@captype{#1}\ifinner
      \@parmoderr\@floatpenalty\z@
    \else\@next\@currbox\@freelist{\@tempcnta\csname ftype@#1\endcsname
       \multiply\@tempcnta\@xxxii\advance\@tempcnta\sixt@@n
       \@tfor \@tempa :=#2\do
                        {\if\@tempa h\advance\@tempcnta \@ne\fi
                         \if\@tempa t\advance\@tempcnta \tw@\fi
                         \if\@tempa b\advance\@tempcnta 4\relax\fi
                         \if\@tempa p\advance\@tempcnta 8\relax\fi
         }\global\count\@currbox\@tempcnta}\@fltovf\fi
    \global\setbox\@currbox\vbox\bgroup
    \def\baselinestretch{\Factor}\@normalsize
    \boxmaxdepth\z@
    \hsize\columnwidth \@parboxrestore}
\makeatother

\begin{document}
\begin{spacing}{\Factor}
\lipsum[1]
\begin{sidewaystable}[ht]
\begin{tabular}{rlll}
  \hline
 & col1 & col2 & col3 \\ 
  \hline
  50 & 19 & 7 & 26 \\ 
  100 & 10 & 20 & 29 \\ 
  150 & 1 & 7 & 2 \\ 
  200 & 0 & 0 & 10 \\ 
\hline
\end{tabular}
\end{sidewaystable}
\end{spacing}
\end{document}

Running pdflatex on this document returns the error:

! Extra }, or forgotten \endgroup.
\color@endbox ->\egroup 

l.40 \end{sidewaystable}

How can I get around this?

3

I don't understand. What do you want to be doublespaced? Why all that code? Simply put \doublespacing after \begin{sidewaystable}[ht]

\documentclass{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{rotating}
%
\begin{document}
\lipsum[1]
\begin{sidewaystable}[ht]
\doublespacing %%% <--- here
\begin{tabular}{rlll}
  \hline
 & col1 & col2 & col3 \\
  \hline
  50 & 19 & 7 & 26 \\
  100 & 10 & 20 & 29 \\
  150 & 1 & 7 & 2 \\
  200 & 0 & 0 & 10 \\
\hline
\end{tabular}
\end{sidewaystable}
\end{document}

enter image description here

Update:

If you want to control things from the preamble, you can use etoolbox package as below:

\documentclass{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{rotating}
\usepackage{etoolbox}   %%% <----here
\AtBeginEnvironment{tabular}{\doublespacing}    %%% <---- and here
%
\begin{document}
\lipsum[1]
\begin{sidewaystable}[ht]
\begin{tabular}{rlll}
  \hline
 & col1 & col2 & col3 \\
  \hline
  50 & 19 & 7 & 26 \\
  100 & 10 & 20 & 29 \\
  150 & 1 & 7 & 2 \\
  200 & 0 & 0 & 10 \\
\hline
\end{tabular}
\end{sidewaystable}
\end{document}

Before the tabular environment, we have issued the command \doublespacing. This approach affects all tabular environments though.

  • Thanks for the simple solution. The main thing that I wanted was to be able to just make a simple re-definition in the preamble that would be only used at one time point, and wouldn't require re-compiling the Sweave source. – David LeBauer Aug 6 '12 at 15:27
  • Thanks - FWIW, I gave +1, not sure why there is a downvote. – David LeBauer Aug 6 '12 at 15:45
  • I would like to use the etoolbox package but want to be able to override the \AtBeginEnvironment{tabular}{\doublespacing} in a single table. Is this possible? – kennyB Nov 14 '16 at 22:47
2

I agree with the other answer that redefining should not be necessary especially redefining a core LaTeX feature like float handling seems very brave.

However you get the error because you have

   \global\setbox\@currbox\vbox\bgroup

Which is how it was in LaTeX2.09 last millenium. The LaTeX2e definition of \@xfloat ends

  \global \setbox\@currbox
    \color@vbox
      \normalcolor
      \vbox \bgroup
        \hsize\columnwidth
        \@parboxrestore
        \@floatboxreset
}

Which means, if you have the color package loaded, that your redefinition has the wrong number of groups, and is not color safe, so you get:

! Extra }, or forgotten \endgroup.
\color@endbox ->\egroup 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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