我正在写一本练习册,希望实现以下结构:
1. First chapter: algebra
Exercise 1.1
Exercise 1.2
...
2. Indipendenza:
...
使用此代码我得到了以下令我高兴的结果。
\documentclass{book}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thechapter}{\arabic{chapter}}
\usepackage{titlesec}
\titleformat{\section}{\normalfont\Large\bfseries}{Esercizio~\thechapter.\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\large\bfseries}{Soluzione~\thechapter.\thesection}{1em}{}
\usepackage{titletoc}
\usepackage{etoolbox}
\setcounter{tocdepth}{1}
\begin{document}
\tableofcontents
\chapter{algebre}
\section{} % First
\subsection{}
test
\section{} % Second
\subsection{}
\section{} % Third
\subsection{}
\chapter{indipendenza}
\section{} % First
\subsection{}
\section{} % Second
\subsection{}
\section{} % Third
\subsection{}
\end{document}
加。如果我想做“第一部分:练习”/“第二部分:解决方案”,仍然使用相同的逻辑怎么办?
答案1
希望它能如您所愿!\titleformat
为您的章节和子章节提供一种格式,但要将其与章节标题分开。这就是为什么您只能在目录中获得章节编号作为输出。
\documentclass{book}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thechapter}{\arabic{chapter}}
\usepackage{titlesec}
\titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{}
\titleformat{\subsection}{\normalfont\large\bfseries}{}{0em}{}
\usepackage{titletoc}
\usepackage{etoolbox}
\setcounter{tocdepth}{1}
\newcommand{\Section}{\section{Esercizio~\thechapter.\thesection}}
\newcommand{\Subsection}{\subsection{Soluzione~\thechapter.\thesection}}
\begin{document}
\tableofcontents
\chapter{algebre}
\Section % First
\Subsection{}
test
\Section{} % Second
\Subsection{}
\Section{} % Third
\Subsection{}
\chapter{indipendenza}
\Section{} % First
\Subsection{}
\Section{} % Second
\Subsection{}
\Section{} % Third
\Subsection{}
\end{document}