0

I'm going mad with this issue. I have a book divided in parts, I currently have the following TOC:

enter image description here

but I would like to hide the page number on the right and have the part title centered. The LaTeX code is:

\renewcommand*\part[1]{

\vspace*{160pt}

\addtocounter{part}{1}

\setcounter{chapter}{0}

{\centering\sffamily 

    \Large \textsc{Parte} \Roman{part}

    \par\nobreak

    \vskip 14pt

    \huge \uppercase{#1} \par\nobreak

}

\addcontentsline{toc}{part}{\centering {Parte \thepart} \\ \numberline{} \centering{#1} 

}

\vskip 40pt

}

Where is the mistake please?

I'm used to writing code in languages like C, Php, Javascript and there the arguments to pass to a function are clearly visible. Whereas here I have a function \part with one argument, the title #1, while \thepart is something like a global variable. Where is the page number though? I expected something like \thecontentspage, here there is nothing of the like and still the page number appears, not required, at the end of the line. Where is the instruction to write the number to the right?

This is confusing to me. I understand LaTeX follows a paradigm, a logic quite different from other programming languages, but I haven't yet understood this logic.

How can I remove that number on the right and have the title centered?

of course it is a book so ... \documentclass[12pt]{book}


Reply

I'm not sure to understand MWE, I see there is a debate about this requirement. I guess a complete .tex file producing a minimal PDF, something I did for other problems.

But to be complete I have to add everything before the \begin{document}, 159 lines plus a minimal example, at least two parts and some dummy chapters and sections. More than 200 lines ...

here is the resulting TOC enter image description here

The problem is still there.

Hope someone has the time to have a look to the code below.

\documentclass[12pt]{book}

\usepackage[italian,english,german]{babel} 
\usepackage{fontspec}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage[linktoc=all]{hyperref}
\usepackage{titletoc}
\usepackage[odd]{emptypage}
\usepackage{lmodern} 
\usepackage{ulem}
\usepackage{enumitem}
\usepackage{longtable}
\usepackage{caption}
\usepackage{multirow}
\usepackage{amssymb}
\usepackage{amsfonts}

\usepackage{amsmath}
\usepackage{verbatim}
\usepackage{ragged2e}

\usepackage{makeidx}
\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage{mystyle_17x24}

\title{La crittografia della Repubblica di Venezia}

\author{Paolo Bonavoglia \\
  {\tt [email protected]} 
}

\date{\today}

\newcommand*{\tabbox}[2][t]{%
    \vspace{0pt}\parbox[#1][3.7\baselineskip]{1cm}{\strut#2\strut}}

\renewcommand\labelitemi{---}

\newcommand*\FancyNulla{%
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
}

\newcommand*\cleartorightpage{%
    \cleardoublepage
    \FancyNulla
}

\newcommand*\FancyParte[1]{%
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\fancyhead[LE]{\thepage #1}
\fancyhead[CE]{Parte \thepart}
\fancyhead[RE]{}
\fancyfoot[LO]{}
\fancyfoot[CO]{} 
\fancyfoot[RO]{\thepage} 
}

\newcommand*\FancyIndice[1]{%
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\fancyhead[LE]{\thepage}
\fancyhead[CE]{#1}
\fancyhead[RE]{}
\fancyhead[LO]{}
\fancyhead[CO]{#1} 
\fancyhead[RO]{\thepage} 
}
\newcommand*\FancyParteSenzaNumeri[1]{%
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\fancyhead[LE]{}
\fancyhead[CE]{#1}
\fancyhead[RE]{}
\fancyhead[LO]{}
\fancyhead[CO]{} 
\fancyhead[RO]{} 
}

\newcommand*\FancyCapitolo[1]{%
\fancyfoot{} % clear all footer fields
\fancyhead[LE]{\thepage}
\fancyhead[CE]{Parte \thepart}
\fancyhead[RE]{}
\fancyhead[LO]{}
\fancyhead[CO]{Cap. \! \thechapter \; #1}
\fancyhead[RO]{\thepage}

}

\newcommand*\Figura[4]{%
    \begin{figure}[ht]\begin{center}\includegraphics[#1]{#2}            \caption{\small \textit{#3}}
    \label{#4}
    \end{center}\end{figure}
}

\setcounter{table}{0}

\renewcommand*\part[1]{
    \vspace*{160pt}
    \addtocounter{part}{1}
    \setcounter{chapter}{0}
    {\centering\sffamily 
        \Large \textsc{Parte} \Roman{part}
        \par\nobreak
        \vskip 14pt
        \uppercase{#1} \par\nobreak
    }
    
    \addcontentsline{toc}{part}{\centering {Parte \thepart} \\ \numberline{} \centering{#1}  }
    
    \vskip 40pt
}


\titlecontents{chapter}[0pt \addvspace{2em} \hspace*{-2.3em}]
        {\thecontentspage \quad Capitolo \thecontentslabel{} \\}%
        {\hspace{-4pt} }
    {}
    {}
    {}


\titlecontents*{section}[0pt\small]
    {\upshape\-}
    {\thecontentslabel {\;}}
    {}
    {,  {\thecontentspage}}
    [][\ \textendash\ ][]

\titlecontents*{subsection}[0pt\small]
    {\itshape\-}
    {\; \thecontentslabel {\;}}
    {}
    {,  {\upshape\thecontentspage}}
    [][\ \textendash\ ][]

% You can include more LaTeX packages here 
\setlength{\abovecaptionskip}{3pt plus 2pt minus 1pt}
\setlength{\belowcaptionskip}{4pt plus 2pt minus 1pt}

\counterwithout{footnote}{chapter}
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}


\makeindex

\begin{document}

\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\pagenumbering{roman}

\selectlanguage{italian} %%% remove comment delimiter ('%') and select language if required

\tableofcontents

\pseudochapter{Prefazione}

\cleardoublepage

\setcounter{part}{0}%restore counter
\pagenumbering{arabic}


\part{Le cifre della Repubblica di Venezia}
\clearpage

\FancyParte{Le cifre della Repubblica di Venezia}



\FancyCapitolo{Organizzazione}

\clearpage

\section{La necessità di scrivere in cifra}

\clearpage
xxxx
\clearpage

\section{Dummy}

\section{Useless}

\part{Dummy part}

\section{La necessità di scrivere in cifra}

\clearpage
xxxx
\clearpage

\section{Dummy}

\section{Useless}

\end{document}
7
  • 1
    How a part is shown in the toc depends from a command you don't mention. So don't show only some snippets but make a small but complete example. Commented Apr 10, 2023 at 8:35
  • 1
    Further to Ulrike's point, we do not now even what your document class is, the answer could vary depending on if you are using book, memoir or another similar class. Could you make a Minimal Working Example (MWE) please?
    – piJT
    Commented Apr 10, 2023 at 8:46
  • well the M in MWE means "minimal". So remove from your preamble unrelated parts, you can test that easily: remove e.g. enumitem and test if the problem is still there. Then remove all the fancyhdr code. etc Commented Apr 10, 2023 at 10:37
  • Hi @Paolo It's an intriguing question. From what I gather in your example, you want to achieve the ToC layout used at the turn at the nineteenth century in books written by some British scientists back then. They divided their books into parts and chapters with the sections with pages (or sometimes not even that) in paragraph style. Is that what you want to achieve? An example of what I mean can be found here.
    – alchemist
    Commented Apr 10, 2023 at 14:31
  • Shouldn't the line \renewcommand*\part[1]{ be \renewcommand*{\part}[1][]{? That is enclosing the to be redefined \part in curly brackets and adding an extra [ ] to the command.
    – alchemist
    Commented Apr 10, 2023 at 16:44

2 Answers 2

0

Use this code

\makeatletter
\def\addcontentslinenopage#1#2#3{% added <<<<<<<<<<<<<<
\begingroup
\phantomsection%
\addtocontents{#1}{\protect\contentsline{#2}{#3}{}{\@currentHref}\protected@file@percent}%
\endgroup
}
\makeatother

\renewcommand*\part[1]{%
    \vspace*{160pt}
    \addtocounter{part}{1}
    \setcounter{chapter}{0}
    {\centering\sffamily 
        \Large \textsc{Parte} \Roman{part}%
        \par\nobreak
        \vskip 14pt
        \uppercase{#1} \par\nobreak
    }   
        \addcontentslinenopage{toc}{part}{\parbox{\linewidth}{\centering Parte \thepart \\  #1}}% changed <<<<<<<<<<     
    \vskip 40pt
}

to suppress the page numbers that appear to the right of the part titles in the ToC and center the part titles.

The page numbers are added by the command \addcontentsline.

c

Use

\tableofcontents
\thispagestyle{empty} %<<<<<<<<<<<<

to suppress the page number of the ToC page.

0

The key idea I found at https://tex.stackexchange.com/a/455423/107497 was to put the part and its title for the toc into a parbox. I'm not entirely sure why this works the way it does (if you remove the space in \thecontentslabel} }, the first word of the title jumps up a line), but it appears to get the job done. And as long as you're loading titletoc, you might as well make full use of it to assist with your \part formatting.

\documentclass[openany]{book}
\usepackage[italian,english,german]{babel} 
\usepackage[newparttoc]{titlesec}
\usepackage{titletoc}

\titleclass{\part}{straight}
\titleformat{\part}[display]{\sffamily\centering}{\Large\textsc{Parte} \Roman{part}}{14pt}{\huge\uppercase}
\titlespacing{\part}{0pt}{160pt}{40pt}

% https://tex.stackexchange.com/a/455423/107497
\titlecontents{part}[0pt]
    {\centering}
    {\parbox{\linewidth}{\centering Parte~\thecontentslabel} }
    {}
    {}

\titlecontents*{section}[0pt\small]
    {\upshape\-}
    {\thecontentslabel\;}
    {}
    {, \thecontentspage}
    [\ --\ ]

\counterwithin{chapter}{part}

\usepackage{lipsum}

\begin{document}

\tableofcontents

\part{Le cifre della Repubblica di Venezia}
\section{La necessità di scrivere in cifra}
\lipsum[1]
\section{Dummy}
\lipsum[1]
\section{Useless}
\lipsum[1]

\part{Dummy Part}
\section{La necessità di scrivere in cifra}
\lipsum[2]
\section{Dummy}
\lipsum[2]
\section{Useless}
\lipsum[2]

\end{document}

code output

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .