I'm using memoir to write my PhD thesis. I want to make a special formatting in the LoF and LoT parts of my thesis. Specifically, I want above each group of figures or tables to print simply a "Chapter x", just for better visualization. I followed the guide here (somehow adapted) using etoolbox. The problem is that the code does not check the
\ifbool
command and a "Chapter x" is always printed for all chapters, although there are chapters that might not contain figures or tables. What I wanted was to conditionally print the "Chapter x" only for chapters that do contain figures or tables. Attached are some snapshots from the XeLaTeX compilation where you can see the error plus a MWE.
Code: Select all
\documentclass[12pt,a4paper,headsepline,twoside]{memoir}
\usepackage{etoolbox}
\usepackage{graphicx}
\providebool{newchap}
\newcommand{\mytitle}[1]{
\chapter{#1}
\global\setbool{newchap}{true}
\ifbool{newchap}{\addtocontents{lof}{\textbf{Chapter \thechapter} \vspace{8pt}}}{\global\boolfalse{newchap}}
\ifbool{newchap}{\addtocontents{lot}{\textbf{Chapter \thechapter} \vspace{8pt}}}{\global\boolfalse{newchap}}
}
\begin{document}
\newpage
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
%\pagestyle{contents}
\setcounter{page}{1}
\pagenumbering{roman}
\newpage
\tableofcontents
\newpage
\listoffigures
%
\newpage
\listoftables
\newpage
\pagenumbering{arabic}
\mytitle{Introduction} \label{ch:1}
\begin{figure}[t]
\centering
\includegraphics[width=5.8in]{ch2_fig2}
\caption{Figure 1}
\label{ch1:fig2}
\end{figure}
\newpage
\mytitle{Mathematical Background} \label{ch:2}
\begin{figure}[t]
\centering
\includegraphics[width=5.8in]{ch2_fig2}
\caption{Figure 2}
\label{ch2:fig1}
\end{figure}
\newpage
\mytitle{Chapter 3} \label{ch:3}
\begin{table}[t]
\renewcommand{\arraystretch}{1.5}
\centering
\begin{tabular}{|l | c |c |c |c |}
\hline
1, 3, 4 & $5L$ & $5L$ & $2L$ & $2L$\\
\hline
\end{tabular}
\caption{Table 1}
\label{ch3:table1}
\end{table}
\newpage
\mytitle{Chapter 4} \label{ch:4}
\begin{table}[t]
\renewcommand{\arraystretch}{1.5}
\centering
\begin{tabular}{|l | c |c |c |c |}
\hline
First BC & $L^2+2L$ & $L^2+L$ & $L^2+3L$ & $L^2+2L$\\
Total & $2L^2+9L$ & $2L^2+8L$ & $2L^2+6L$ & $2L^2+5L$\\
\hline
\end{tabular}
\caption{Table 2}
\label{ch4:table1}
\end{table}
\def\thechapter{A}
\newpage
\end{document}