请问如何能在目录章节编号的前面加星号?【转群友的问题】

发布于 2022-03-20 20:32:18

请问如何能在目录章节编号的前面加星号?如下图:
image.png

查看更多

关注者
1
被浏览
1.3k
1 个回答
LaTeXStudio
LaTeXStudio 2022-03-20
这家伙很懒,什么也没写!

解决方案一:选自:https://tex.stackexchange.com/questions/16336/add-an-asterisk-in-front-of-section-label-in-toc

\documentclass{book}
\usepackage{tocloft}
\usepackage{lipsum} % for dummy text
\newenvironment{hard}
{\renewcommand{\thesection}{*\thechapter.\arabic{section}}}
{}
% set section numbers in TOC flush right (from the tocloft documentation)
\newlength{\extralen}
\setlength{\extralen}{0.5em}    % need some extra space at end of number
\renewcommand{\cftsecpresnum}{\hfill} % note the double ‘l’ 
\renewcommand{\cftsecaftersnum}{\hspace*{\extralen}}
\addtolength{\cftsecnumwidth}{\extralen}
\begin{document}
\tableofcontents
\chapter{A chapter}
\section{A regular section}\label{easylabel}
In Section~\ref{easylabel} we see\ldots
\lipsum
\begin{hard}
\section{A hard section}\label{hardlabel}
\lipsum
\end{hard}
In Section~\ref{hardlabel} we see\ldots
\end{document}

效果图:
image.png

解决方案二:莲枝提供:

\usepackage[titles]{tocloft}
\usepackage{etoolbox}

\section{Foo}
\addtocontents{toc}{\protecting{\renewcommand{\cftsubsecpresnum}{\makebox[0pt][r]{$\star$\space}}}}
\subsection{Something something}
\addtocontents{toc}{\protecting{\renewcommand{\cftsubsecpresnum}{}}}

效果图:
image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览