1

I need all the numbering aligned left, sections and subsections slightly (0 or 2pt maybe?) on the right of chapter. Chapter and section all caps.

The screenshot will explain better what I need:

ToC with no ident

And this is my 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}

As you can see below, when I add \titleformat for chapter, it gets an extra space (in red). Whats weird for me is that section has a titleformat but doesn't get buged.

Uppercase is not working for section, but bold is. abntex2 class is based on memoir, but using memoir returns me chapters without dots and breaks other necessary things on my thesis.

What I get:

ToC with chapter misaligned

I did try etoc and other packages, but it seems to me that I did something wrong that can be fixed without another package.

Or maybe there is indeed a conflict?

EDIT:

As suggested by cfr, I look at abntex2 manual for the upper case command, and it states doesn't affect ToC.

I also tried the sumario=tradicional option which should use memoir default ToC style, but I still get chapters with that weird space:

enter image description here

If I try to set

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

I get a undefined control error. It seems like titlesec is indeed inferring with ToC.

line 4: Undefined control sequence. ...ntrodu\IeC {\c c}\IeC{\~a}o}{3}{chapter.1}

line 8: Undefined control sequence. ...eC {\c c}\IeC{\~a}o do tema}{5}{chapter.2}

Those lines contains: \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}

  • You have a choice. Either you can stick with the class you are using and work with its method of configuring things, amending anything which doesn't work out-of-the-box. Or you can use a more standard class and its configuration options, loading any additional packages you need. Packages such as titlesec cannot be expected to work with arbitrary classes. The class you are using handles things in a certain way. Assuming that you can read the documentation, have a look to see how it tells you to do these things. (I can't read Portuguese so I'm just going by the code.) – cfr Oct 23 '15 at 20:46
  • 1
    It has options for upper-casing headings, for example. I wouldn't probably recommend the class. I never trust classes and packages which include \makeatletter... \makeatother. But perhaps that's just me. – cfr Oct 23 '15 at 20:49
  • Sadly my university requires me to follow this standards, which abntex2 seem to implement at some extend. I will have a look at the uppercase part. Thanks. – G. Bay Oct 23 '15 at 21:24
  • There's code for the ToC as well. But it will be easier to figure out for you reading the documentation than trying to do it from the code, which is the only bit I can read. If you get stuck, I can ping people in the chat room. At least one (probably more) will be able to read the docs. – cfr Oct 23 '15 at 21:44
  • I did, nothing specific about alignment, just font, levels, numbering etc. It points to memoir manual for further customization. – G. Bay Oct 23 '15 at 21:52
2

The problem seems to be that something is writing a redefinition of \cftchapindent to the very long \cftlastnumwidth at the start of the TOC. This happens even without using \titleformat, but absent use of titleformat another redefinition of cftchapindent back to reasonable lengths follows the first. I have looked and looked and cannot begin to guess where either of these lines are coming from, but in any case you can set the lengths right again by putting in yet a third redefinition which puts cftchapterindent back as it should be, like so:

\tableofcontents*
\addtocontents{toc}{\setlength  {\cftchapterindent }{0em} \setlength  {\cftchapternumwidth }{\cftlastnumwidth }}
  • Your solution is better, more efficient since it uses only one line vs. 3 of mine, and it does fix the extra-space. Many Thanks! :) – G. Bay Oct 25 '15 at 12:26
1

I still couldn't make titlesec work without having this extra space issue. However after further reading and searching (mostly encouraged by cfr) on memoir manual and Memoir Chapter Styles I found a way to workaround and display results as I need it. Of course, for section style I still use titlesec.

After looking at this answer by Medina, I realize it could be all done really simply by creating my own memoir chapter style. My code, as it might be useful to someone is the following:

\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}

The vhrulefill is, again from Medina.

If I was to define the style at the preamble, then my lists and even ToC title would have the rule, which is not what I wanted.

ToC with chapter style

If I define the style with \makechapterstyle and then "load" it only after ToC, it seems to work, but then again I get the same odd extra spacing at chapters ToC. Don't know why.

To solve this I simply pasted the above code in the preamble of my textual file, witch goes after ToC. I have no idea how this would be done in a single-file document, any suggestions please leave a comment.

1

If you really want the TOC to look like your image (which is weird, but anyway), you should stick with what the class already provides you:

\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}

enter image description here

I don't know why you use Bera Sans for all sectional entries below chapter.

If you had read the documentation, you'd have noticed section 6.1: \ABNTEXchapterfont, and \ABNTEXchapterfontsize, which you can change.

Other macros like \cftchapterfont com from memoir. (See chapter 9.)

I agree with cfr -- if you want something in all caps, you'd better write it in all caps.

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.