# LaTeX: iopart and overlapping appendices

I am writing a report for which I am required to use the iopart class, which can be downloaded from this page, and I'm having some problems with the word 'Appendix' overlapping with its title in the Table of Contents.

Let me explain. Notice in the image how the Appendix word overlaps with the appendix's name.

Latex code:

\documentclass[12pt]{iopart}
\pdfoutput=1

\begin{document}
\title{Title}
\author{Author$^1$, Author$^2$, Author$^1$}
{\small $^1$University department.} \\
{\small $^2$Company.}
}
\begin{abstract}
Abstract.
\end{abstract}
\maketitle
\tableofcontents
\clearpage

\section{Section 1}
\section{Section 2}

\appendix
\section{Extra 1}
\subsection{Extra 1.1}
\subsection{Extra 1.2}
\section{Extra 2}
\subsection{Extra 2.1}
\subsection{Extra 2.2}

\end{document}


Now, I found an answer here that helped me fix the problem, but only partially: some of the Appendix do not overlap their own title any more, but this only happens with those that correspond to sections (Appendix A, Appendix B, ...). The appendices corresponding to subsections (Appendix A.1, A.2, B.1, B.2, ...) still overlap.

The new code is

\documentclass[12pt]{iopart}
\pdfoutput=1
\usepackage{lipsum}
\usepackage{etoolbox}

\makeatletter
\def\@mkboth#1#2{}
\newlength\appendixwidth
\newcommand{\patchl@section}{%
\settowidth{\appendixwidth}{\textbf{Appendix }}%
\patchcmd{\l@section}{1.5em}{\appendixwidth}{}{\ddt}%
}
\makeatother

\begin{document}
\title{Title}
\author{Author$^1$, Author$^2$, Author$^1$}
{\small $^1$University department.} \\
{\small $^2$Company.}
}
\begin{abstract}
Abstract.
\end{abstract}
\maketitle
\tableofcontents
\clearpage

\section{Section 1}
\section{Section 2}

\appendix
\section{Extra 1}
\subsection{Extra 1.1}
\subsection{Extra 1.2}
\section{Extra 2}
\subsection{Extra 2.1}
\subsection{Extra 2.2}

\end{document}


I tried coming up with a solution by adding

\makeatletter
\def\@mkboth#1#2{}
\newlength\subappendixwidth
\newcommand{\patchl@subsection}{%
\settowidth{\subappendixwidth}{\textbf{Appendix }}%
\patchcmd{\l@subsection}{1.5em}{\subappendixwidth}{}{\ddt}%
}
\makeatother


but unfortunately, it does not work. Do any of you have any idea how to fix the overlapping of the appendixes A.1, A.2, B.1, B.2, ...? I've been using LaTeX for quite a while but I don't know how to fix it myself, or even whether it can be fixed or not.

Thanks to all of you for your time.

You can patch the commands \l@section and \l@subsection, which are responsible for typesetting the titles in the table of contents, but only after \appendix is issued.

\documentclass[12pt]{iopart}
\usepackage{etoolbox}

\makeatletter
\newrobustcmd{\fixappendix}{%
\patchcmd{\l@section}{1.5em}{7em}{}{}%
\patchcmd{\l@subsection}{2.3em}{7em}{}{}%
}
\makeatother

\begin{document}

\title{Title}
\author{Author$^1$, Author$^2$, Author$^1$}
{\small $^1$University department.} \\
{\small $^2$Company.}
}
\begin{abstract}
Abstract.
\end{abstract}
\maketitle

\makeatletter

\tableofcontents

\clearpage

\section{Section 1}
\section{Section 2}

\appendix
\section{Extra 1}
\subsection{Extra 1.1}
\subsection{Extra 1.2}
\section{Extra 2}
\subsection{Extra 2.1}
\subsection{Extra 2.2}

\end{document}


I don't have the iopart class and don't want to download it. From what I've seen of your code you do nothing to put Appendix before the numbers in the ToC. If that is so then there is a problem with the class which you should report.

However, below is similar code to yours but using the article class. I've used the tocloft package to provide additional space for the Appendix section numbers in the ToC.

% temp4.tex SE 520516

%\documentclass[12pt]{iopart}
\documentclass[12pt]{article}
\usepackage{tocloft}

\begin{document}

\tableofcontents
\clearpage

\section{Section 1}
\section{Section 2}

\appendix


The LaTeX \addtocontents macro inserts code into the ToC file and read the tocloft manual (> texdoc tocloft) for the meaning of the \cft... macros. Adjust the 5em and 4em to suit your document.