Prevent pagebreaks before and after part

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}
\Huge\bfseries My Part % (*)
\end{center}

\vfill
\vfill
\vfill

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


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

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
\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?

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
\endgroup
\end{center}

\vfill
\vfill
\vfill

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


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

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
\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