I need to center the title of the parts in the toc. I'm trying these two approaches:

```
\documentclass{article}
\usepackage{hyperref}
\usepackage{tocloft}
\cftpagenumbersoff{part}
\begin{document}
    \tableofcontents
    \addcontentsline{toc}{part}{\centerline{Part A}}
    \addcontentsline{toc}{section}{Section A}
    \addcontentsline{toc}{part}{\hfill{Part B}\hfill}
    \addcontentsline{toc}{section}{Section B}
\end{document}

```

When the PDF is generated, the bookmarks have some of problems:

1. Part A appears in the bookmarks as "toPart A".
2. Part B appears hierarchically under Section A.
3. Part B appears correctly in the bookmarks, but it's not correctly centered in the page.

What can I do to solve this problem? Thank you!
['https://tex.stackexchange.com/questions/373831', 'https://tex.stackexchange.com', 'https://tex.stackexchange.com/users/134459/']
You need to expand the number when you define \parttitle:

```
\documentclass[11pt, oneside, a4paper]{memoir}

\usepackage{lipsum}

\newcounter{DocPart}
\setcounter{DocPart}{0}
\newcommand{\pageNumber}{}
\newcommand{\parttitle}{}
\renewcommand{\part}[1]{%
    \ifnum\theDocPart = 0
         \renewcommand{\parttitle}{A. #1}
         \renewcommand{\pageNumber}{A.\thepage}
         \cftaddtitleline{toc}{part}{A. #1}{}
    \else
        \edef\parttitle{A\theDocPart. #1}%<----
        \edef\pageNumber{A\theDocPart.\noexpand\thepage}%<-----
        \cftaddtitleline{toc}{part}{A\theDocPart. #1}{}
    \fi
    \stepcounter{DocPart}
}

\makepagestyle{test}
\makeoddhead{test}{\pageNumber}{}{\parttitle}
\pagestyle{test}

\begin{document}

\part{PART NUMBER ZERO} % I want this to say A. PART NUMBER ZERO in the header, which it does
\chapter{FAKE CHAPTER ONE}
\theDocPart \thispagestyle{test}
\lipsum[88]
\chapter{FAKE CHAPTER TWO}
\thispagestyle{test}
\lipsum[120]

\newpage

\tableofcontents*

\part{PART NUMBER ONE} % I want this to say A1. PART NUMBER ONE in the header
\chapter{FAKE CHAPTER TWO}
\thispagestyle{test}
\lipsum

\part{PART NUMBER TWO} % I want this to say A2. PART NUMBER TWO in the header
\chapter{FAKE CHAPTER THREE}
\thispagestyle{test}
\lipsum

\end{document}

```
The setting of the header is as far as I know asynchronous. However, expanding the `\theDocPart` in `\pageNumber` and `\parttitle` does work:

```
\documentclass[11pt, oneside, a4paper]{memoir}

\usepackage{lipsum}

\newcounter{DocPart}
\setcounter{DocPart}{0}
\newcommand{\pageNumber}{}
\newcommand{\parttitle}{}
\renewcommand{\part}[1]{
    \ifnum\theDocPart = 0
         \renewcommand{\parttitle}{A. #1}
         \renewcommand{\pageNumber}{A.\thepage}
         \cftaddtitleline{toc}{part}{A. #1}{}
    \else
        \xdef\parttitle{A\theDocPart. #1}
        \xdef\pageNumber{A\theDocPart.\noexpand\thepage}
        \cftaddtitleline{toc}{part}{A\theDocPart. #1}{}
    \fi
    \stepcounter{DocPart}
}

\makepagestyle{test}
\makeoddhead{test}{\pageNumber}{}{\parttitle}
\pagestyle{test}

\begin{document}

\part{PART NUMBER ZERO} % I want this to say A. PART NUMBER ZERO in the header, which it does
\chapter{FAKE CHAPTER ONE}
\thispagestyle{test}
\lipsum[88]
\chapter{FAKE CHAPTER TWO}
\thispagestyle{test}
\lipsum[120]
\newpage

\tableofcontents*

\part{PART NUMBER ONE} % I want this to say A1. PART NUMBER ONE in the header
\chapter{FAKE CHAPTER TWO}
\thispagestyle{test}
\lipsum

\part{PART NUMBER TWO} % I want this to say A2. PART NUMBER TWO in the header
\chapter{FAKE CHAPTER THREE}
\thispagestyle{test}
\lipsum

\end{document}

```