newcolumntype leads to error with afterpage
As a general principle, \newcolumntype
declarations shouldn't be used outside a document's preamble. (The fact that using them outside the preamble doesn't result in a crash when not used in conjunction with the afterpage
environment doesn't contradict this point...)
The following MWE, which is based on your code, compiles without errors. Note that I've replaced the \begin{center}
... \end{center}
instructions with a simple \centering
instruction and have loaded the rotating
package to make use of its sidewaystable
environment.
\documentclass{article}
\usepackage{afterpage,array,rotating}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\afterpage{%
\begin{sidewaystable}
\centering
\begin{tabular}{|C{2.0cm}|C{2.0cm}|}
\hline
1 1 & 1 2\\
2 1 & 2 2\\
\hline
\end{tabular}
\end{sidewaystable}
}
\end{document}
Afterpage tokens are put through a \def
(of a temporary macro who's name is shown in the error message) So as usual with a def you have to double the #
:
\documentclass{article}
\usepackage{afterpage,array,rotating}
\begin{document}
\afterpage{%
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{##1}}
\begin{sidewaystable}
\centering
\begin{tabular}{|C{2.0cm}|C{2.0cm}|}
\hline
1 1 & 1 2\\
2 1 & 2 2\\
\hline
\end{tabular}
\end{sidewaystable}
}
\end{document}
It would have been possible to define afterpage
in a way that avoided the need to double the #
(by cycling the tokens through a token register) but I didn't think anyone would ever use the package let alone need macro parameter tokens within its argument:-)