For my dissertation, I need to create a list of tables containing both tables from the main chapters and the corresponding appendices to each chapter. For each appendix table, a capital A is set before the chapter and section number to distinguish them from the tables in the main body. Unfortunately, this setup results in a misalignment of the table numbers in the list of tables, in addition to overlapping with the table titles for appendix tables 10+ (as shown below).
Ideally, I would have all the tables align along the dot within the list of tables. I have looked at the tocloft package, but have not been able to figure out how to reduce the left indentation for the appendix tables only. I have also tried to follow an approach similar to this allowing the A to have zero width in the list of tables, but I could never successfully get it to run.
Any help would be much appreciated. Below is the code to generate the above image.
\documentclass[11pt,oneside,english,doublespacing,liststotoc,toctotoc]{MastersDoctoralThesis}%
\begin{document}
\listoftables
\chapter{1}
\section{1}
\begin{table}
\caption{Table}%
\label{table1}
\end{table}
\section*{Appendix}
\setcounter{table}{0}
\renewcommand{\thetable}{A\thechapter.\arabic{table}}
\begin{table}
\caption{Table in appendix}%
\label{tablea1}
\end{table}
\setcounter{table}{9}
\begin{table}
\caption{Another table in appendix}%
\label{tablea10}
\end{table}
\end{document}
Update:
Ok, I was able to repurpose the above mentioned approach for table number alignment within a list of tables (see image and code below).
\documentclass[11pt,oneside,english,doublespacing,liststotoc,toctotoc]{MastersDoctoralThesis}%
\usepackage{xparse}
\usepackage{kantlipsum}
\NewDocumentCommand{\optionaltable}{O{#3}om}{%
\renewcommand{\thetable}{\opta\standardthetable}%
\optzerotrue
\IfNoValueTF{#2}{\table[#1]{#3}}{\table[#1][#2]{#3}}%
\optzerofalse
\renewcommand{\thetable}{\standardthetable}%
}
\AtBeginDocument{\let\standardthetable\thetable}
\NewDocumentCommand{\opta}{}{%
\ifoptzero\makebox[0pt][r]{A}\else A\fi
}
\newif\ifoptzero
\begin{document}
\optzerotrue
\listoftables
\optzerofalse
\chapter{1}
\section{1}
\begin{table}
\caption{Table}%
\label{table1}
\end{table}
\section*{Appendix}
\setcounter{table}{0}
\renewcommand{\thetable}{\opta\standardthetable}
\begin{table}
\caption{Table in appendix}%
\label{tablea1}
\end{table}
\setcounter{table}{9}
\begin{table}
\caption{Another table in appendix}%
\label{tablea10}
\end{table}
\end{document}
I am still not too sure what the code is exactly doing, especially the following part:
\NewDocumentCommand{\optionaltable}{O{#3}om}{%
\renewcommand{\thetable}{\opta\standardthetable}%
\optzerotrue
\IfNoValueTF{#2}{\table[#1]{#3}}{\table[#1][#2]{#3}}%
\optzerofalse
\renewcommand{\thetable}{\standardthetable}%
}
Nevertheless, this will do for my purpose now.


bookclass instead of of yourMastersDoctoralThesisto which I had no access as you hadn't said where you got it from. The code that you say works seems very complex. I have a feeling thatMastersDoctoralThesisdoes unusual things if it can't process the code in my MWE. I wouldn't be surprised if you found more difficulties trying to tweak your outptut. – Peter Wilson May 30 '20 at 17:07