1

I want to keep hyphenation across the document but to be disabled in TOC

This code is not working

\makeatletter
\renewcommand{\@tocrmarg}{2.55em plus1fil}
\makeatother

Here is the MWE

\documentclass[a4paper,12pt]{report}
\usepackage{geometry}
\geometry{margin=2.5cm}
\usepackage{kantlipsum}
\linespread{1.2}

\usepackage[titles]{tocloft} %clear page TOC \newcommand\Dotfill{\cftdotfill{\cftsecdotsep}} \renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}} \setcounter{secnumdepth}{-1} \setcounter{tocdepth}{4}

%----------hypenation--------------------- \usepackage{hyphenat} \emergencystretch=10pt % allows some extra whitespace per line. \exhyphenpenalty=100 % allows using hyphens which were already present. % \hyphenpenalty=10000 % disables hyphens completly.

%-------------Title Chap & Section------------------------ \usepackage{titlesec}

\titleformat{\section}[block]{\filleft\bfseries\Large}{\thesection.}{0.5em}{} \titleformat{\subsection}[block]{\filleft\bfseries\large}{\thesection.}{0.5em}{} \titleformat{\subsubsection}[block]{\filleft\bfseries\large}{\thesection.}{0.5em}{}

\titleformat {\chapter} % command [display] % shape {\Huge\bfseries\raggedleft} % format {} % label {22pt} % separation between label and chapter-title {\Huge}[\vspace{1ex}] % before-code

\titleformat {\section} % command [display] % shape {\Huge\bfseries\raggedleft} % format {} % label {25pt} % separation between label and chapter-title {\Huge}[\vspace{2ex}] % before-code

% \titleformat{\section}{\bfseries\Large\raggedleft}{}{0.5em}{} \titleformat{\subsection}{\bfseries\normalsize\raggedleft}{}{0.5em}{} \titleformat{\subsubsection}{\bfseries\normalsize\raggedleft}{}{0.5em}{}

\titlespacing{\chapter}{0pt}{\baselineskip}{\baselineskip} \titlespacing{\section}{0pt}{4ex}{1ex} \titlespacing{\subsection}{0pt}{0pt}{1ex} \titlespacing{\subsubsection}{0pt}{0pt}{6ex}

\newcommand{\autor}[1]{\textbf{\Large {#1}}\medskip\par} \newcommand{\scoala}[1]{\textit{\normalsize{#1}}\medskip\par} % \newcommand{\prof}[1]{\textit{\small prof. coord. {#1}}\ \smallskip}

\newcommand{\prof}[1]{% \par\begingroup\linespread{1}\small\itshape \begin{tabular}[t]{@{}r@{}}#1\end{tabular}% \par\endgroup\smallskip }

\begin{document}

\cftpagenumbersoff{part} \cftsetrmarg{4cm} \cftsetindents{part}{0cm}{1cm} \cftsetindents{chapter}{1cm}{0cm} \cftsetindents{section}{1cm}{0cm} \cftsetindents{subsection}{2cm}{0cm}

\tableofcontents

\part{This is part I}

\chapter{Specii. Discurs și comportament politicianist în literatura noastră de secol XIX și XX} \begin{flushright} \autor{Student Name} \scoala{Name of School} \prof{Professor 1} \end{flushright}

\kant[1] \end{document}

Edited later

I'm looking for an elegant way to show the TOC, meaning to show that chapters are belonged to the Part. Hyphenation is an ugly way for me. I'm open to any suggestion that will display an elegant TOC for a collective document.

Mafsi
  • 664
  • Does that work? https://tex.stackexchange.com/questions/132266/how-to-turn-off-hyphenation-in-toc-only – Ingmar Oct 22 '21 at 10:31
  • @Ingmar unfortunately is not working for me. I also tried \begingroup \RaggedRight \tableofcontents \endgroup and is not working – Mafsi Oct 22 '21 at 10:36
  • Why do you think that \RaggedRight disables hyphenation? Are you maybe confusing it with \raggedright? – Mico Oct 22 '21 at 10:47
  • @Mico I found it here and I tried> https://tex.stackexchange.com/questions/139740/hyphenation-in-a-table-of-contents-causing-bad-blocks – Mafsi Oct 22 '21 at 10:50
  • @Mafsi -- Please note what I wrote below the accepted answer in the link you provided: "The \RaggedRight [command] won't prohibit all hyphenation. To really turn off all hyphenation in a flush-left setting, use \raggedright (note: no uppercase letters)". Still don't believe me? Here's an excerpt from the abstract of the user guide of the ragged2e package (which provides the \RaggedRight macro): "This package provides new commands and environments ... which are easy to configure to allow hyphenation." – Mico Oct 22 '21 at 11:04
  • 1
    @Mico I'm open to any suggestion that will make a TOC elegant. I'm not good in LaTeX, so I found how to use tocloft today. If there is any way to make Chapters indented in order to show belonging to the Part, I can accepted – Mafsi Oct 22 '21 at 14:05

1 Answers1

4

Try this in your MWE, for which thank you.

\bgroup    % keep non-hyphenation local to the ToC
\hyphenpenalty=10000
\tableofcontents
\egroup

Processing your MWE shows that chapters are indented wrt to parts in the ToC, so you already have that.

enter image description here

Peter Wilson
  • 28,066