0

enter image description hereI desperately need help i tried and searched for everything but not even chatGPT was able to help me at this point maybe its just not possible please enlighten me. So since some of my section have pretty long titles i would like to edit the table of contents, so that the title would break the line earlier than just 1mm before the page number. I just don't like how it looks.

I tried using the \usepackage{titletoc} package and no matter what i try the titles always stay the same i can only move the page numbers or everything else but i can't manage to break the titles earlier so there is more space in between the actual section title and the page number.

I need this for a term paper which is due soon Pls help :(

My Code:

\documentclass[german,a4paper, 12pt]{article}
\usepackage[onehalfspacing]{setspace}
\usepackage[paper=a4paper,margin=1.18in]{geometry}
\usepackage{lipsum}
\usepackage{kotex}
\usepackage{fontspec}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[nottoc,numbib]{tocbibind} 
\usepackage{titletoc}

\titlecontents{section}
  [0pt]
  {\addvspace{10pt}}
  {\thecontentslabel\quad}
  {}
  {\hspace{2em plus 1fil}\contentspage} % Doesnt helppp !!! 
  %only shifts the number 


\usepackage[english]{babel}
\usepackage{csquotes}

% Bibliografie stuff
\usepackage[notes,backend=biber]{biblatex-chicago}
\bibliography{references.bib}

\AtEveryCitekey{\clearfield{issn} \clearfield{isbn}}

\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist 

%STUFF FOR HEADER AND FOOTER 
\usepackage{fancyhdr}
\pagestyle{fancy}

\fancyhead{}
\fancyfoot{}
\fancyfoot[R]{\thepage\ }
\renewcommand{\headrulewidth}{0pt}
7
  • Welcome to TeX StackExchange! Without compilable code and a screenshot of what your problem looks like, it's pretty hard to tell what's happening in your document. Could you please edit your question with this information so that we can better help you?
    – gz839918
    Aug 6, 2023 at 20:22
  • Just curious: Why did you think that turning to ChatGPT for advice might be the way to go?
    – Mico
    Aug 6, 2023 at 20:29
  • At any rate: Do tell us which document class you employ.
    – Mico
    Aug 6, 2023 at 20:30
  • 1
    Well i couldn't find anyone with a similar problem so i thought maybe chatGPT knew it got be farther than before but didn't really help ^^' Aug 6, 2023 at 20:34
  • 1
    your example should be an example of the problem so people can test answers, but it makes no output at all and certainly no table of contents with long titles. Aug 6, 2023 at 20:53

1 Answer 1

0

Whatever else you do, don't bother consulting Chat-GPT4 for usable information on Table of Contents matters in a LaTeX document, at least not for the foreseeable future. :-)

Instead, I suggest you run the following code in the preamble:

\usepackage[titles]{tocloft} % cf. https://www.ctan.org/pkg/tocloft
\makeatletter
\renewcommand{\@tocrmarg}{3.55em} % default: 2.55em
\makeatother

As you can probably guess, the macro \@tocrmarg governs the width of the right-hand margin of the Table of Contents, which contains (among other things) the page numbers associated with the sectioning headers. For the article document class, the default value of this length parameter is 2.55em; my suggestion is to add, say, 1em of space to this parameter. (You're obviously free to make a different choice for the value of this parameter.)

The following screenshot shows the effect this change has on the longest section header contained in the ToC (highlighting added).

enter image description here

\documentclass[ngerman,a4paper,12pt]{article}
\usepackage[onehalfspacing]{setspace}
\usepackage[paper=a4paper,margin=1.18in]{geometry}
\usepackage{lipsum}
\usepackage{kotex}
\usepackage{fontspec}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[nottoc,numbib]{tocbibind} 

%% (what is this filth?)
%%%\usepackage{titletoc}
%%%
%%%\titlecontents{section}
%%%  [0pt]
%%%  {\addvspace{10pt}}
%%%  {\thecontentslabel\quad}
%%%  {}
%%%  {\hspace{2em plus 1fil}\contentspage} % Doesnt helppp !!! 
%%%  %only shifts the number 


\usepackage[english]{babel}
\usepackage{csquotes}

%% (not needed for this example)
%%%% Bibliografie stuff
%%%\usepackage[notes,backend=biber]{biblatex-chicago}
%%%\bibliography{references.bib}
%%%
%%%\AtEveryCitekey{\clearfield{issn} \clearfield{isbn}}
%%%

%% (more filth?)
%%%\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
%%%\let\endchangemargin=\endlist 

%STUFF FOR HEADER AND FOOTER 
\usepackage{fancyhdr}
\pagestyle{fancy}

\fancyhead{}
\fancyfoot{}
\fancyfoot[R]{\thepage\ }
\renewcommand{\headrulewidth}{0pt}


%% new code
\hypersetup{colorlinks,allcolors=blue,linktocpage} % optional

\usepackage[titles]{tocloft}
\makeatletter
\renewcommand{\@tocrmarg}{3.55em} % default: 2.55em
\makeatother

\begin{document}
\tableofcontents

\clearpage

\section{Introduction}
\section{Literature Review}
\section{Analysis of Yeosu's Sustainable Tourism Policies and Initiatives}
\section{Economic Impacts of Tourism in Yeosu}
\section{Assessment of the Balance between Economic Growth and Environmental Conservation}
\section{Conclusion}

\end{document}
4
  • 1
    Oh how I dislike hyphenated words and fixed-width multi-line entries in a TOC. Much nicer, I think, would be to allow TOC entries to be ragged right. That can be done while still enabling a slightly wider space for the page numbers. Aug 6, 2023 at 23:15
  • @barbarabeeton - Thanks. Suppression of hyphenation may be achieved by running \renewcommand{\@tocrmarg}{3em plus1fil}, say.
    – Mico
    Aug 6, 2023 at 23:33
  • 1
    Omg you are a godsend hahaha worked like a charm thanks sooo much <3 Your annotation really got me cackling haha you can really tell i am new to all of this Aug 6, 2023 at 23:59
  • @NicoloVolturana - You're most welcome. And, my thanks for applying the right amount of humor and levity to my annotations. :-)
    – Mico
    Aug 7, 2023 at 8:31

You must log in to answer this question.

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