我正在尝试让章节号显示在目录中。这是我当前的代码:
\documentclass{report}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{titletoc}
\definecolor{tbl}{HTML}{F035A3}
\contentsmargin{0cm}
\makeatletter
\titlecontents{chapter}[3.7pc]
{%
\addvspace{30pt}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=tbl,draw=tbl] (-7,-.1) rectangle (-0.7,.5);%
\pgftext[left,x=-3.6cm,y=0.2cm]{\color{white}\Large\sc\bfseries Lecture\ \thecontentslabel};%
\end{tikzpicture}%
\color{tbl}\large\sc\bfseries%
}%
{}
{}
{\;\titlerule\;\large\sc\bfseries Page \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=tbl,draw=tbl] (2pt,0) rectangle (4,0.1pt);
\end{tikzpicture}}%
\titlecontents{section}[3.7pc]
{\addvspace{2pt}}
{\contentslabel[\thecontentslabel]{2pc}}
{}
{\hfill\small \thecontentspage}
[]
\titlecontents*{subsection}[3.7pc]
{\addvspace{-1pt}\small}
{}
{}
{\ --- \small\thecontentspage}
[ \textbullet\ ][]
\makeatother
\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{-20\p@}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=15cm,y=0.2cm]{\color{tbl}\Huge\sc\bfseries \contentsname};%
\draw[fill=tbl,draw=tbl] (13,-.75) rectangle (20,1);%
\clip (13,-.75) rectangle (20,1);
\pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge\sc\bfseries \contentsname};%
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
\newcommand\lecture[2]{%
\setcounter{chapter}{#1}
\section*{Lecture #1: #2}
\addcontentsline{toc}{chapter}{#2}
}
\begin{document}
\tableofcontents
\lecture{5}{Hi}
\lecture{1}{Hi}
\lecture{9}{Hi}
\lecture{10}{Hi}
\lecture{2}{Hi}
\end{document}
创建以下 PDF:
如何让章节号显示在左侧演讲文本?我尝试添加\arabic{chapter}
, \thechapter
。我甚至尝试创建一个计数器和一个变量,并将其放在演讲文本,但仍然不起作用。我该怎么办?
答案1
找到了我的答案(通过 chatgpt)。我只需要将以下行从:
\pgftext[left,x=-3.6cm,y=0.2cm]{\color{white}\Large\sc\bfseries Lecture\ \thecontentslabel};%
到
\pgftext[left,x=-3.7cm,y=0.2cm]{\color{white}\Large\sc\bfseries Lecture~\thecontentslabel\\*\hspace*{.7em}\ \thecontentslabel};