![目录 (TOC) 中的章节号后跟一个点,但标题 (Titles) 中没有该章节号](https://linux22.com/image/435229/%E7%9B%AE%E5%BD%95%20(TOC)%20%E4%B8%AD%E7%9A%84%E7%AB%A0%E8%8A%82%E5%8F%B7%E5%90%8E%E8%B7%9F%E4%B8%80%E4%B8%AA%E7%82%B9%EF%BC%8C%E4%BD%86%E6%A0%87%E9%A2%98%20(Titles)%20%E4%B8%AD%E6%B2%A1%E6%9C%89%E8%AF%A5%E7%AB%A0%E8%8A%82%E5%8F%B7.png)
在里面書類我想要部分、章节、节和小节的编号为后面跟着一个点,标题和目录中均有,但有一处例外:章节编号应仅在目录中添加一个点,而不应在标题中添加。
这可能看起来有点异想天开和奇怪,但原因是在我的书籍设计中,章节号位于一个方框内,因此不适合放置要点。
以下屏幕截图分别显示了章节标题片段和目录片段:
我使用这个代码来控制点:
% Section style definition
\titleformat{\section}[runin]
{\normalsize \bfseries}
{\color{black} \S \thesection}
{1ex}{\color{black}}[\quad]
% Subsection style definition
\titleformat{\subsection}[runin]
{\normalsize \bfseries}
{\color{black} \S \thesubsection}
{1ex}{\color{black}}[\quad]
\renewcommand\thepart{\Roman{part}.}
\renewcommand\thesection{\thechapter.\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}
从第二张截图中可以看出,在目录中章节号后面没有点, 和这就是我想要解决的问题。
编辑 1 _________________________________________________________________
我避免在序言中包含所有代码,因为它非常麻烦。然而,一些想帮助我的人建议我包含一个可编译版本,我重现了它,省略了许多我自己的定义,但显示了所有已加载的包,因为有时由于包之间的不兼容而出现问题:
\documentclass[a4paper,14pt,twoside,reqno]{extbook}
\usepackage[tmargin=28mm,bmargin=28mm,lmargin=28mm,rmargin=28mm]{geometry}
\usepackage{amsmath, amsfonts,amssymb,amstext,amsthm,mathpazo, xfp, latexsym}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{cite}
\usepackage{times}
\usepackage[usenames]{color}
\usepackage[dvipsnames]{xcolor}
\usepackage{pstricks}
\usepackage{tikz, ifthen, bclogo}
\usepackage{pst-poly}
\usepackage{pst-all}
\usetikzlibrary{decorations.fractals,calc}
\usetikzlibrary{arrows,calc,patterns,shadows,petri,decorations.markings,shapes,trees}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{lindenmayersystems}
\usepackage{latexsym, graphicx}
\usepackage{subfigure}
\usepackage[thicklines, makeroom]{cancel}
\usepackage{verbatim}
\usepackage{wasysym}
\usepackage{stmaryrd, scalerel, stackengine}
\usepackage{pifont}
\usepackage{calligra}
\usepackage{mathtools}
\usepackage{titlesec}
\usepackage{underoverlap}
\usepackage{theorem}
\usepackage{secdot}
% Definition of bcancelto _____________________________________
\usepackage{etoolbox}
\makeatletter
%patch \canto@vector to correctly place script.
\pretocmd{\canto@vector}{\edef\testneg{#4<0}}{}{\@latex@error{Patch fail}}
\patchcmd{\canto@vector}{^}{\ifnum\testneg_\else^\fi}{}{\@latex@error{Patch fail}}
\patchcmd{\canto@vector}{\raise#2\dimen@}{\raise\dimexpr\ifnum\testneg-\ht\z@+\fi#2\dimen@}{}{\@latex@error{Patch fail}}
\renewcommand*{\thepage}{{\small} \arabic{page}} % Resize page numbers
% _____________________________________________
\↨DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}
% Frame definition: space to edge and edge thickness:
\fboxsep 6pt \fboxrule 1pt
% Section style definition
\titleformat{\section}[runin]
{\normalsize \bfseries}
{\color{black} \S \thesection}
{1ex}{\color{black}}[\quad]
% Subsection style definition
\titleformat{\subsection}[runin]
{\normalsize \bfseries}
{\color{black} \S \thesubsection}
{1ex}{\color{black}}[\quad]
\renewcommand\thepart{\Roman{part}.}
\renewcommand\thesection{\thechapter.\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}
%TOC edit attempt:
%\let\OldNumberline=\numberline
%\RenewDocumentCommand{\numberline}{ m }{%
% \OldNumberline{#1.}%
%}
\date{} % clear date
% Frame definition: margins and border thickness:
\fboxsep 6pt \fboxrule 1pt
\raggedbottom % For LaTeX to leave excess space at the bottom of the sheet and not distribute white spaces across it.
\setlength\parindent{0pt} % noindent in the whole document
\titlespacing*{\section}{0pt}{3ex}{2ex} %Espacio a la izquierda, espacio antes del título, espacio después del título.
\titlespacing*{\subsection}{0pt}{3ex}{2ex}
\usepackage[colorlinks=true,linkcolor=black]{hyperref}
\titleformat{\chapter}{\large \bfseries}{\filright \fboxrule 3pt \framebox[1.8em][c]{\thechapter}}{16pt}{\large}
%___________________________________________________________________________
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setcounter{chapter}{0}
\thispagestyle{empty}
\renewcommand{\baselinestretch}{1.25} % line spacing
% head and foot __________________________________________
\usepackage{emptypage} %To skip header / footer on empty pages (generated so that each chapter starts on an odd page)
\begin{document}
\pagestyle{plain}
\tableofcontents
\addcontentsline{toc}{chapter}{FOREWORD.}
\chapter*{FOREWORD.}
\end{document}
编辑2 _________________________________________________________________
使用此代码,
\usepackage{tocloft}
\renewcommand{\cftchapaftersnum}{.}
我收到以下错误:
这些错误信息最奇怪的是第 623 行仅包含文本,第 624 行是空白。
编辑 3 _________________________________________________________________
在目录中,小节编号和小节标题后的空格大于编号和小节标题之间的空格,如何使这些空格相等?看到这个截图了吗?:
答案1
通过多次尝试,我得到了以下信息:
\renewcommand\cftchapnumwidth{2em}
\renewcommand\cftsecindent{2em}
\renewcommand\cftchapaftersnum{\hskip-1.4em
\filright \fboxrule 3pt \fbox{$\mathstrut${\Large~~~}}}%[1.8em][c]{}}
\renewcommand\cftsecpresnum{\S}
插入到 \titleformat 和 \usepackage{tocloft,etoolbox} 之后 您必须忽略有关 lof 和 lot 的消息。结果是:
我不得不调整章节的数字宽度和节的缩进。此外,对节和小节使用段落符号是不合逻辑的。它们中只有一个可以是段落。
答案2
使用tocloft
包。以下是您的 MWE 的精简版本,其中包含与您的问题相关的代码要点以及tocloft
解决方案。
% dotprob.tex SE 601137
\documentclass[a4paper,14pt,twoside,reqno]{extbook}
\usepackage[tmargin=28mm,bmargin=28mm,lmargin=28mm,rmargin=28mm]{geometry}
\usepackage{tocloft}
\renewcommand{\cftchapaftersnum}{.}
\usepackage{titlesec}
\titleformat{\chapter}{\large \bfseries}{\filright \fboxrule 3pt \framebox[1.8em][c]{\thechapter}}{16pt}{\large}
\begin{document}
\pagestyle{plain}
\tableofcontents
\addcontentsline{toc}{chapter}{FOREWORD.}
\chapter*{FOREWORD.}
\chapter{Regular}
\end{document}