1

I've managed to change the section formating mid-document. However, in the table of contents, the formatting resets. I'm new to latex so I don't fully understand the \titleformat option. I want it to say "Anexo A" but in the table of content it says "A Anexo". Thanks in advance.

\documentclass[12pt]{article}  
\usepackage[explicit]{titlesec}
\usepackage{blindtext}
\begin{document}
    \tableofcontents
    \section{Introdução}
    \blindtext

    \setcounter{section}{0}
    \renewcommand{\thesection}{\Alph{section}} 
    \titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{#1\ \thesection}
    \section{Anexo}
    \blindtext
\end{document}

enter image description here

1
  • I guess you have more than one appendix, otherwise simply using \section*{Anexo A} and a suitable \addcontentsline would be your easiest approach. In the case of multiple appendices, you need to insert the change via \addtocontents at the same time you redefine the section format. It's late and if I try to write an answer, I'll probably get it all wrong. But look up \addtocontents and how to redefine the command for sections in the TOC. (I don't know if it's provided in a package; it may require a patch.) – barbara beeton Oct 18 '20 at 2:46
0

You should simply switch #1 and \thesection. The #1 is the argument (i.e. the section title), whereas the \thesection is the value of the section counter.

\documentclass[12pt]{article}  
\usepackage[explicit]{titlesec}
\usepackage{blindtext}
\begin{document}
    \tableofcontents
    \section{Introdução}
    \blindtext

    \setcounter{section}{0}
    \renewcommand{\thesection}{\Alph{section}} 
    \titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{\thesection\ #1}

    \section{Anexo}
    \blindtext
\end{document}
1
  • Thanks for the reply, but that does the opposite of what I want. I want the section counter to appear after the section title in both the table of context and the document, "Anexo A". Where "Anexo" is the section title and "A" the section counter. – Renato Morais Jan 21 '20 at 23:56

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.