我尝试创建文档,使得第一章有一个编号,章节没有编号,但每个问题环境都有一个与章节编号匹配的连续编号,并且编号从 1 开始。例如:
Chapter 1
Coordinate transformation
Problem 1.1.
Problem 1.2.
.
.
.
Chapter 2 Linear Algebra
matrices
Problem 2.1.
Problem 2.2.
.
.
.
SLAE solution
Problem 2.10.
Problem 2.11.
.
.
.
Chapter 5. Integral Calculus
Definite integral
Problem 5.1.
Problem 5.2.
.
.
.
Indefinite integral
Problem 5.20.
Problem 5.21.
.
.
.
Chapter 8. Differential Equations
Linear ODEs
Problem 8.1.
Problem 8.2.
.
.
.
ODE systems
Problem 8.25.
Problem 8.26.
.
.
.
在这种情况下,第 1-4 章的问题环境应为绿色,第 5-7 章为蓝色,第 8-10 章为深橙色。当我开始编译此文件时,出现错误:
未定义控制序列。} 太多。"
我的代码:
\documentclass[a4paper, 12pt]{report}
\usepackage[left=2cm, right=1.5cm, top=1.5cm, bottom=2cm]{geometry}
\usepackage{setspace}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{tcolorbox}
\usepackage{titlesec}
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{changepage}
\usepackage{fancyhdr}
% 1. Line spacing 1.15
\setstretch{1.15}
% 2. Indent margin 1.25 cm
\setlength{\parindent}{1.25cm}
% 3. Indentation between adjacent paragraphs 12pt (double)
\setlength{\parskip}{12pt}
% 6. First page title page with date and title (centered)
\title{\centering\Huge Solution Manual \endgraf\vspace{1cm}\Large \today}
\date{}
\author{Alex Milns}
% 7. Subsequent pages - content
\titleformat{\chapter}[display]{\normalfont\huge\bfseries}{\thechapter}{14pt}{\Huge}
\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\large\bfseries}{\thesubsection}{1em}{}
% 8. Custom environment for problems
\newcounter{problem}[chapter]
\renewcommand{\theproblem}{\thechapter.\arabic{problem}}
\makeatletter
\@addtoreset{problem}{chapter}
\makeatother
\newenvironment{problem}[1]{%
\refstepcounter{problem}%
\phantomsection\addcontentsline{toc}{section}{Problem \thechapter.\theproblem}%
\par\medskip\noindent\textbf{Problem \thechapter.\theproblem: #1}\par%
\begin{tcolorbox}[colback=white!96!gray, colframe=white!5!Green, arc=5pt, title=Solution:]
}{\end{tcolorbox}}
% Define colors for different chapter ranges
\definecolor{problemcolor1}{RGB}{75, 157, 75} % Green
\definecolor{problemcolor2}{RGB}{30, 144, 255} % Blue
\definecolor{problemcolor3}{RGB}{255, 87, 34} % Dark Orange
\newcommand{\setproblemcolor}[1]{%
\ifnum\value{chapter}<5
\colorlet{problemcolor}{problemcolor1}
\else
\ifnum\value{chapter}<8
\colorlet{problemcolor}{problemcolor2}
\else
\colorlet{problemcolor}{problemcolor3}
\fi
\fi
}
% Apply color to problem environment
\newenvironment{customproblem}[1]{%
\refstepcounter{problem}%
\phantomsection\addcontentsline{toc}{subsection}{Problem \thechapter.\theproblem}%
\par\medskip\noindent\textbf{Problem \thechapter.\theproblem: #1}\par%
\begin{tcolorbox}[colback=white!96!gray, colframe=white!5!Green, arc=5pt, title=Solution:]
}{\end{tcolorbox}}
% 9. Main text font (Computer Modern)
\usepackage[T1,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{concmath} % Computer Modern font
% Hyperref settings
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,
}
\begin{document}
\maketitle
\thispagestyle{empty} % Remove page number from title page
\newpage
\tableofcontents
\thispagestyle{empty}
\newpage
\chapter{Vector algebra}
\section*{Cartesian coord}
\begin{customproblem}{Condition of the first problem}
Solution to the first problem goes here.
\end{customproblem}
\begin{customproblem}{Condition of the second problem}
Solution to the second problem goes here.
\end{customproblem}
\begin{customproblem}{Condition of the third problem}
Solution to the third problem goes here.
\end{customproblem}
\chapter{Linear Algebra}
\section*{Matrices}
\begin{customproblem}{Condition of the first problem}
Solution to the first problem goes here.
\end{customproblem}
\begin{customproblem}{Condition of the second problem}
Solution to the second problem goes here.
\end{customproblem}
\section*{SLAE solution}
\begin{customproblem}{Condition of the third problem}
Solution to the third problem goes here.
\end{customproblem}
\chapter{Integral Calculus}
\section*{Definite integral}
\begin{customproblem}{Condition of the first problem}
Solution to the first problem goes here.
\end{customproblem}
\begin{customproblem}{Condition of the second problem}
Solution to the second problem goes here.
\end{customproblem}
\section*{Indefinite integral}
\begin{customproblem}{Condition of the third problem}
Solution to the third problem goes here.
\end{customproblem}
\chapter{Differential Equations}
\section*{Linear ODEs}
\begin{customproblem}{Condition of the first problem}
Solution to the first problem goes here.
\end{customproblem}
\begin{customproblem}{Condition of the second problem}
Solution to the second problem goes here.
\end{customproblem}
\section*{ODE systems}
\begin{customproblem}{Condition of the third problem}
Solution to the third problem goes here.
\end{customproblem}
\chapter{Differential Equations}
\section*{Linear ODEs}
\begin{customproblem}{Condition of the first problem}
Solution to the first problem goes here.
\end{customproblem}
\chapter{Differential Equations}
\section*{Linear ODEs}
\begin{customproblem}{Condition of the first problem}
Solution to the first problem goes here.
\end{customproblem}
\end{document}
这个问题该如何解决呢?
更新:
我更新了代码,但任务编号不正确,问题是,是否可以更改目录的样式以使其不存在这样的间隙并将目录写在一行中?