2

I am doing my appendices with

\appendix
\section*{Appendices}
\addcontentsline{toc}{section}{Appendices}
\renewcommand{\thesubsection}{\Alph{subsection}}

\subsection{Code}
...

so the Appendices section is listed in the table of contents just like other sections (omitting the section number by using section*), and each appendix listed as subsection under this section in the table of contents.

It looks great, but I am also using

\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}

so when I am creating an equation, figure or table in the appendix, the numbers become ".1", ".2", etc., because I have omitted the section number. What I want is actually to get the subsection's number/letter.

It would work if I did something like

\appendix
\section{Code}
...

but then I don't get the appendices as a list indented under the entry "Appendices".

What can I do to make all the appendices sections instead of subsection, but still obtain the functionality in the table of contents?

  • try with \renewcommand{\the...}{\arabic{...}} – touhami Jun 18 '16 at 9:36
  • 1
    BTW, you should really thank touhami for creating a MWE for you. – John Kormylo Jun 19 '16 at 17:00
2

Here is a solution.

Update All what we need is

\let\l@section\l@subsection

enter image description here

\documentclass{article}
\usepackage{mwe}% just for the example

\usepackage{amsmath}

\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}

\begin{document}
\tableofcontents
\listoffigures
\listoftables
\section{Foo}
\section{Bar}

\clearpage % just for the example

\appendix
\section*{Appendices}
\addcontentsline{toc}{section}{Appendices}
\addtocontents{toc}{\begingroup\string\makeatletter\global\let\string\l@section\string\l@subsection\endgroup}

\section{Code}
\begin{equation}
a=b
\end{equation}
\begin{table}
\caption{Caption of table 1}
\begin{tabular}{|c|c|}
\hline 
1 & 2 \\ 
\hline 
3 & 4 \\ 
\hline 
\end{tabular} 
\end{table}
\begin{table}
\caption{Caption of table 2}
\begin{tabular}{|c|c|}
\hline 
1 & 2 \\ 
\hline 
3 & 4 \\ 
\hline 
\end{tabular} 
\end{table}
\section{Code code}
\begin{figure}
\includegraphics[scale=.55]{example-image}
\caption{Caption of figure 1} 
\end{figure}
\begin{figure}
\includegraphics[scale=.55]{example-image}
\caption{Caption of figure 2}
\end{figure}
\end{document}
  • If I use this approach, equations, figures and tables are no longer numbered with section_number.equation_number, but only with equation_number. – Jamgreen Jun 18 '16 at 20:40
  • @Jamgreen answer updated, \renewcommand{\theequation}{\arabic{equation}}... after \appendix – touhami Jun 18 '16 at 20:52
  • @Jamgreen answer updated <<finally english is difficult>> – touhami Jun 20 '16 at 6:36
2

After each \subsection, you need to increment the section counter so as to reset all the other counters. Since this also resets the subsection counter, you need to reset it to equal the new section number. I combined these into the macro \appsection.

\documentclass{article}
\usepackage{mwe}% just for the example

\usepackage{amsmath}

\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}

\newcommand{\appsection}[1]% #1 = appendix name
 {\subsection{#1}%
  \stepcounter{section}%
  \setcounter{subsection}{\value{section}}}

\begin{document}
\tableofcontents
\listoffigures
\listoftables
\section{Foo}
\section{Bar}

\clearpage % just for the example

\appendix
\section*{Appendices}
\addcontentsline{toc}{section}{Appendices}
\renewcommand{\thesubsection}{\Alph{subsection}}

\appsection{Code}
\begin{equation}
a=b
\end{equation}
\begin{table}
\caption{Caption of table 1}
\begin{tabular}{|c|c|}
\hline 
1 & 2 \\ 
\hline 
3 & 4 \\ 
\hline 
\end{tabular} 
\end{table}
\begin{table}
\caption{Caption of table 2}
\begin{tabular}{|c|c|}
\hline 
1 & 2 \\ 
\hline 
3 & 4 \\ 
\hline 
\end{tabular} 
\end{table}
\appsection{Code code}
\begin{equation}
a=b
\end{equation}
\begin{figure}
\includegraphics[scale=.55]{example-image}
\caption{Caption of figure 1} 
\end{figure}
\begin{figure}
\includegraphics[scale=.55]{example-image}
\caption{Caption of figure 2}
\end{figure}
\end{document}

demo

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.