# directed to middle of page instead of start

I'd like to include some pdfs in my file and make a table of contents with hyperlinks to the individual pages. I almost got it to work with \phantomsection and \addcontentsline however if i click the on the link in the table of contents I get directed to the right page but it jumps to the middle of the page and not to the start. How can I fix this?

In order to compile the document you will need pdf files with the corresponding names in your directory. The document is compileable however I get a miktex package manager windows every time I compile it and I get this message "Process started

Unfortunately, the package xcolor could not be installed.

Please check the log file: C:/Users/Tim/AppData/Local/MiKTeX/2.9/miktex/log/pdflatex.log"

Edit: Dear Christian Hupfer. Since I don't have enough reputation to comment this is the only way I know how to communicate with you. How can I improve my question so you can help me?

Code:

\documentclass[12pt]{article}
\usepackage{cite}
\usepackage[german]{babel}
\usepackage[utf8]{inputenc}

\usepackage{pdfpages}

\usepackage[bookmarks,hypertexnames=false,debug]{hyperref}
\usepackage{bookmark}

\begin{document}

\section*{test}

\tableofcontents

\newpage
\phantomsection
\includepdf[pages=-]{asdf}

\newpage
\phantomsection
\includepdf[pages=-]{asdf2}

\newpage
\phantomsection
\includepdf[pages=-]{asdf3}

\end{document}

• Welcome to TeX.SX! Rather use the ngerman option to babel, but that's not the cause of your problem. Also your document is not compilable – user31729 May 22 '16 at 21:52
• Apparently you have two accounts. Please contact the SE staff to get the accounts merged. And your edit did not really improve the post, sorry! – user31729 May 23 '16 at 7:04
• Also see the pdfpages manual, it has an interface for adding stuff to the toc. You have issues here as \includepdf starts a new page, so your \addcontentsline potentially ends on the wrong page – daleif May 23 '16 at 9:43

The correct way of adding something to the ToC with pdfpages is addtotoc (see also How to generate TOC by custom labels at appended documents' beginnings? please)

\documentclass[12pt]{article}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}

\usepackage{pdfpages}

\usepackage[bookmarks]{hyperref}
\usepackage{bookmark}

\begin{document}

\section*{test}
\tableofcontents
\clearpage

\clearpage
\end{document}


Here's the code for 7.pdf (which is generated as usual with pdftex 7.tex and then just copied to 8.pdf as well)

\documentclass{article}

\usepackage{blindtext}

\begin{document}
\section{Beginning \jobname}
\blindtext[50]
\end{document}


I managed to solve this problem by putting:

\usepackage{geometry}
\geometry{paper=a4paper, left=35mm, right=35mm, top=0mm, bottom=30mm}


at the start of the document.

This didn't change the position of the .pdfs since they where the size of a whole page but it automatically made the hyperlinks point to the correct position (start of the .pdf).

Hi this is what I use on Ubuntu 16.04 with texlive-full installed. I recommend to install always a full Latex if you can afford 3 GB on your hard-disc for in majority unneeded packages. The thing is it will most likely prevent problems like yours with the xcolor package.

As you can see I define a new command called fakesection which then does the job for me. It jumps to the top of the page (where the fakesection is, the PDFs are then below.)

\documentclass{article}
\usepackage{pdfpages}

\newcommand{\fakesection}[1]{%
\par\refstepcounter{section}% Increase section counter
% Add more content here, if needed.
}
\usepackage{hyperref}
\hypersetup{
citecolor=black,
filecolor=black,
urlcolor=black
}
\begin{document}
\pagenumbering{gobble}
\includepdf[pages=-]{coverletter.pdf}
\tableofcontents
\pagenumbering{arabic}
\fakesection{Curriculum vitae}
\includepdf[pages=-]{resume.pdf}
\fakesection{Doctoral certificate}
\includepdf[pages=-]{DoctorRerumNaturalium.pdf}

\end{document}