Text FormattingAdding "Chapter" to the start of numbered chapters in TOC using tocbasic

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Hersa37
Posts: 1
Joined: Wed Mar 20, 2024 1:39 pm

Adding "Chapter" to the start of numbered chapters in TOC using tocbasic

Post by Hersa37 »

I'm still new to latex, not even a month, and I'm struggling to handle toc entry modifications when I'm using tocbasic. I've tried using tocloft to manage my list of stuff, but I'm struggling to make a consistent look for custom floats like appendices and code listings, so I tried using tocbasic. The looks are consistent but I have yet to find a way to add "Chapter" to numbered toc entries. So, the outcome would be "Chapter I Some Chapter". I'm also trying to add things like "Figure" and "Table" to the respective entries. While I'm at it, I also want to be able to capitalize all the entries.

I don't mind if I need to try komascript, but after reading at the documentation idk if I'm ready to go there yet.

Below is a part of what I've been working on. I tried trimming what I feel like I don't need to show, but if there's anything else I need to provide, let me know

Code: Select all

\documentclass[oneside,12pt]{book}

\usepackage{titlesec} % Manage chapter and sections

\usepackage{lipsum} % Lorem Ipsum
\usepackage[portrait, left=4cm, right=3cm, top=3cm, bottom=3cm]{geometry} % set margins
\usepackage{indentfirst} % indents first line after section

\usepackage{tocbasic} % TOC modifications
\usepackage{float}

%=================== Chapter numbering =====================%
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}

\titleformat 
{\chapter} 
[display]
{\bfseries\Large\centering} 
{\uppercase{Bab} \Roman{chapter}}
{0.5ex} 
{\uppercase}
[\vspace{-0.5ex}] 

\titlespacing{\chapter}{0pt}{0pt}{20pt} 

%================== Quote modifications =============%
\renewenvironment{quote} {
	\list{}{%
		\leftmargin0.5in   
		\rightmargin0cm
	}
	\item\relax
}
{\endlist}

%============= Table of contents modifications ==========%

\setcounter{tocdepth}{1}									
\renewcommand{\contentsname}{Daftar Isi}
\renewcommand{\listfigurename}{Daftar Gambar}
\renewcommand{\listtablename}{Daftar Tabel}


\DeclareTOCStyleEntry[]
{dottedtocline}{chapter}

\DeclareNewTOC[
type=lampiran,
types=lampiran,
float,
floattype=4,
name=Lampiran,
listname={Daftar Lampiran}
]{lor}
\setuptoc{lor}{chapteratlist}

%================ Start of document ==================%
\begin{document}
	
	%=================== Front matters =======================%
	% Bastracts, page of thanks, table of content/figures/etc
	\frontmatter

	\setcounter{tocdepth}{0}
	\renewcommand{\thechapter}{\Roman{chapter}} % Makes chapter numbering roman numeral
	\tableofcontents
	\setcounter{tocdepth}{2}
	\addcontentsline{toc}{chapter}{Daftar Lampiran}
	\setcounter{tocdepth}{1}
	\listoflampiran
	
	%=================== Main part of document =================%
	% Chapters etc
	% TODO: Check if spacing is correct
	\mainmatter
	
	\chapter{First}
	\section{first}
	\lipsum[1-2]
	
	\chapter{Second}
	\backmatter

	\clearpage
	\appendix
	\addcontentsline{toc}{chapter}{Lampiran}
	
	\begin{lampiran}[H]
		\caption{Lampiran Pertama}
		
		something2
	\end{lampiran}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply