# How do I fix wrong numbering when using afterpage in appendix?

So I'm writing my thesis and was in need of a table in landscape mode as it was too big, and found a simple solution at How to place a table on a new page with landscape orientation without clearing the current page? and it worked pretty well, except that the numbering of the table is wrong when put in the appendix. The following code reproduces my problem.

\documentclass{report}
\usepackage[english]{babel}
\usepackage{float}
\usepackage{pdflscape}
\usepackage{afterpage}
\begin{document}
\chapter{Main}
\section{section}
main section
\begin{table}[h]
\caption{main}
\end{table}
\begin{appendices}
\chapter{appchap}
\begin{table}[h]
\caption{correct numbering}
\end{table}
\afterpage{
\clearpage
\thispagestyle{empty}
\begin{landscape}
\begin{table}
\centering
\caption{wrong numbering}
\end{table}
\end{landscape}
\clearpage
}
\end{appendices}
\end{document}


The tables created, in order, are numbered 1.1, A.1, 1.2. Table 1.2 is the second in appendix and should be named A.2 in my opinion, but it doesn't seem to get the chapter number (A) right. How can I fix the numbering issue?

the numbering was correct, you had delayed the table to be inserted at the next page break but as there was no text in the appendix, this was at the \clearpage in \end{document} so after \end{appendices} so not in the appendix, so did not get A.

You could add something to force a page break within the appendix

\documentclass{report}
\usepackage[english]{babel}
\usepackage{float}
\usepackage{pdflscape}
\usepackage{afterpage}
\begin{document}
\chapter{Main}
\section{section}
main section
\begin{table}[h]
\caption{main}
\end{table}
\begin{appendices}
\chapter{appchap}
\begin{table}[h]
\caption{correct numbering}
\end{table}
\afterpage{
\clearpage
\thispagestyle{empty}
\begin{landscape}
\begin{table}
\centering
\caption{wrong numbering}
\end{table}
\end{landscape}
\clearpage
}
\clearpage%<<<<<<<<<<<<<<<<<<<
\end{appendices}
\end{document}


or simply in this case don't use \afterpage which is doing nothing useful in this example.