0

I'm trying to create a titlepage that's linked in the table of contents (i.e. clicking the link should send me onto the titlepage). It should look like this:

\documentclass[oneside]{scrbook}

\usepackage{hyperref}
\usepackage{blindtext}

\begin{document}

    \tableofcontents

    \blinddocument

    \begin{titlepage}
        There's some text up here!

        \vfill
        \vfill

        \begin{center}
            \addcontentsline{toc}{chapter}{My Part}
            \Huge\bfseries My Part % (*)
        \end{center}

        \vfill
        \vfill
        \vfill

        And there's more text down here!
    \end{titlepage}
\end{document}

Unfortunately, when you do click the link in the table of contents, you find yourself one page above my titlepage.

To achieve my goal correctly, I've decided to use the part sectioning command. So let's replace the line I marked with (*) with \addpart{My Part}. Unfortunately, you'll notice that the page breaks apart.

What can I do to prevent this from happening? I'm aware that you can change fonts in KOMA-Script classes by redefining \partformat or using \addtokomafont{part}{...}. Are there similar commands to control the pagebreaks?

3 Answers3

1

This seems like an XY problem.

There shouldn't be any need for the \addpart command - if you want hypperref to link to a specific page, simply insert \phantomsection at the correct place in your document. This will act as an anchor for the hyperlink.

In this case, put it before \addcontentsline.

Demonstration:

\documentclass[oneside]{scrbook}

\usepackage{hyperref}
\usepackage{blindtext}

\begin{document}

    \tableofcontents

    \blinddocument

    \begin{titlepage}
        There's some text up here!

        \vfill
        \vfill

        \begin{center}
            \phantomsection % <---- added - this will make sure the hyperlink points to the right place
            \addcontentsline{toc}{chapter}{My Part}
            \Huge\bfseries My Part % (*)
        \end{center}

        \vfill
        \vfill
        \vfill

        And there's more text down here!
    \end{titlepage}
\end{document}

For more details, see When do I need to invoke \phantomsection?

0

This uses a minipage instead of titlepage. \pageanchor causes the TOC to link to the top of the page rather than the location of \refstepcounter.

\documentclass[oneside]{scrbook}

\usepackage{hyperref}
\usepackage{blindtext}

\makeatletter
\newcommand{\pageanchor}{\edef\@currentHref{page.\arabic{page}}}
\makeatother

\begin{document}

    \tableofcontents

    \blinddocument

\clearpage
\thispagestyle{plain}% or empty
\markboth{}{}%
\refstepcounter{part}% position on page usually matters
\pageanchor% to link to top of page
\addcontentsline{toc}{part}{My Part}% use \numberine{\thepart} to add part number.
\noindent\begin{minipage}[t][\textheight][s]{\textwidth}
    There's some text up here!

    \vfill
    \vfill

    \begin{center}

        \Huge\bfseries My Part % (*)
    \end{center}

    \vfill
    \vfill
    \vfill

    And there's more text down here!
\end{minipage}
\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Unfortunately, this doesn't help me. I should have been more specific. I want the titlepage to be literally linked using the hyperref package. The link should lead me onto the titlepage. With addcontentsline, it doesn't seem to manage this correctly. – StckXchnge-nub12 May 15 '19 at 15:33
  • You should at least have included hyperref in the MWE. – John Kormylo May 15 '19 at 16:01
0

I've managed to find the following answer:

https://tex.stackexchange.com/a/474328/175332

You can just "let newpage relax" for a bit by putting it in a group, so that no pagebreaks can occur.

\documentclass[oneside]{scrbook}

\usepackage{hyperref}
\usepackage{blindtext}

\begin{document}

    \tableofcontents

    \blinddocument

    \begin{titlepage}
        There's some text up here!

        \vfill
        \vfill

        \begin{center}
%           \Huge\bfseries My Part % (*)
            \begingroup
            \let\clearpage\relax
            \let\newpage\relax
            \addpart{My Part}
            \endgroup
        \end{center}

        \vfill
        \vfill
        \vfill

        And there's more text down here!
    \end{titlepage}
\end{document}

Note how the link in the table of contents now works perfectly!

Sure, it doesn't seem like a very clean solution.. but I'm willing to live with it if nothing better comes up.