我正在尝试将目录中的“章节”一词更改为“故事”。我已成功在章节标题中将其更改,但目录中却给我带来了麻烦。
我试图改变这个答案,但它并没有完全满足我的要求。如下所示,在目录中,“故事”一词被放在了章节标题行上,而不是其上方的行上。相反,我希望“ Chapter
X”说的是“ 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}
更新: 根据评论中的要求,这是所需最终输出的图像。
答案1
我不知道这是否是最强大的解决方案,但您可以重新定义某些结构的名称,如下所示:
\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}
将以下行添加到您的代码中:
...
\renewcommand\chaptername{Story} %<--- to change the name of chapters
\begin{document}
...
结果:
一些更新:
这是我寻找所需内容的尝试;在内容索引的情况下,尽管可以使用命令将其留空\renewcommand\contentsname{}
;我决定添加一些装饰并尝试使用颜色,将索引的元素放在左侧,将的值更改为\hspace
,5 em
在 leftbar 环境中,在的4 em
两个 中,我添加了一些代码来更改文本标题上的空间......parbox
\titlecontents
titlesec
一些变化:
梅威瑟:
% 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}