TransWikia.com

Use arabic chapter label for figure and table, if chapter use NUMBERSTRING{chapter}

TeX - LaTeX Asked by riza on July 5, 2021

I use

%% Use CHAPTER ONE instead of CHAPTER 1
renewcommand{thechapter}{NUMBERstring{chapter}}

to change CHAPTER 1 to CHAPTER ONE.

However, for Equation, Table and Figure. I want to use arabic for chapter number. I try this code:

renewcommand{thetable}{arabic{chapter}.arabic{table}}
renewcommand{thefigure}{arabic{chapter}.arabic{figure}}
renewcommand{theequation}{arabic{chapter}.arabic{equation}}

It works fine for Equation, but, not for Figure and Table.

enter image description here

This is the minimal code:

documentclass[a4paper,12pt,oneside]{memoir}

usepackage{amsmath,amsfonts}
usepackage{graphicx}
usepackage{fmtcount} 
usepackage[T1]{fontenc}
usepackage{mathptmx} %Times font
usepackage{lipsum}

%% Format Chapter. Eg. CHAPTER ONE.
renewcommand*{chapterheadstart}{} %remove margin before chapter
setlength{midchapskip}{-2pt} % between chapter and chapter name
renewcommand*{chapnamefont}{largebfseries}
renewcommand*{chaptitlefont}{largebfseriescentering}
renewcommand*{chapnumfont}{largebfseriescentering}
renewcommand*{printchaptername}{%
    centeringchapnamefontMakeUppercase{chaptername}}%
renewcommand*{printchaptertitle}[1]{chaptitlefontMakeUppercase{#1}}
renewcommand{thechapter}{NUMBERstring{chapter}}

%% Add word CHAPTER before the chapter number in TOC. Eg. CHAPTER ONE.
renewcommand*chapternumberline[1]{%
    CHAPTER #1:spacespace
}

%% Add word Page on top of page numbers in TOC, LOT and LOF.
addtocontents{toc}{protectcontentsline{chapter}{}{Page}}
addtocontents{lot}{protectcontentsline{chapter}{Tables Title}{Page}}
addtocontents{lof}{protectcontentsline{chapter}{Figures Title}{Page}}

%% Format Section. Eg. 1.1.
renewcommand{thesection}{arabic{chapter}.arabic{section}}

%% Format Table, Figure and Equation label. Eg. Figure 4.1.
renewcommand{theequation}{arabic{chapter}.arabic{equation}} % work
renewcommand{thetable}{arabic{chapter}.arabic{table}} % does not work
renewcommand{thefigure}{arabic{chapter}.arabic{figure}} % does not work

%% Add a new page after List of Tables / Figures.
renewcommand{lotheadstart}{clearpage} 
renewcommand{lofheadstart}{clearpage}

begin{document}
tableofcontents
listoftables
listoffigures


mainmatter
chapter{Introduction}
lipsum[1]

begin{table}[ht]
    caption{A Table}
    label{table:atable}
end{table}

begin{figure}[ht]
    caption{A Figure}
    label{fig:afigure}
end{figure}

begin{equation}
    y = mx + c
    label{eq:anequation}
end{equation}

section{A Section}
lipsum[1]

end{document}

2 Answers

I have solved the problem by moving these two lines:

renewcommand{thetable}{arabic{chapter}.arabic{table}}
renewcommand{thefigure}{arabic{chapter}.arabic{figure}}

outside the preamble, and put them after mainmatter.

However, is there a way to put them inside the preamble?

Answered by riza on July 5, 2021

Don't redefine thechapter, but printchapternum and chapternumberline:

%% Format Chapter. Eg. CHAPTER ONE.
renewcommand*{chapterheadstart}{} %remove margin before chapter
setlength{midchapskip}{-2pt} % between chapter and chapter name
renewcommand*{chapnamefont}{largebfseries}
renewcommand*{chaptitlefont}{largebfseriescentering}
renewcommand*{chapnumfont}{largebfseriescentering}
renewcommand*{printchaptername}{%
    centeringchapnamefontMakeUppercase{chaptername}}%
renewcommand{printchapternum}{chapnumfontNUMBERstring{chapter}}
renewcommand*{printchaptertitle}[1]{chaptitlefontMakeUppercase{#1}}

%% Add word CHAPTER before the chapter number in TOC. Eg. CHAPTER ONE.
renewcommand*chapternumberline[1]{%
    CHAPTER NUMBERstringnum{#1}:spacespace
}

Answered by egreg on July 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP