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?

  • Why do you need a part to make a title page? – Bernard May 15 at 15:04
  • To have it linked in the table of contents. I am using this titlepage for the appendix, which's titlepage is supposed to be insanely similar to the front titlepage. – StckXchnge-nub12 May 15 at 15:07
  • Unless you specify [oneside], \tableofcontents will add a blank page too. – John Kormylo May 15 at 15:21
  • That's true, but not part of the question. I don't care mind the blank pages---I want that the upper and lower text is on the same page as "My Part", even when using \addpart. – StckXchnge-nub12 May 15 at 15:23
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

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.

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}
  • 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 at 15:33
  • You should at least have included hyperref in the MWE. – John Kormylo May 15 at 16:01

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.