ToC 章节对齐与 titlesec 冲突

ToC 章节对齐与 titlesec 冲突

我需要所有编号左对齐,章节和小节略微(可能是 0 点或 2 点?)位于章节右侧。章节和小节全部大写。

屏幕截图可以更好地解释我的需求:

没有标识的 ToC

这是我的 MWE:

\documentclass[a5paper]{abntex2}

\usepackage[T1]{fontenc}        
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\selectlanguage{brazil}
\usepackage{xcolor}

\usepackage{hyperref} 
\hypersetup{
  colorlinks   = {true}, %Colours links instead of ugly boxes
  urlcolor     = {black}, %Colour for external hyperlinks
  linkcolor    = {black}, %Colour of internal links
  citecolor   = {black} %Colour of citations
}

\usepackage{titlesec}
\titleformat{\chapter}
  {\fontfamily{phv}\selectfont\bfseries\LARGE}
  {\MakeUppercase{\thechapter}}{15pt}{} 
\titleformat{\section}
  {\fontfamily{fvs}\selectfont\bfseries}
  {\MakeUppercase{\thesection}}{15pt}{} 


\begin{document}

\tableofcontents*

\chapter{Introdução}
\section{Objetivos}
\subsection{Objetivos gerais}
\subsection{Objetivos específicos}

\chapter{Exposição do tema}
\section{Tema Geral}
\subsection{Tema específico}

\end{document}

如下所示,当我添加\titleformat章节时,它会多出一个空格(红色)。对我来说奇怪的是,该部分有标题格式,但没有出现错误。

大写字母不适用于该部分,但粗体可以使用。abntex2课程基于memoir,但使用回忆录会让我返回没有点的章节并破坏我的论文中其他必要的内容。

我得到的是:

目录与章节错位

我确实尝试了etoc其他软件包,但在我看来,我做错了一些事情,不需要其他软件包就可以修复。

或者确实存在冲突?

编辑:

根据 cfr 的建议,我看一下abntex2大写命令手册,其中指出不影响 ToC

我也尝试了sumario=tradicional使用memoir默认 ToC 样式的选项,但仍然得到带有奇怪空格的章节:

在此处输入图片描述

如果我尝试设置

\makeatletter
 \renewcommand*\l@chapter{\@dottedtocline{0}{0em}{3.2em}}
\makeatother

我收到未定义的控制错误。看来 titlesec 确实在使用 ToC 进行推断。

第 4 行:未定义控制序列。...ntrodu\IeC {\cc}\IeC{\~a}o}{3}{chapter.1}

第 8 行:未定义控制序列。...eC {\cc}\IeC{\~a}o do tema}{5}{chapter.2}

这些行包含: \contentsline {chapter}{\chapternumberline {1}Introdu\IeC {\c c}\IeC {\~a}o}{3}{chapter.1}

\contentsline {chapter}{\chapternumberline {2}Exposi\IeC {\c c}\IeC {\~a}o do tema}{5}{chapter.2}

答案1

问题似乎是在目录开头写入了\cftchapindent很长的重新定义。即使不使用,也会发生这种情况,但如果不使用另一个重新定义,则会在第一个之后将重新定义回合理长度。我看了又看,无法猜测这两行代码来自哪里,但无论如何,您可以通过再次输入第三个重新定义来重新设置长度,使其回到应有的长度,如下所示:\cftlastnumwidth\titleformattitleformatcftchapindentcftchapterindent

\tableofcontents*
\addtocontents{toc}{\setlength  {\cftchapterindent }{0em} \setlength  {\cftchapternumwidth }{\cftlastnumwidth }}

答案2

我仍然无法titlesec在没有这个额外空间问题的情况下工作。然而,在进一步阅读和搜索(主要是在 cfr 的鼓励下)memoir手册和Memoir Chapter Styles我找到了一种解决方法,并按我需要的方式显示结果。当然,对于部分样式,我仍然使用titlesec

看过之后Medina 的这个回答,我意识到这一切都可以通过创建我自己的回忆录章节风格来实现。我的代码(可能对某些人有用)如下:

\newcommand*\varhrulefill[1][0.4pt]{\leavevmode\leaders\hrule height#1\hfill\kern0pt}
\renewcommand*{\chapnumfont}{\fontfamily{phv}\selectfont\LARGE\bfseries}
\renewcommand*{\chaptitlefont}{\fontfamily{phv}\selectfont\LARGE\bfseries}

\renewcommand*{\afterchaptertitle}{\vskip 1em \varhrulefill[0.35cm]\vskip\afterchapskip}

vhrulefill 再次从麦地那

如果我在序言中定义样式,那么我的列表甚至目录标题都会有规则,这不是我想要的。

具有章节样式的目录

如果我用 定义样式\makechapterstyle,然后仅在目录之后“加载”它,它似乎可以工作,但我再次在章节目录中得到相同的奇怪的额外间距。不知道为什么。

为了解决这个问题,我简单地将上述代码粘贴到文本文件的序言中,该文本文件位于目录之后。我不知道如何在单文件文档中完成此操作,如有任何建议,请发表评论。

答案3

如果你真的希望 TOC 看起来像你的图像(这很奇怪,但无论如何),你应该坚持使用课程已经为你提供的内容:

\documentclass[a5paper]{abntex2}
%\setboolean{ABNTEXupperchapter}{false}
\usepackage[T1]{fontenc}        
\usepackage[utf8]{inputenc}
%\usepackage[brazil]{babel} &don't need this, already default
%\selectlanguage{brazil} &don't need this, already default
\usepackage{xcolor}

\usepackage{hyperref} 
\hypersetup{
  colorlinks   = {true}, %Colours links instead of ugly boxes
  urlcolor     = {black}, %Colour for external hyperlinks
  linkcolor    = {black}, %Colour of internal links
  citecolor   = {black} %Colour of citations
}

\renewcommand{\ABNTEXchapterfont}{\fontfamily{phv}\selectfont\bfseries}
\renewcommand{\ABNTEXsectionfont}{\fontfamily{fvs}\selectfont\bfseries} %Bera Sans? Really?
%\newcommand{\ABNTEXsectionfontsize}{\Large}}{}
\renewcommand{\cftchapterfont}{\bfseries}
\renewcommand{\cftsubsubsectionfont}{\normalfont}
\renewcommand{\cftsubsectionfont}{\bfseries}
\renewcommand{\cftsubsubsectionfont}{\normalfont}
\setlength{\cftbeforechapterskip}{0pt}

\begin{document}

\tableofcontents*

\chapter{Introdução}
\section{Objetivos}
\subsection{Objetivos gerais}
\subsection{Objetivos específicos}

\chapter{Exposição do tema}
\section{Tema Geral}
\subsection{Tema específico}

\end{document}

在此处输入图片描述

我不知道为什么你在章节以下的所有分段条目中都使用 Bera Sans。

如果你读过文档,您可能已经注意到第 6.1 节:\ABNTEXchapterfont,和\ABNTEXchapterfontsize,您可以更改它们。

其他宏如\cftchapterfontcom 来自memoir。(参见第 9 章。)

我同意 cfr — 如果您想要全部大写,则最好全部大写。

相关内容