3

I am trying to change the word "Chapter" to "Story" in the ToC. I have successfully changed it in the chapter headings, but the ToC is giving me trouble.

I tried to alter this answer, but it hasn't quite given me what I want. As you can see below, in the ToC, the word "Story" has been placed on the chapter title line instead of the line above it. Instead, I want "Chapter X" to say "Story X".

\documentclass[11pt]{book}

\usepackage{framed}
\usepackage[compact,pagestyles,clearempty]{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}

% % % ToC modified from https://tex.stackexchange.com/questions/35825/pretty-table-of-contents
\patchcmd{\tableofcontents}{\contentsname}{\rmfamily\contentsname}{}{}

\renewenvironment{leftbar}
  {\def\FrameCommand{\hspace{26.7em}%
    {\vrule width 2pt depth 3pt}\hspace{1em}}%
    \MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
  }
 {\endMakeFramed}

\titlecontents{chapter}
  [0em]{\vspace*{0.3\baselineskip}}
  {\parbox{14.8em}{% mainmatter
    \hfill\huge\rmfamily\bfseries\thecontentspage}%
   \vspace*{-2.4\baselineskip}\leftbar\textsc{\normalsize\chaptername~\thecontentslabel}\\\normalsize\rmfamily}
  {\parbox{14.55em}{% frontmatter
    \hfill\huge\rmfamily\bfseries\thecontentspage}%
   \vspace* {-1.95\baselineskip}\leftbar\normalsize\rmfamily}
  {\endleftbar}
% % %

    %changes "Chapter" to "Story" in the chapter headings   
    \makeatletter
    \renewcommand\@chapapp{Story}
    \makeatother
    %

%this is where I need help
\makeatletter
\let\orig@chapter\@chapter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{chapter}%
                                   {Story~\protect\numberline{\thechapter}#1}%
                       \else
                         \addcontentsline{toc}{chapter}{#1}%
                       \fi
                    \else
                      \addcontentsline{toc}{chapter}{#1}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}
\makeatother
%   
\begin{document}

\tableofcontents
\frontmatter
\chapter{Introduction}
\mainmatter
\chapter{A chapter}
\chapter{Another chapter}

\end{document}

enter image description here

UPDATE: As requested in the comments, here is an image of the desired final output.

enter image description here

AML
  • 2,265
  • You do not want page numbers in you table of contents, and the chapter titles in the table of contents have to begin more or less in the middle of the page? – Bernard May 10 '18 at 08:29
  • I don't understand your question. The page numbers are on the left-side of the black bar, and the chapter number and name are stacked on the right-side of the black bar. I'll change the position of the word "Contents". – AML May 10 '18 at 10:06
  • Sorry, I didn't notice that. Why didn't use use titletoc, that you load, to do that? – Bernard May 10 '18 at 10:12
  • Because I'm a noob? Please suggest an answer. Would love to learn a better way. – AML May 10 '18 at 10:13
  • I don't have time at the moment, but I'll post some code later. I'm sure it can be simplified. – Bernard May 10 '18 at 11:43
  • @Bernard Actually, a very simple solution is to replace {\normalsize\chaptername~\thecontentslabel} with {\normalsize{Story}~\thecontentslabel}. And also delete everything in the preamble below %this is where I need help. – AML May 10 '18 at 23:58

1 Answers1

5

I do not know if it is the most powerful solution but you can redefine the name of some structures like the following:

\renewcommand\contentsname{New contents name} 
\renewcommand\listfigurename{New image contents name} 
\renewcommand\listtablename{New table index name} 
\renewcommand\bibname{New bibliography name} 
\renewcommand\glossaryname{New glossary name} 
\renewcommand\acronymname{New Acronmym name} 
\renewcommand\figurename{New figure description} 
\renewcommand\tablename{New table description} 
\renewcommand\partname{New part description} 
\renewcommand\chaptername{New chapter name} 
\renewcommand\appendixname{New appendix} 
\renewcommand\abstractname{New abstract name}

Add the following line to your code:

...
\renewcommand\chaptername{Story} %<--- to change the name of chapters
\begin{document}
...

Result:

enter image description here

Some update:

This is my attempt looking for what is required; in the case of the content index, although it can be left empty using the command \renewcommand\contentsname{}; I decided to put some decoration and try with colors, to place the elements of the index on the left, change the values of \hspace to 5 em, in the leftbar environment, 4 em in the two parbox of \titlecontents, I added some titlesec code to change the space on the text titles ...

SOME CHANGES:

TOC enter image description here

MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[11pt]{book}

\usepackage{framed}
\usepackage[compact,pagestyles,clearempty]{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}
\usepackage{adforn} %decoration gliphs
\usepackage{lipsum} % to add dummy text
\usepackage{xcolor}
\definecolor{KLEIN}{HTML}{002fa7}
\definecolor{RED}{HTML}{ff0000}
%This is titlesec code to change the chapter display space above.
\titleformat{\chapter}[display] 
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}   
\titlespacing*{\chapter}{0pt}{-50pt}{40pt}  

% % % ToC modified from https://tex.stackexchange.com/questions/35825/pretty-table-of-contents

% Here dark code that requires deciphering, has no explanatory comments, names of functions and global variables, nothing ... possibly focused on very latex experts.
\patchcmd{\tableofcontents}{\contentsname}{\rmfamily\contentsname}{}{}

\renewenvironment{leftbar}{%Defining some decoration
    \def\FrameCommand{\hspace{5em}{\color{KLEIN!60}\vrule width 2pt depth 6pt} \hspace{10pt}}%
    \MakeFramed {\advance\hsize-\width \FrameRestore}}%
{\endMakeFramed}

\titlecontents{chapter}[0em]{\vspace*{0.3\baselineskip}}
    {\parbox{4em}{% mainmatter
            \hfill\huge\rmfamily\bfseries\thecontentspage}%
            \vspace*{-2.4\baselineskip}\leftbar\textsc{\normalsize\chaptername~\thecontentslabel}\\\normalsize\rmfamily
    }
    {\parbox{4em}{% frontmatter
            \hfill\huge\rmfamily\bfseries\thecontentspage}%
            \vspace* {-1.95\baselineskip}\leftbar\normalsize\rmfamily
    }
    {\endleftbar}

%this is where I need help
\makeatletter
\let\orig@chapter\@chapter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
    \refstepcounter{chapter}%
    \typeout{\@chapapp\space\thechapter.}%
    \addcontentsline{toc}{chapter}%
    {\protect\numberline{\thechapter}#1}%
    \else
    \addcontentsline{toc}{chapter}{#1}%
    \fi
    \else
    \addcontentsline{toc}{chapter}{#1}%
    \fi

    \chaptermark{#1}%
    \addtocontents{lof}{\protect\addvspace{10\p@}}%
    \addtocontents{lot}{\protect\addvspace{10\p@}}%
    \if@twocolumn
    \@topnewpage[\@makechapterhead{#2}]%
    \else
    \@makechapterhead{\adfflatleafleft\,#2\,\adfflatleafright}%
    \@afterheading
    \fi}

\makeatother
%
%treiying to include coloar and decorations
\renewcommand\contentsname{\color{KLEIN!50!RED}{\adftripleflourishleft\, *\, \adftripleflourishright}} 
\renewcommand\chaptername{Story}   
\begin{document}
    \tableofcontents
    \frontmatter
    \chapter{Introduction}
    \lipsum[1-7]
    \mainmatter
    \chapter{Some begin in somewhere...}
    \lipsum[1-7]
    \chapter{A brief history...}
    \lipsum[8-14]
    \chapter{The Cathedral and the Bazaar and some text}
    \lipsum[1-7]
    \chapter{Homesteading the Noosphere }
    \lipsum[8-14]

    \chapter{The Magic Cauldron }
    \lipsum[1-7]
    \chapter{The Revenge}
    \lipsum[8-14]

\end{document}
J Leon V.
  • 11,533
  • 16
  • 47
  • Baffling. I swear I tried that before, and it didn't work. But now it works, so great! Also, for posterity, I need to remove the section of code below %this is where I need help because it puts "Story" in the wrong ToC line. – AML May 10 '18 at 10:07
  • It would be very helpful, if you update your question and show us an image even if it is edited that you want the final result to be... So we can use our techniques to make an efficient code to obtain that result. – J Leon V. May 10 '18 at 14:42
  • I have added an image of the desired output. – AML May 10 '18 at 14:56
  • That's a fun answer! – AML May 10 '18 at 23:55