2

In my document, I want to hide certain things from the headers/footers using ifthen (rather than defining new page styles). For example, I'd like to hide the page number on the first few pages:

\cfoot{\ifthenelse{\thepage<11}{}{\thepage}}

This will hide the page number in pages which are smaller than 11 (so, pages 1 to 10), and show the page number if the page number is 11 or above, in the center footer.

However, this seems to only work if the page numbering is arabic. Say I wanted to change the page numbering of the first five pages to roman. Then my pages would be numbered as follows:

i, ii, iii, iv, v, 1, 2, 3, 4, 5, 6, ...

This would mess up my ifthen conditional, because, for example, for the first page, the expression in \cfoot would evaluate to the following:

\ifthenelse{i<11}{}{\thepage}

and i<11 doesn't make sense.

My question now is, is there perhaps a better counter to use, rather than \thepage, which can be a non-numeric value if the page numbering is roman?

4
  • Normally using pagenumbering{some numbering system} resets the page counter. How do you manage not to?
    – Bernard
    Commented Jul 4, 2017 at 15:38
  • \thepage is not the counter, it's the output of the counter page with some defined formatting. You want \value{page} which provides the real number not the formatted one
    – user31729
    Commented Jul 4, 2017 at 15:43
  • You can use \ifnum\value{page}<11\else\thepage\fi.
    – Werner
    Commented Jul 4, 2017 at 15:43
  • @Bernard sorry, that's my fault. You're right, and I updated my question to reflect the correct numbering :) Commented Jul 4, 2017 at 16:02

1 Answer 1

3

Rather use \value{page} than \thepage, in order to perform a numerical test on the value of the page counter, not on its output definition (which would fail in certain cases anyway).

In my opinion, there's no need to use \ifthenelse. The TeX primitive \ifnum is sufficient here.

\documentclass{article}

\usepackage{fancyhdr}

\usepackage{blindtext}
\def\pagethreshold{10}

\fancypagestyle{plain}{%
  \renewcommand{\headrulewidth}{0pt}
  \fancyhf{}
   \cfoot{%
   \ifnum\pagethreshold<\value{page}
     \arabic{page}% or \thepage
    \else
    % Do something else
   \fi
 }
}

\pagestyle{plain}

\begin{document}
\blindtext[100]
\end{document}

Update for possible \pagenumbering usage

\documentclass{article}

\usepackage{fancyhdr}

\usepackage{blindtext}


\newif\ifshowpagenumbers
\showpagenumbersfalse% Don't show them
\def\pagetreshold{10}

\fancypagestyle{plain}{%
  \renewcommand{\headrulewidth}{0pt}
  \fancyhf{}
  \cfoot{%
    \ifshowpagenumbers
    \thepage
    \else
    \ifnum\pagetreshold<\value{page}
    \arabic{page}% or \thepage
    \else
    %
    \fi
    \fi
  }
}

\pagestyle{plain}

\begin{document}
\pagenumbering{roman}
\blindtext[50]
\clearpage
\showpagenumberstrue% Show them!
\pagenumbering{arabic}
\blindtext[50]

\end{document}    
10
  • 1
    btw I believe the spelling is threshold :) if I'm not mistaken Commented Jul 4, 2017 at 16:06
  • @SkeletonBow: Yes, you're right. Corrected the error. Thanks!
    – user31729
    Commented Jul 4, 2017 at 16:07
  • Using \pagenumbering{arabic} seems to reset \value{page}. Is there a way to prevent that? Commented Jul 4, 2017 at 16:51
  • @SkeletonBow: That's another question ;-)
    – user31729
    Commented Jul 4, 2017 at 16:52
  • True, but now I'm a wee bit confused. My question was to hide page numbers on the first ten pages if the first five pages in my document are numbered using roman numbers (so with \pagenumbering{roman}. Does your answer take that into account? it only seems to show how to hide page numbers on pages<11, but doesn't mention anything about roman numbering, if I'm mistaken. I thought \value{page} would return 2 for ii, 7 for 2, and 8 for 13, meaning that using \value{page} the page numbers are hidden on pages 1-15 for me. Commented Jul 4, 2017 at 17:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .