tcolorbox 中的页码错误?

tcolorbox 中的页码错误?
\documentclass[12pt, a4paper, UTF8, scheme = plain, twoside, draft]{ctexart}
\usepackage{lipsum}
\usepackage{amsmath,enumerate}
\usepackage[margin = 2cm]{geometry}
\usepackage{adjustbox}
%% - header and footer - %%
\usepackage{fancyhdr}
\usepackage{totpages}
\fancyhead{}
\fancyfoot{}
\fancyfoot[CE]{\qquad Page~\thepage\ of~\pageref{TotPages}}
\fancyfoot[CO]{Page~\thepage\ of~\pageref{TotPages}\qquad}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyfootoffset[R]{-2.28cm}
%%    - PDF settings -   %%
\usepackage{pdfpages}
\usepackage{hyperref}
%%       - license -     %%
\usepackage[type={CC}, modifier={by-nc-nd}, version={4.0} ]{doclicense}
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse}
%%      - Ques env -     %%
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse}
\tcbset{%
    colback      = white,
    colframe     = black,
    title filled = false
}
\NewTColorBox[
    auto counter,
    number freestyle =  { Q\noexpand\arabic{\tcbcounter} }
    ]{question}{ O{}mo }{
    lowerbox         =  ignored, %invisible/ignored
    fonttitle        =  \bfseries,
    title            =  \thetcbcounter: #2,
% after title/after upper
    after title      =  {\hfill Page~\thepage\ of~\pageref{TotPages}},
    #1
}%
\newcommand{\mytopic}[1]{%%%%%%%%%%%%%%%%%%%
%%% \clearpage
\begin{question}{Test}
%   \includegraphics[scale=0.44]{./PaperQBank/#1}
    #1
\end{question}
}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength{\parindent}{0pt}
\begin{document}
\clearpage
\thispagestyle{empty}
\tableofcontents
\newgeometry{top=0.5cm,left=1.5cm,right=0.5cm,bottom=2.28cm}
\lipsum[7]
\pagestyle{fancy}%%%%%%%%%%%%%%%%%%%%%%%%%%%
\lipsum[8]
%%%%%\input{chap1.tex}
\mytopic{\lipsum[1]}
\mytopic{\lipsum[2]}
\mytopic{\lipsum[3]}
\mytopic{\lipsum[4-5]}
\mytopic{\lipsum[8]}
\mytopic{\lipsum[10]}
\mytopic{\lipsum[1]}
\lipsum[9]
\normalsize%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newgeometry{top=0.5cm,left=0.5cm,right=0.5cm,bottom=2.28cm}
\lipsum[7-13]
\newgeometry{margin = 2cm}
\lipsum[1-6]
\clearpage
\mytopic{\lipsum[3]}
\mytopic{\lipsum[4-5]}
\mytopic{\lipsum[8]}
\mytopic{\lipsum[10]}
\mytopic{\lipsum[1]}
\section{33333333}
\clearpage%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\thispagestyle{empty}%%%%%%%%%%%%%%%%%%%%%%%
\centering%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\vspace*{\fill}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{\huge[THIS PAGE IS INTENTIONALLY LEFT BLANK.]}
\vspace*{\fill}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

在此处输入图片描述

答案1

你不能做

after title      =  {\hfill Page~\thepage\ of~\pageref{TotPages}},

相反,设置 \label 并通过以下方式访问页面\pageref

after title      =  {\hfill Page~\label{tb\thetcbcounter}\pageref{tb\thetcbcounter}\ of~\pageref{TotPages}},

完整示例(使用文章,因为我没有 ctexart 的字体)

在此处输入图片描述

\documentclass[12pt, a4paper, UTF8, scheme = plain, twoside, draft]{article}
\usepackage{lipsum}
\usepackage{amsmath,enumerate}
\usepackage[margin = 2cm]{geometry}
\usepackage{adjustbox}
%% - header and footer - %%
\usepackage{fancyhdr}
\usepackage{totpages}
\fancyhead{}
\fancyfoot{}
\fancyfoot[CE]{\qquad Page~\thepage\ of~\pageref{TotPages}}
\fancyfoot[CO]{Page~\thepage\ of~\pageref{TotPages}\qquad}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyfootoffset[R]{-2.28cm}
%%    - PDF settings -   %%
\usepackage{pdfpages}
\usepackage{hyperref}
%%       - license -     %%
\usepackage[type={CC}, modifier={by-nc-nd}, version={4.0} ]{doclicense}
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse}
%%      - Ques env -     %%
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse}
\tcbset{%
    colback      = white,
    colframe     = black,
    title filled = false
}
\NewTColorBox[
    auto counter,
    number freestyle =  { Q\noexpand\arabic{\tcbcounter} }
    ]{question}{ O{}mo }{
    lowerbox         =  ignored, %invisible/ignored
    fonttitle        =  \bfseries,
    title            =  \thetcbcounter: #2,
% after title/after upper
    after title      =  {\hfill Page~\label{tb\thetcbcounter}\pageref{tb\thetcbcounter}\ of~\pageref{TotPages}},
    #1
}%
\newcommand{\mytopic}[1]{%%%%%%%%%%%%%%%%%%%
%%% \clearpage
\begin{question}{Test}
%   \includegraphics[scale=0.44]{./PaperQBank/#1}
    #1
\end{question}
}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength{\parindent}{0pt}
\begin{document}
\clearpage
\thispagestyle{empty}
\tableofcontents
\newgeometry{top=0.5cm,left=1.5cm,right=0.5cm,bottom=2.28cm}
\lipsum[7]
\pagestyle{fancy}%%%%%%%%%%%%%%%%%%%%%%%%%%%
\lipsum[8]
%%%%%\input{chap1.tex}
\mytopic{\lipsum[1]}
\mytopic{\lipsum[2]}
\mytopic{\lipsum[3]}
\mytopic{\lipsum[4-5]}
\mytopic{\lipsum[8]}
\mytopic{\lipsum[10]}
\mytopic{\lipsum[1]}
\lipsum[9]
\normalsize%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newgeometry{top=0.5cm,left=0.5cm,right=0.5cm,bottom=2.28cm}
\lipsum[7-13]
\newgeometry{margin = 2cm}
\lipsum[1-6]
\clearpage
\mytopic{\lipsum[3]}
\mytopic{\lipsum[4-5]}
\mytopic{\lipsum[8]}
\mytopic{\lipsum[10]}
\mytopic{\lipsum[1]}
\section{33333333}
\clearpage%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\thispagestyle{empty}%%%%%%%%%%%%%%%%%%%%%%%
\centering%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\vspace*{\fill}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{\huge[THIS PAGE IS INTENTIONALLY LEFT BLANK.]}
\vspace*{\fill}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

相关内容