2

I am trying to let the title name of the appendix appear just before the appendix letter. However, at the same time I am using titlesec to adjust the appearance of section titles. I found a similar question, Problem with titlesec and appendix, however, the answer does not solve my problem since it changes the toc appearance only. Here`s an MWE:

\documentclass[a4paper, 12pt, english, leqno]{article}

\usepackage[compact]{titlesec} 
\titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{12pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}

\usepackage[title]{appendix}

\usepackage{titlesec}
\titleformat{\section}
  {\normalfont\bfseries\center}{\thesection}{1em}{}

\titleformat{\subsection}
  {\normalfont\bfseries}{\thesubsection}{1em}{}

\titleformat{\subsubsection}
  {\normalfont\itshape}{\thesubsection}{1em}{}


\begin{document}

\section{A section}
\clearpage

\begin{appendices}

\section{first appendix} 
\label{appendix:A}

\section{second appendix} 
\label{appendix:B}

\end{document}
latexQ
  • 221

1 Answers1

4

Is this like you want? I made some corrections to \titleformat, and loaded etoolbox and \apptools, which defines the boolean \ifappendix, very useful in this context. Note \appendixname doesn't appear in the table of contents.

\documentclass[a4paper, 12pt, english, leqno]{article}

\usepackage[compact]{titlesec}
\titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{12pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}

\usepackage[title]{appendix}
\usepackage{etoolbox, apptools}
\AtBeginEnvironment{appendices}{\appendixtrue}

\usepackage{titlesec}
\titleformat{\section}[block]
  {\normalfont\bfseries\filcenter}{\IfAppendix{\appendixname~}{\relax}\thesection\IfAppendix{: }{}}{1em}{}

\titleformat{\subsection}
  {\normalfont\bfseries}{\thesubsection}{1em}{}

\titleformat{\subsubsection}
  {\normalfont\itshape}{\thesubsection}{1em}{}

\begin{document}

\section{A section}
\clearpage

\begin{appendices}

\section{first appendix}
\label{appendix:A}
If a woodchuck could chuck wood,  would a woodchuck chuck wood?

\section{second appendix}
\label{appendix:B}
Blah blah blah.
\end{appendices}

\end{document}  

enter image description here

Bernard
  • 271,350