Page LayoutInstead of invoking \clearpage, how to update \thepage soon?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Instead of invoking \clearpage, how to update \thepage soon?

Post by yoyoimut »

Dear all,

I want to invoke \thepage in any pages. Unfortunately, sometimes the printed page number is out of sync with the \thepage.

Actually we can flush the buffer by calling \clearpage, but this way will sacrifice the benefit of latex auto paging.


Is there any other method to update the counter page wherever I want it?


Thank you in advance.


Yuko

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: Instead of invoking \clearpage, how to update \thepage s

Post by daleif »

out of sync how? minimal example please
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Instead of invoking \clearpage, how to update \thepage soon?

Post by yoyoimut »

Code: Select all


\documentclass[a4paper,twoside,11pt,final]{book}
\usepackage[margin=3cm]{geometry}
\usepackage{lipsum,multido}

\newcommand{\tablefactory}
{
\begin{table}
\centering
\begin{tabular}{|c|}\hline
\Huge\thepage \\\hline
\end{tabular}
\caption{Compare it with the page number. Sometimes they are out of sync.}
\end{table}
}


\begin{document}
\multido{\i=1+1}{20}{
\tablefactory
\lipsum[1]
\tablefactory
}
\end{document}
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Instead of invoking \clearpage, how to update \thepage soon?

Post by gmedina »

Hi,

I've explained a typical workaround for this in some other threads. The idea is to use the \label, \pageref mechanism:

Code: Select all

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{lipsum,multido}

\newcounter{mycount}

\newcommand{\tablefactory}{%
  \begin{table}
  \stepcounter{mycount}
  \label{tab:\themycount}
  \centering
  \begin{tabular}{|c|}\hline
    \Huge\pageref{tab:\themycount} \\\hline
  \end{tabular}
  \caption{Compare it with the page number. It's OK now.}
  \end{table}}

\begin{document}

\multido{\i=1+1}{20}{%
  \tablefactory
  \lipsum[1]
  \tablefactory
}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Re: Instead of invoking \clearpage, how to update \thepage s

Post by yoyoimut »

Thanks gmedina.

However calling \thepage is mandatory not only inside the table but also other places.



Yuko
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Instead of invoking \clearpage, how to update \thepage soon?

Post by gmedina »

yoyoimut wrote:...However calling \thepage is mandatory not only inside the table but also other places...
Can't you just apply a variation of my proposed solution?
1,1,2,3,5,8,13,21,34,55,89,144,233,...
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Instead of invoking \clearpage, how to update \thepage soon?

Post by yoyoimut »

gmedina wrote:
Can't you just apply a variation of my proposed solution?

Because I don't need labeling so the \pageref is irrelevant in my situation.


Thank you.
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: Instead of invoking \clearpage, how to update \thepage s

Post by daleif »

What is the need for \thepage inside the table anyways?
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Instead of invoking \clearpage, how to update \thepage soon?

Post by yoyoimut »

daleif wrote:What is the need for \thepage inside the table anyways?

for the sake of example.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Instead of invoking \clearpage, how to update \thepage soon?

Post by gmedina »

yoyoimut wrote:...Because I don't need labeling so the \pageref is irrelevant in my situation...
You don't need it, but you might use it to solve your problem, so it doesn't seem to be irrelevant.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply