3

This minimal working example is not working if hyperref is in the preamble. Why is that? Everything else is working fine.

\documentclass[10pt]{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{hyperref}

\definecolor{myblue}{rgb}{0.7,0.8,0.9}
\makeatletter\newenvironment{bluebox}{
   \begin{lrbox}{\@tempboxa}\begin{minipage}{\textwidth}}{\end{minipage}\end{lrbox}
   \colorbox{myblue}{\usebox{\@tempboxa}}
}\makeatother

\begin{document}
\renewcommand{\thepage}[1]{\centerline{\arabic{page} of 3}}
\centerline{\LARGE{\bf{CURRICULUM VITAE}}}
\vspace{0.5cm}

\begin{bluebox}
{\bf CONTACT}
\end{bluebox}

\end{document}

It says:

! Argument of \HyPL@CheckThePage has an extra }. \par l.20 \end{document}

Best regards, Alex

  • 1
    \renewcommand{\thepage}[1]{...} → bad idea , your \thepage macro expects an argument, getting none and is screwing up many things, amongst \centering` and the completely outdated \bf macro, as well as \LARGE does not have an argument – user31729 Dec 29 '17 at 16:44
  • Damn, I forgot to remove the backticks ;-) – user31729 Dec 29 '17 at 17:03
9

\renewcommand{\thepage}[1]{} screws up both hyperref by expecting an argument now for \thepage as well as the typesetting and the links.

You can use the lastpage and \pageref*{LastPage} in order to achieve 1 of 10000 etc.

Don't use \bf -- it is outdated -- either use \bfseries as a font switch or the limiting version \textbf. Alsoe \LARGE does not have an an argument. Also drop \centerline.

I've replaced the weird \thepage setting with fancyhdr \fancyfoot[C]{...} and the blue color box with tcolorbox settings.

\documentclass[10pt]{article}
\usepackage[usenames,dvipsnames]{xcolor}

\usepackage{lastpage}

\usepackage{fancyhdr}
\usepackage[most]{tcolorbox}

\usepackage{blindtext}

\usepackage{hyperref}


\definecolor{myblue}{rgb}{0.7,0.8,0.9}

\pagestyle{fancy}

\renewcommand{\headrulewidth}{0pt}
\fancyfoot[C]{\thepage\ of \pageref*{LastPage}}

\newtcolorbox{bluebox}[1][]{enhanced, sharp corners, frame hidden,colback=myblue,halign=left,boxsep=0pt,fontupper=\bfseries,left=0pt, #1}

\begin{document}

\begin{center}
  \LARGE \bfseries CURRICULUM VITAE
\end{center}

\begin{bluebox}
\bfseries CONTACT
\end{bluebox}

\blindtext[20]
\end{document}

enter image description here

| improve this answer | |
  • Im sorry, I was hoping I could accept both answers. – Aleksander Dec 29 '17 at 19:02
  • @Aleksander: Concerning the spacings: Use top=0pt,bottom=0pt in the \newtcolorbox options – user31729 Dec 29 '17 at 19:20
  • 1
    Not the day for backticks! There's still an unmatched one in your answer (before '\centering'). – LSpice Dec 29 '17 at 20:42
  • 1
    @LSpice: Oh, thanks for notifying me. I just corrected the error – user31729 Dec 29 '17 at 21:20
6

The problem here is your redefinition of \thepage - it is used by a number packages for auxiliary purposes. The following code replicates your behaviour:

\documentclass{article}

\usepackage{hyperref}

\begin{document}

\renewcommand{\thepage}[1]{\centerline{\arabic{page} of 3}}

Random text.

\end{document}

Specifically, hyperref makes links to the start of the document which requires the use of \thepage. Your \thepage is not just the page number, but also some formatting and additional text.

Instead, use fancyhdr to set your header like so (a suggestion):

\documentclass{article}

\usepackage{fancyhdr,lastpage}
\usepackage{hyperref}

\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\renewcommand{\headrulewidth}{0pt}% Remove header rule
\renewcommand{\footrulewidth}{0pt}% Remove footer rule (default)
\fancyfoot[C]{\thepage{} of \pageref*{LastPage}}

\begin{document}

Random text.

\end{document}

Note the use of lastpage that automatically sets a \label (called LastPage) for the last page of the document, which we use in the footer to reference it's page. That way you can change the "Page X of Y" dynamically.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.