![无法获取自定义目录中显示的章节编号](https://linux22.com/image/461829/%E6%97%A0%E6%B3%95%E8%8E%B7%E5%8F%96%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9B%AE%E5%BD%95%E4%B8%AD%E6%98%BE%E7%A4%BA%E7%9A%84%E7%AB%A0%E8%8A%82%E7%BC%96%E5%8F%B7.png)
我正在尝试让章节号显示在目录中。这是我当前的代码:
\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};