Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am writing a paper for university and I need to do it according to style guides. Everything looks peachy, except for the ToC.

This is how it comes out for me: enter image description here

The word "appendix" shouldn't overlap with the section name, but also the non-appendix subsections cannot be further to the right than they are now. That's why I cannot use

\renewcommand\l@subsection{\@dottedtocline{2}{1.5em}{3em}}

Following is the code I have in my *.cls file which might have some influence in current formatting.

\renewcommand{\section}{%
    \@startsection {section}{1}{\z@}
    {-3.5ex \@plus -1ex \@minus -.2ex}
    {2.3ex \@plus.2ex}
    {\normalfont\Large\bfseries}
}

\renewcommand{\l@section}[2]{%
    \ifnum \c@tocdepth >\z@
        \addpenalty\@secpenalty
        \setlength\@tempdima{1.5em}
        \begingroup
            \vspace{1.5mm}
            \parindent \z@ \rightskip \@pnumwidth
            \parfillskip -\@pnumwidth
            \leavevmode {
            \advance\leftskip\@tempdima
            \hskip -\leftskip
            \MakeUppercase{#1}}\nobreak\ %
            \leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}
            \hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
        \endgroup
    \fi
}

\renewcommand{\appendix}{%
    \renewcommand{\thesubsection}{\arabic{subsection} appendix.}
}

The ToC in the image was generated with following statements:

\section{Section 1}
\section{Section 2}
\subsection{Subsection 2.1}
\section{Appendices}
\appendix
\subsection{Awesome appendix}
\subsection{Not so awesome appendix}

I will be grateful for any help you can provide.

share|improve this question
    
Welcome to TeX.sx!! Please add a minimal working example (MWE) that illustrates your problem. –  Marco Daniel Jun 17 '12 at 16:44

2 Answers 2

up vote 9 down vote accepted

You can use the titletoc package to change the formatting for subsection entries just before the appendices; here's an example:

\documentclass{article}
\usepackage{titletoc}

\makeatletter
\renewcommand{\l@section}[2]{%
    \ifnum \c@tocdepth >\z@
        \addpenalty\@secpenalty
        \setlength\@tempdima{1.5em}
        \begingroup
            \vspace{1.5mm}
            \parindent \z@ \rightskip \@pnumwidth
            \parfillskip -\@pnumwidth
            \leavevmode {
            \advance\leftskip\@tempdima
            \hskip -\leftskip
            \MakeUppercase{#1}}\nobreak\ %
            \leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}
            \hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
        \endgroup
    \fi
}

\renewcommand{\appendix}{%
    \renewcommand{\thesubsection}{\arabic{subsection} appendix.}
}
\makeatother

\begin{document}
\tableofcontents
\section{Section 1}
\section{Section 2}
\subsection{Subsection 2.1}
\section{Appendices}
\appendix

\titlecontents{subsection}
  [7.5em]{}
  {\contentslabel{6em}}
  {\hspace*{-6em}}
  {\titlerule*[0.6pc]{.}\contentspage}

\subsection{Awesome appendix}
\subsection{Not so awesome appendix}

\end{document}

enter image description here

In your actual document, all you need to do is to load the package and

\titlecontents{subsection}
  [7.5em]{}
  {\contentslabel{6em}}
  {\hspace*{-6em}}
  {\titlerule*[0.6pc]{.}\contentspage}

ust before the subsections corresponding to the appendices.

share|improve this answer
    
You are a life saver. This is the most correct and cleanest looking answer. Thank you. –  Paulius K. Jun 17 '12 at 17:12

use a modified definiton of \l@subsection:

\documentclass{article}
\begin{document}

\tableofcontents
\section{Section 1}
\section{Section 2}
\subsection{Subsection 2.1}
\section{Appendices}
\addtocontents{toc}{\string\renewcommand\string\l@subsection{\string\@dottedtocline{2}{1.5em}{6em}}}
\appendix
\renewcommand\thesubsection{appendix~\arabic{subsection}}
\subsection{Awesome appendix}
\subsection{Not so awesome appendix}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.