2

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
\addcontentsline{toc}{section}{Section without standard heading1}
\includepdf[pages=-]{asdf}



\newpage 
\phantomsection
\includepdf[pages=-]{asdf2}
\addcontentsline{toc}{section}{Section without standard heading2}




\newpage 
\phantomsection
\includepdf[pages=-]{asdf3}
\addcontentsline{toc}{section}{Section without standard heading3}


\end{document}
Tom
  • 5
  • 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 –  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! –  May 23 '16 at 07:04
  • 1
    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 09:43

3 Answers3

2

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

\includepdf[pages=-,addtotoc={1,section,1,Section without standard heading1,firstsection}]{7}
\clearpage
\includepdf[pages=-,addtotoc={1,section,1,Section without standard heading2,secondsection}]{8}
\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}
0

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).

CarLaTeX
  • 62,716
Tom
  • 5
0

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
    \sectionmark{#1}% Add section mark (header)
    \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}% Add section to ToC
    % Add more content here, if needed.
}
\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=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}