1

The package:

\usepackage{chngcntr} 
\counterwithin*{chapter}{part}
\renewcommand{\restoreapp}{}

Works for the first chapter of my thesis, but on the two other chapters, the count starts at every section, I don't know why it's not working for the next chapters.

\documentclass[12pt,a4paper,oneside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{\thepage}
\lhead{}
\renewcommand{\headrulewidth}{0pt}

\usepackage{fix-cm}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{amsmath}
\numberwithin{table}{chapter}
\usepackage{marvosym}

\usepackage[style=authoryear,natbib=true]{biblatex}
\usepackage{appendix}
\usepackage{chngcntr}
\counterwithin*{chapter}{part} %To reset chapter counter for every part
\renewcommand{\restoreapp}{}
\AtBeginEnvironment{subappendices}{%
\chapter*{Appendix}
\addcontentsline{toc}{chapter}{Appendices}
\counterwithin{figure}{section}
\counterwithin{table}{section}
}
%\usepackage[toc,page]{appendix}
\usepackage{hyperref}
\hypersetup{
     colorlinks   = true, 
     citecolor    = blue
}
% \usepackage{hypertex}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\addbibresource{inf.bib}
\addbibresource{aid.bib}
\addbibresource{csr.bib}
\usepackage{csquotes}
\usepackage{array}
\usepackage{longtable}
\usepackage{rotating}
\usepackage{booktabs}
\usepackage{makeidx} 
\usepackage{booktabs,caption,fixltx2e}
\usepackage[flushleft]{threeparttable}
\usepackage{bbm}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{caption}
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}
\usepackage{multirow}
\usepackage{setspace}
\usepackage{rotfloat}
\usepackage{subcaption}
\usepackage{adjustbox} 
\usepackage{listings}
\usepackage{alltt}

\doublespacing

\restylefloat{figure}
\restylefloat{table}
\usepackage{mathtools}

\allowdisplaybreaks
\usepackage[lmargin=3.20cm,rmargin=3.0cm,tmargin=3cm,bmargin=3cm]{geometry}

% Set the beginning of a LaTeX document
\begin{document}

\setstretch{1.3}
\begingroup
\hypersetup{linkcolor=black}
\tableofcontents
\endgroup

\newpage
\mainmatter
\chapter{Ilkfo}
\label{Chapter 1} 

\begin{doublespace}
\section{Introduction}
Text....

\section{Literature review}
\subparagraph{Background...}

This section.....

%%%%%%
%Table 1
\begin{table} [htbp]
\centering
\caption{\label{tab1}
\textbf{Summar...}}
\begin{adjustbox}{max width=\textwidth}
\begin{threeparttable}
\begin{tabular}{l c c c c c}\hline 
\multicolumn{1}{c}{\textbf{Variable}} & \textbf{Mean}  & \textbf{Std. Dev.} & \textbf{Min.} &  \textbf{Max.} & \textbf{Obs.}\\ \hline  
\cline{1-6}
\multicolumn{6}{l}   {Panel A: } \\ \hline
Age &  &  &  &  & \\ \hline 
\multicolumn{6}{l}     {Panel B: } \\ \hline 
Age  &  &  &  &  & \\ \hline
\multicolumn{6}{l}     {Panel C: } \\ \hline 
Age &  &  &  &  & \\
\cline{1-6}
\end{tabular} 
\end{threeparttable}
\end{adjustbox}
\end{table}
%%%%%%

\section{Results}
\subsection{... results}
%%%%%%%%%%%%%%%%%%%
%Table 5: Main regression results

\begin{table} [htbp]
\centering
\caption{\label{general}
\textbf{Ma...}}
\begin{adjustbox}{max width=\textwidth}
\begin{threeparttable}
\begin{tabular}{lccccccc} \toprule
\multicolumn{8}{l}{ \emph{Infor}} \\ \hline  
& \multicolumn{3}{c}{Full sample} & \multicolumn{2}{c}{txt} & \multicolumn{2}{c}{text} \\
 & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\  
  \midrule
 & & & & & & & \\
textx & *** &  &  & ** &  & - &  \\
\bottomrule
\end{tabular} 
\begin{tablenotes} \footnotesize \item Notes: text 
\end{tablenotes}
\end{threeparttable}
\end{adjustbox}
\end{table}
%%%%%%%%%%%%%%%%%%%

\end{doublespace}
\setstretch{1.3}
\newpage
\begin{subappendices} 
\section{Quarterly...}

\begin{table} [htbp]
\centering
\caption{\label{quarterlytransitions}
\textbf{text}}
\begin{adjustbox}{max width=\textwidth}
\begin{threeparttable}
\begin{tabular}{l c c }\hline 
\textbf{Change} & \textbf{$Formal_{t}$}  & \textbf{$Informal_{t}$} \\ \hline  
\cline{1-3}
\multicolumn{3}{l} {Panel A: } \\ \hline
$Informal_{t-1}$ & \% & \% \\  \hline   
\cline{1-3} 
\end{tabular}
\end{threeparttable}
\end{adjustbox}
\end{table}

\end{subappendices}

\backmatter
\pagebreak

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pagebreak
\mainmatter
\chapter{Latin American...}
\label{Chapter 2} 

\begin{doublespace}
\section{Introduction}

\begin{table} [htbp]
\caption{\label{sumstatisticsaid}
\textbf{Summary }}
\begin{adjustbox}{max width=\textwidth}
\begin{threeparttable}
\centering
\begin{tabular}{l c c  c c }\hline
 & \multicolumn{2}{c}{\underline{\textbf{ World}}} &  \multicolumn{2}{c}{\underline{\textbf{Latin }}} \\
\multicolumn{1}{c}{Variable} & Mean  & Obs. & Mean & Obs.\\ 
 \hline
 &&&& \\
Ln per capita Income (US\$ constant) &    &  &    & \\ \hline
\end{tabular}
\begin{tablenotes} \footnotesize \item Sta
\end{tablenotes}
\end{threeparttable}
\end{adjustbox}
\end{table}

\section{Methodology}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% Table 1. MAIN SPECIFICATION %%%%%%%%%%%%%%%
\begin{table} [htbp]
\caption{\label{mainaid}
\textbf{Aid }}
\begin{adjustbox}{max width=\textwidth}
\begin{threeparttable}
\centering
\begin{tabular}{lcccc} \hline
 &\multicolumn{2}{c}{$ Aid$}  & \multicolumn{2}{c}{$d)$}  \\
 & (1) & (2) & (3) & (4) \\
 \hline
 &&&& \\
 &  &  &  &  \\
\bottomrule
\end{tabular}
\begin{tablenotes} \footnotesize \item ade. 
\item Notes: el. 
\end{tablenotes}
\end{threeparttable}
\end{adjustbox}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{doublespace}
\backmatter
\end{document}

The table of contents looks something like this:
1 Chapter 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Literature review . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3.1 Conceptual . . . . . 12
1.3.2 Empirical . . . . . . . . . . . . . . 16
1.4 Data . . . . . . . . . . . . . . . . . . . . . . . . 19
1.4.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.2 . . . . . . . . . . . . . . . . . . . . . 21
Appendices 46
1.A . . . . . . . 46
1.B . . . . . . . . . . . . . . . . 46

2 Chapter 2
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Literature Review . . . . . . . . . . . . . . . . . . . . . . . .. . .
2.3 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4 Methodology . . . . . . . . . . . . . . . . . . . . . . . . .
example of table of contents

  • 5
    Welcome to TeX.SX! Please edit your post and add a small complete LaTeX document (starting with \documentclass and ending with \end{document}) that shows your problem. – gernot Sep 25 '16 at 15:46
  • Hi @gernot, I just managed to edit the text to that shows the problem. – user95256 Oct 4 '16 at 16:28
  • Can you explain how the structure of your document should look like? Don't use LaTeX commands for this, just sketch the table of contents: numbering, indentation, etc. Your LaTeX code is confusing: You say \counterwithin*{chapter}{part}, but you don't use \part commands. It is also unclear to me, whether appendices are on the level of chapters or sections; and I guess, you don't want to have the appendices numbered within the preceding chapter. – gernot Oct 4 '16 at 16:42
  • Add the information to your post, using the edit button. – gernot Oct 4 '16 at 16:47
  • The appendices are not numbered within the preceding chapter and are at the level of chapters. – user95256 Oct 4 '16 at 17:03
0

I suggest not to use the appendix package (to have better control over what happens; otherwise you have to undo again the things that you don't like). Moreover, use \mainmatter only once, because otherwise it will reset again the page counter. If you like a specific side-effect of the second \mainmatter, let's achieve it explicitly.

Below is a sample document that seems to produce what you want. Let me know if anything is missing. Copy the definition of the environment appendices, remove \numberwithin{table}{chapter} (this is the default), remove \usepackage{appendix}, remove \counterwithin*{chapter}{part} (you don't have \parts), remove \renewcommand{\restoreapp}{}, and remove the whole \AtBeginEnvironment{subappendices} stuff.

As a side-note, except from exceptional cases, the package hyperref should be loaded last. Moreover, you load several packages twice (booktabs, caption), and I'm not convinced that you really need adjustbox, float and several other of the packages. You also have a duplicate \restylefloat{table}. You declare \doublespacing in the preamble, but set \setstretch{1.3} later in the document. Usually it is better not to collect preambles from different documents and web pages without having a good reason.

\documentclass{book}

\usepackage{chngcntr}
\newenvironment{appendices}%
  {\chapter*{Appendices}%
   \addcontentsline{toc}{chapter}{Appendices}%
   \setcounter{section}{0}%
   \def\thesection{\thechapter.\Alph{section}}%
   \counterwithin{figure}{section}%
   \counterwithin{table}{section}%
  }%
  {\counterwithout{figure}{section}%
   \counterwithout{table}{section}%
  }

\usepackage{lipsum}
\newcommand\somecontents
  {\lipsum[1]
   \begin{table}
     \centering
     \begin{tabular}{cc}
       a & b \\
       c & d
     \end{tabular}
     \caption{Some caption}
     \label{tab:\thetable}
   \end{table}
   \lipsum[2]
  }

\begin{document}
\frontmatter
\tableofcontents
\mainmatter

\chapter{Informality and Taxes in Mexico}
\section{Introduction}
\somecontents
\section{Literature review}
\somecontents
\section{Methodology}
\somecontents
\subsection{Conceptual framework and threats to identification}
\somecontents
\subsection{Empirical stratecy and specification}
\somecontents

\begin{appendices}
\section{Quaterly transitions between formality and informality}
\somecontents
\somecontents
\section{Formulas to calculate average tax rates}
\somecontents
\somecontents
\section{Narrative discussion of changes in tax rates}
\somecontents
\somecontents
\end{appendices}

\chapter{Latin American Aid Patterns: Democratic Political Regimes and US domestic Politics}
\section{Introduction}
\somecontents
\section{Literature review}
\somecontents
\section{Data}
\somecontents
\section{Methodology}
\somecontents
\end{document}

enter image description here

  • Thanks! It worked perfectly! I also removed everything else you mentioned!!! Thanks a lot! Now I can finally submit the last version!! :) – user95256 Oct 5 '16 at 19:27
  • @user95256 To indicate that the solution worked for you, please tick the check mark to its left. Otherwise it looks like an unresolved issue. See here for an explanation. – gernot Oct 6 '16 at 8:05

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.