2

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).

enter image description here

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).

enter image description here

\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.

1 Answers1

0

I don't think that tocloft will help with your alignment problem but try the MWE below (changed the documentclass to book because the class you used I didn't have access to).

% apptocprob.tex SE 546892

%\documentclass[11pt,oneside,english,doublespacing,liststotoc,toctotoc]{MastersDoctoralThesis}%
\documentclass{book}
\usepackage{tocloft}
\setlength{\cfttabnumwidth}{3em} % choose this to suit

\begin{document}

\listoftables

\renewcommand{\thetable}{\phantom{A}\thechapter.\arabic{table}}
\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} 

I have used tocloft to make extra space for long table numbers. In the body of the document I have changed the regular table numbering to include a space equivalent to A before the number. This all works, at least in the LoT.

Peter Wilson
  • 28,066
  • The MWE above doesn't seem to work; it returns a: Incomplete \iffalse; all text was ignored after line 16. – Sebastian Roth May 29 '20 at 22:33
  • @Easystyle The MWE code as given does work. Note that I used the book class instead of of your MastersDoctoralThesis to 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 that MastersDoctoralThesis does 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