2

I'm working in memoir class and creating ToC with both short and (sometimes very) long chapter title. I need to:

  1. Adjust horizontal spacing between part\chapter number and the title so they won't be overlapped, no matter how long the digits\numbers are. The left part of longer-number title doesn't have to be aligned with the shorter one. I prefer the spacing would be automatic/adjustable (depends on the part or chapter digit/number). Thanks. overlapping chapter number and title enter image description here
  2. Sometimes there's an unwanted vertical spacing between two chapter title in random. unwanted vertical spacing

What is the proper way to fix them? I've tried to search for same problems here, but still no luck. Accident/unwanted vertical spacing is still bothering. Thanks.

\documentclass[12pt,twoside]{memoir}
\usepackage[paperwidth=140mm, paperheight=210mm, margin=20mm]{geometry}
\usepackage{titletoc}

\renewcommand\thepart{\arabic{part}}

% simulate larger part and chapter number
\setcounter{part}{50}
\setcounter{chapter}{1200}

\begin{document}

\tableofcontents

\part{This is My First Part}
\chapter{This is first chapter}
\chapter{This is very very long chapter title}
\chapter{Next chapter goes here}

\part{This is My Second Chapter}
\chapter{Very long chapter title also goes here}
\chapter{Another chapter goes here}
\chapter{Another chapter goes here}
\chapter{Another chapter goes here}

% ...and so on...

\end{document}

UPDATE:

In addition to my Pastebin, here's the replicated main.tex. Hope this helps. Thank you.

\documentclass[12pt,twoside]{memoir}
\usepackage[paperwidth=140mm, paperheight=210mm, margin=20mm]{geometry}
\usepackage{libertine}
\usepackage{graphicx}
\usepackage[svgnames]{xcolor}
\usepackage{framed}
\usepackage{fourier-orns}
\usepackage{bbding}
\usepackage{pdfpages}
\usepackage{lipsum}

% quote
\newcommand*\openquote{\makebox(25,-22){\scalebox{5}{``}}}
\newcommand*\closequote{\makebox(25,-22){\scalebox{5}{''}}}
\colorlet{shadecolor}{Azure}

\makeatletter
\newif\if@right
\def\shadequote{\@righttrue\shadequote@i}
\def\shadequote@i{\begin{snugshade}\begin{quote}\openquote}
\def\endshadequote{%
  \if@right\hfill\fi\closequote\end{quote}\end{snugshade}}
\@namedef{shadequote*}{\@rightfalse\shadequote@i}
\@namedef{endshadequote*}{\endshadequote}
\makeatother
% END quote setting

\usepackage{type1cm}
\usepackage{lettrine}
\usepackage{pdfpages}

\chapterstyle{dash}

\usepackage{textcomp}
\usepackage{gensymb}

\renewcommand{\cftchapterfont}{\normalfont}

% ToC Setting
% http://tex.stackexchange.com/questions/201358/styling-toc-dot-leader-using-emdash-and-other-formatting-requirements
% Redefinitions of \part-entry in ToC
% \renewcommand{\cftpartname}{Part~}
\renewcommand{\cftpartname}{Part~}
\renewcommand{\cftpartaftersnum}{:}
\renewcommand{\cftpartleader}{---}
\renewcommand{\cftpartformatpnum}[1]{%
  \cftpartformatpnumhook{#1}%
  {\cftpartpagefont #1}}
\renewcommand{\cftpartafterpnum}{\hfill\null}

% Redefinition of \chapter-entry in ToC
% \renewcommand{\cftchaptername}{Chapter~}
% \renewcommand{\cftchapteraftersnum}{:}
\renewcommand{\cftchaptername}{}
\renewcommand{\cftchapteraftersnum}{.}
\renewcommand{\cftchapterleader}{---}
\let\oldcftchapterfont\cftchapterfont
\renewcommand{\cftchapterfont}{\oldcftchapterfont\mdseries}
\renewcommand{\cftchapterformatpnum}[1]{%
  \cftchapterformatpnumhook{#1}%
  {\cftchapterpagefont #1}}
\let\oldcftchapterpagefont\cftchapterpagefont
\renewcommand{\cftchapterpagefont}{\oldcftchapterpagefont\mdseries}
\renewcommand{\cftchapterafterpnum}{\hfill\null}

% Distance between part and chapter
\setlength{\cftbeforepartskip}{1em} % part
\setlength{\cftbeforechapterskip}{3pt} % chapter

% Arabic-style page numbering
% http://tex.stackexchange.com/questions/129592/add-parts-to-the-table-of-contents
\renewcommand\thepart{\arabic{part}}

% change font size of ToC item & number
% \renewcommand{\cftpartfont}{\Large\bfseries}
\renewcommand{\cftpartfont}{\normalsize\bfseries}
\renewcommand{\cftpartpagefont}{\normalsize\bfseries}

% GOOD (by Werner)
% http://tex.stackexchange.com/questions/201940/toc-content-spacing-and-related-formatting?noredirect=1#comment470627_201940
\renewcommand{\partnumberlinebox}[2]{#2 }
\renewcommand{\chapternumberlinebox}[2]{#2 }

% Past:
%\setlength{\cftchapternumwidth}{2em}
%\setlength{\cftpartnumwidth}{2em}

% --- END ToC settings

% RUNNING HEADER
% The following code have been found in Peter Wilsons Memoir manual in chapter 7 (page127)
\makepagestyle{My_pagestyle} % Create a new pagestyle

% Following code to edit the pagestyle
\makepsmarks{My_pagestyle}{\nouppercaseheads

% This is where we specify what \leftmark and \rightmark contains
%\createmark{chapter}{both}{nonumber}{}{\space}
%\createmark{section}{right}{nonumber}{}{\space}
% Change "shownumber" to "nonumber" if you don't want the chapter/section number displayed at the header.
\createmark{title}{left}{nonumber}{}{\space}
\createmark{chapter}{right}{nonumber}{}{\space}
\createplainmark{toc}{both}{\contentsname}
\createplainmark{lof}{both}{\listfigurename}
\createplainmark{lot}{both}{\listtablename}
\createplainmark{bib}{both}{\bibname}
\createplainmark{index}{both}{\indexname}
\createplainmark{glossary}{both}{\glossaryname}}
% Might want to keep those, see the manual for further information.

% The following is where you tweek your header
% http://hstuart.dk/2007/06/12/styling-the-page-footer-and-header/
% For verso pages
\makeevenhead{My_pagestyle}{\normalfont\thepage\hskip.5cm\vrule\hskip.5cm\footnotesize\Booktitle}{}{}
% For recto pages
\makeoddhead{My_pagestyle}{}{}{\footnotesize\rightmark\hskip.5cm\vrule\hskip.5cm\normalfont\thepage}

% Activate your new pagestyle
\pagestyle{My_pagestyle}

% --- END

% The 'Part' page
% http://tex.stackexchange.com/questions/49512/part-style-in-memoir-class/49534#49534
\renewcommand\partname{Part}
\renewcommand*{\partnamefont}{\normalfont\large} % part name
\renewcommand*{\partnumfont}{\normalfont\large} % part number
\renewcommand*{\parttitlefont}{\normalfont\LARGE} % part title
\renewcommand{\midpartskip}{\par\parbox{0.5in}{\hrulefill}\par} 

\renewcommand{\beforepartskip}{\vspace*{\fill}}
\renewcommand{\afterpartskip}{\vspace*{\fill}}

% Set book title and the writer's name
% http://tex.stackexchange.com/questions/195863/include-document-title-in-memoir-class-header
% http://latex-community.org/forum/viewtopic.php?f=47&t=15857
\def\Booktitle{My book title goes here}
\title{\Booktitle}
\author{The writer's name}
\date{}

% Let's do it
\begin{document}

\frontmatter

% ENDORSEMENT
\pagestyle{empty}
\include{./include/00-prelims-pages/endorsement}
\cleardoublepage % Start a new odd page (manually)

% BOOK TITLE
\include{./include/00-prelims-pages/booktitle-01}
\cleardoublepage % Start a new odd page (manually)
\include{./include/00-prelims-pages/booktitle-02}

% BOOK INFO, ISBN, ETC
\include{./include/00-prelims-pages/kdt}

% DEDICATION
\include{./include/00-prelims-pages/dedication}

\pagestyle{My_pagestyle}

% FOREWORDS
\include{./include/00-prelims-pages/intro}
\cleardoublepage % Start a new odd page (manually)

% TOC
\tableofcontents

% SET PAGE NUMBERING (1, 2, 3.. for main content)
\mainmatter

% PROLOG
\include{./include/00-prelims-pages/prolog}


% PART 1
\part{This is Part}
\include{./include/part-01/01}
\include{./include/part-01/02}
\include{./include/part-01/03}
\include{./include/part-01/04}
\include{./include/part-01/05}
\include{./include/part-01/06}

% PART 2
\part{Part}
\include{./include/part-02/01}
\include{./include/part-02/02}
\include{./include/part-02/03}
\include{./include/part-02/04}
\include{./include/part-02/05}
\include{./include/part-02/06}
\include{./include/part-02/07}
\include{./include/part-02/08}
\include{./include/part-02/09}
\include{./include/part-02/10}
\include{./include/part-02/11}

% PART 3
\part{Part}
\include{./include/part-03/01}
\include{./include/part-03/02}
\include{./include/part-03/03}
\include{./include/part-03/04}

% ...and so on...

% ABOUT THE WRITER
\cleardoublepage % Start a new odd page (manually)
\pagestyle{plain}
\include{./include/about-writer}

% ...and so on...

\end{document}
  • Perhaps you can use the tocloft package for adjust your TOC for avoid those character collisions. – Aradnix Sep 19 '14 at 2:59
  • I am not an expert about memoir, but I wonder about this feature. Do you really need 50 parts, 1500 etc. chapters? – user31729 Sep 19 '14 at 3:05
  • 1
    @Aradnix tocloft is already build into memoir, so see the chapter about toc formatting in the memoir manual – daleif Sep 19 '14 at 3:29
  • Your minimal example only replicates problem (1), not (2). To solve (1), add \renewcommand{\partnumberlinebox}[2]{#2 } \renewcommand{\chapternumberlinebox}[2]{#2 } to your preamble. It allows for a flexible spacing around the number for both \parts and \chapters. – Werner Sep 19 '14 at 3:45
  • @daleif I've never used memoir, I have reviewed its documentation very briefly, but it is a useful data, thanks. – Aradnix Sep 19 '14 at 5:14
4

Your minimal example only replicates problem (1), not (2). To solve (1), add

\renewcommand{\partnumberlinebox}[2]{#2 }
\renewcommand{\chapternumberlinebox}[2]{#2 }

to your preamble. It allows for a flexible spacing around the number for both \parts and \chapters, effectively discarding the requirement to place the part/chapter number inside a box of (fixed) width given by #1.

enter image description here

\documentclass{memoir}
\renewcommand\thepart{\arabic{part}}
\renewcommand{\partnumberlinebox}[2]{Part~#2 }
\renewcommand{\chapternumberlinebox}[2]{#2 }

% simulate larger part and chapter number
\setcounter{part}{50}
\setcounter{chapter}{1200}

\begin{document}

\tableofcontents

\part{This is My First Part}
\chapter{This is first chapter}
\chapter{This is very very long chapter title}
\chapter{Next chapter goes here}

\part{This is My Second Chapter}
\chapter{Very long chapter title also goes here}
\chapter{Another chapter goes here}
\chapter{Another chapter goes here}
\chapter{Another chapter goes here}

% ...and so on...

\end{document}

In the example above I've prepended each \part-like entry with Part~ as well.

  • Thank you, Werner. I've tried it but still can't replicate the problem. I'm trying to re-post the code. Thank you. UPDATE: The unwanted vertical spacing sometimes also occurred between part name and its chapters beneath. – Eko san Sep 19 '14 at 17:52
  • @Ekosan: You can post you .aux and/or .toc file somewhere (like Pastebin) for the community to inspect. Not sure what it might deliver, but it could help... – Werner Sep 19 '14 at 18:16
  • Okay, will try soon. UPDATE: here's the .aux file (replicated). I'm sorry, I can't show the real wording. I replace the real ones with plain wording to match the real pattern (words count, words number, mark, etc) as close as possible. Does it really matter? Hope this helps. Thank you. – Eko san Sep 19 '14 at 20:08
  • @Ekosan: Nothing in the .aux indicate that spaces are added to to the ToC. If you can identify the chapters around which it happens, examine their individual .aux files. – Werner Sep 19 '14 at 20:19
  • I've deleted all .aux files, but still no luck. Still have 3 unwanted spacing issues (1 between part and chapter, the rest are between chapters). Thanks. – Eko san Sep 19 '14 at 21:00
1

Werner's answer seemed very authoritative, but when I tried it, I got the error

! LaTeX Error: \partnumberlinebox undefined.

Consulting the memoir manual suggested to me that the correct incantation was actually

\renewcommand\partnumberline[1]{#1\hspace{1em}}

and indeed that worked great for me! Here's my test case:

\documentclass{memoir}
% \renewcommand\partnumberlinebox[2]{#2\hspace{1em}}  % attempt 1, failed
% \renewcommand\partnumberline[1]{#1\hspace{1em}}     % attempt 2, worked

\begin{document}
\tableofcontents
\part{First}
\part{Second}
\part{Third}
\part{Fourth}
\end{document}

It appears that \partnumberline is supported at least as far back as memoir.cls version 2011/03/06 v3.6j (which is what I have), and \partnumberlinebox is a newer addition. I'm not sure why one would prefer one over the other.

  • I cannot reproduce your error, both solutions work. Maybe you have an outdated version of memoir.cls. The current version is something like 2016/05/16 v3.7f . – gernot Feb 24 '17 at 23:14
  • Correct, my system has 2011/03/06 v3.6j. I'll edit my answer to reflect that. – Quuxplusone Feb 25 '17 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.