17

The problem is that the links (as well as the PDF bookmarks) of abstract, explanation, CV and appendix do not lead to the right pages. abstract leads to the titlepage and appendix to introduction etc. Also the sections belong to the introduction in the bookmarks :( Maybe it is due to the page numbering I did (and I need). I've tried so many things, I'm about to leave it like that :( Please correct my codes if you find the mistake. I'm a beginner and have a lot of difficulties to adjust the options, packages etc...

\makeatletter
\renewcommand*{\@pnumwidth}{3em}  
\makeatother 

\documentclass[a4paper,12pt,ngerman]{article}
\usepackage[
colorlinks, 
linkcolor=black,
filecolor=black,
citecolor=black
]{hyperref}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{eurosym}
\usepackage{latexsym}
\usepackage{graphicx}
\usepackage[abbr,agsmcite,agsm,round]{harvard}
\usepackage{longtable}
\usepackage{portland}
\usepackage{lscape}
\usepackage[onehalfspacing]{setspace}
\usepackage{footmisc}
\usepackage{hyphenat}
\usepackage{rotating}
\usepackage[USenglish]{babel}
\usepackage{array}
\usepackage{tabularx}
\usepackage[latin1]{inputenc}
\usepackage[para]{threeparttable}
\usepackage{caption}
\usepackage[capposition=top]{floatrow}
%\usepackage[subfigure]
\usepackage{currvita}
\usepackage{enumitem}

%\usepackage[latin9]{inputenc}
%\usepackage[T1]{fontenc}

\setcounter{MaxMatrixCols}{12}

\setlength{\skip\footins}{10mm}
\setlength{\evensidemargin}{0cm}
\setlength{\textwidth}{15cm}
\setlength{\textheight}{23cm}
\setlength{\topmargin}{-1cm}
\pagenumbering{arabic}
\renewcommand\harvardand{and}
\renewcommand{\labelenumi}{\Alph{enumi})}
\renewcommand{\labelenumii}{\arabic{enumii}.}
\renewcommand{\cite}{\citeasnoun} 
\renewcommand{\harvardand}{and} 

\begin{document}

\begin{titlepage}
\begin{center}
Title
\end{center}
\end{titlepage}

\newpage
\pagenumbering{Roman}%
\renewcommand{\abstractname}{Acknowledgements}
\begin{abstract}
\noindent
bla bla
\end{abstract}
\newpage

\phantom{T}\vspace{5,3cm}
\renewcommand{\abstractname}{Abstract}
\begin{abstract}
TEXT
\end{abstract}
\addcontentsline{toc}{section}{Abstract}
\newpage

\tableofcontents
\newpage

\listoffigures
\addcontentsline{toc}{section}{List of Figures}
\newpage

\listoftables
\addcontentsline{toc}{section}{List of Tables}
\newpage

\section*{Symbols}

\addcontentsline{toc}{section}{Symbols}%
\newpage

\section*{List of abbreviations}
\begin{tabular}{L{5.5cm} L{9cm}}
\end{tabular}%

\addcontentsline{toc}{section}{List of abbreviations}%
\newpage

\pagenumbering{arabic}
\setcounter{page}{1}%

\section{Introduction}
text text text
\newpage

\section{System and whatever}
\subsection{System}

\setcounter{table}{0}
\setcounter{figure}{0}  
\setcounter{section}{0} 

\newcommand{\initAnhang}{
    \renewcommand{\thepage}{\Alph{section}\ \arabic{page}}
    \newpage
}
\renewcommand\appendix{\par
        \renewcommand\thesection{\Alph{section}}
        \renewcommand\thesubsection{\Alph{section}\arabic{subsection}}
    \renewcommand\thefigure{\Alph{section}\arabic{figure}}
        \renewcommand\thetable{\Alph{section}\arabic{table}}}

\newcommand{\anhang}[1]{
    \setcounter{page}{1}
    \input{#1}
    \newpage
}       

\appendix\initAnhang
\section{Appendix}
%\addcontentsline{toc}{section}{Appendix}%
\subsection{Descriptive Statistics}

\newpage

\nocite{*}
\bibliographystyle{dcu}
\bibliography{bib}
\addcontentsline{toc}{section}{References}
\newpage

\section*{Explanation}
\addcontentsline{toc}{section}{Explanation}
\newpage

\begin{cv}{CV}
\addcontentsline{toc}{section}{CV}%
\end{cv}

\end{document}
3
  • 3
    Create the missing anchors using \phantomsection; for example, \pahntomsection\section*{Explanation} \addcontentsline{toc}{section}{Explanation} Commented Mar 18, 2013 at 16:55
  • Pass the option pdfborder = {0 0 0} to the hyperref pacakge to get rid of the borders around links.
    – jub0bs
    Commented Mar 18, 2013 at 16:56
  • I put hyperref last. pdfborder adds a first page (before title) and puts a comma in there. What's that? The red borders are still there.
    – Anna
    Commented Mar 18, 2013 at 17:44

3 Answers 3

15

Apart from putting hyperref first and not last among the called packages I see nothing too bad in them; but are you sure you need all of them?

Anyway, I'd put fontenc, inputenc and babel first:

\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc} % recommended for German
\usepackage[latin1]{inputenc}
\usepackage[USenglish,ngerman]{babel}

<...other packages...>

\usepackage[
  colorlinks,
  linkcolor=black,
  filecolor=black,
  citecolor=black
  ]{hyperref} %% should be last

\makeatletter
\renewcommand*{\@pnumwidth}{3em}  
\makeatother 

<...other settings...>

Your problem about wrong links is in the order of the commands:

\begin{document}

\pagenumbering{alph} % not to get duplicate links (see Ulrike's comment)
\begin{titlepage}
\begin{center}
Title
\end{center}
\end{titlepage}

\newpage
\pagenumbering{Roman}

\begingroup %% there will be no need to reset \abstractname
\renewcommand{\abstractname}{Acknowledgements}
\begin{abstract}
\noindent
bla bla
\end{abstract}
\endgroup

\newpage

\vspace*{5,3cm} %% the space won't disappear at the top of the page

\phantomsection
\addcontentsline{toc}{section}{Abstract}

\begin{abstract}
TEXT
\end{abstract}

\newpage

\tableofcontents

\newpage

\phantomsection
\addcontentsline{toc}{section}{List of Figures}
\listoffigures

\newpage

<...similarly for the other lists...>

With \phantomsection you set the link position; by putting \addcontentsline just after the page break you know that the reference to the page will be correct.

7
  • The title page needs also an unique page number format (e.g. with pagenumbering{roman}) or pageanchors should be disabled locally. Commented Mar 18, 2013 at 17:18
  • @UlrikeFischer Yes, I always forget about that; fixed.
    – egreg
    Commented Mar 18, 2013 at 17:22
  • phantomsection works for all sections but Appendix. Tried it differently. But it does work for subsections of Appendix. I also put \pagenumbering for the titlepage (before \titlepage). Doesnt change anything. If I put hyperref last, the red borders just dont disappear with any options. pdfborder or colorlinks=true or whatever. \usepackage[T1]{fontenc} makes the font grey/pale. The sections of the main part are still in the bookmarks of introduction.
    – Anna
    Commented Mar 18, 2013 at 17:53
  • phantomsection works for the appendix, too, if I do it like you said: \phantomsection\section{Appendix} \addcontentsline{toc}{section}{Appendix} BUT, then my special pagenumbering for the appendix wont work (I want A1 etc) as shown in the minimal example.
    – Anna
    Commented Mar 18, 2013 at 18:01
  • @Anna Do all page numbers in the appendix be A1 and so on, or should they change according to the appendix they're in?
    – egreg
    Commented Mar 18, 2013 at 18:59
4

Load hyperref as last package and then

...
\phantomsection
\phantom{T}\vspace{5.3cm}
\renewcommand{\abstractname}{Abstract}
\begin{abstract}
TEXT
\end{abstract}
\addcontentsline{toc}{section}{Abstract}
\newpage
...
1
  • 1
    +1 for "Load hyperref LAST." That ought to be the first thing taught.
    – twip
    Commented Jan 5, 2016 at 16:24
0

Finally, I solved the problem. In my case of only one Appendix, this is sufficient:

\setcounter{table}{0}       
\setcounter{page}{1}

\newcommand{\initAnhang}{
    \renewcommand{\thepage}{A\arabic{page}}
    \newpage
}
\renewcommand\appendix{\par
        \renewcommand\thesection{A}
        \renewcommand\thesubsection{A\arabic{subsection}}
        \renewcommand\thetable{A\arabic{table}}}        

\appendix\initAnhang
\section{Appendix}
\subsection{Descriptive Statistics}

Instead of resetting the counter of the sections (that was the problem!), I just typed manually "A" to start the counting of the appendix, the pages and tables from "A" on.

The red borders of the links only disappear when putting hyperref before

\usepackage[abbr,agsmcite,agsm,round]{harvard}

You must log in to answer this question.

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