2

In my table of contents I would like to have it say "Appendix A Regression results". However my code is giving the following output:enter image description here

My code is the following

    \documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[margin=1.25in]{geometry}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{ltxtable} 
\usepackage{ltablex}
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage[titletoc,page]{appendix}
\usepackage[nottoc,notlot,notlof]{tocbibind}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
\end{filecontents}

\usepackage{blindtext}

\renewcommand\appendix{\par
  \setcounter{section}{0}
  \setcounter{subsection}{0}
  \setcounter{figure}{0}
  \setcounter{table}{0}
  \renewcommand\thesection{Appendix \Alph{section}}
  \renewcommand\thefigure{\Alph{section}\arabic{figure}}
  \renewcommand\thetable{\Alph{section}\arabic{table}}
}

\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}

\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1.5}

\begin{document}
\tableofcontents

\appendix

\section{Regression tables}
Here is the 
\clearpage

\end{document}

I hope this helps you understanding the problem. Thank you so much!

  • 2
    Please make your code compilable! – CarLaTeX May 4 '17 at 6:11
  • 1
    It is a bad idea in 99.9% of all cases to include words in to \thesection etc. Please use the tocloft package and change the \cftsecnumwidth length such that the word Appendix fits into it – user31729 May 4 '17 at 6:25
  • Will this post be improved or is it kept unclear? – user31729 May 5 '17 at 18:01
  • Sorry @ChristianHupfer, what do you mean add words in \thesection? Like for starting a section in the text in general I do \section{Determinant Analysis}, is that bad? I tried doing what you suggested but now every word in the table contents is separated from the number. Also, maybe you could be more on how I could improve the post. – urpi May 5 '17 at 18:43
  • 1
    Sorry, @ChristianHupfer, I think my code now compiles. – urpi May 5 '17 at 18:58
1

Using \begin{appendices}...\end{appendices} will provide most of the features that are requested, rather than changing \thesection.

The \Alph - counting style of \thesection is the default for article if the appendix is used, titletoc prepends the title Appendix A etc. to the entry in the toc.

In order to apply the figure/table counter resetting within section, use \counterwithin from chngcntr package, right at the begin of appendices, either manually or \AtBeginEnvironment{appendices}{...}

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[margin=1.25in]{geometry}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{ltxtable} 
\usepackage{ltablex}
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage[titletoc,page]{appendix}
\usepackage[nottoc,notlot,notlof]{tocbibind}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
\end{filecontents}

\usepackage{blindtext}

\usepackage{etoolbox}
\usepackage{chngcntr}
\AtBeginEnvironment{appendices}{%
  \counterwithin{figure}{section}
  \counterwithin{table}{section}
}


\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}

\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1.5}

\begin{document}
\tableofcontents

%\appendix
\begin{appendices}
\section{Regression tables}

\begin{figure}
\caption{A figure}
\end{figure}

\begin{table}
\caption{A table}
\end{table}
\end{appendices}
Here is the 
\clearpage

\end{document}

enter image description here

| improve this answer | |

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.