我正在写报告。我正在使用以下代码。
\documentclass{report}
\usepackage{chngcntr,tocloft}
\counterwithin*{figure}{section}
\counterwithin*{figure}{subsection}
\counterwithin*{figure}{subsubsection}
\addtolength{\cftfignumwidth}{2em}
\renewcommand{\thefigure}{%
\ifnum\value{section}=0
\thechapter.\arabic{figure}%
\else
\ifnum\value{subsection}=0
\thesection.\arabic{figure}%
\else
\ifnum\value{subsubsection}=0
\thesubsection.\arabic{figure}%
\else
\thesubsubsection.\arabic{figure}%
\fi
\fi
\fi
}
\begin{document}
\listoffigures
\chapter{Intro}
\section{A section}
\begin{figure}[!htp]
\caption{section.figure}
\end{figure}
\subsection{A subsection}
\begin{figure}[!htp]
\caption{subsection.figure}
\end{figure}
\begin{figure}[!htp]
\caption{subsection.figure}
\end{figure}
\subsubsection{A subsubsection}
\begin{figure}[!htp]
\caption{subsubsection.figure}
\end{figure}
\subsection{A subsection}
\begin{figure}[!htp]
\caption{subsection.figure}
\end{figure}
\section{A section}
\begin{figure}[!htp]
\caption{section.figure}
\end{figure}
\end{document}
这给了我这样的输出: 但我想要这样的输出: 如何获得它。它应该适用于图表列表和表格列表
答案1
目前还没有完全解决——它们dots
仍然会消失。我正在努力解决这个问题。
\documentclass{report}
\usepackage{chngcntr}
\usepackage{tocloft}
\counterwithin*{figure}{section}
\counterwithin*{figure}{subsection}
\counterwithin*{figure}{subsubsection}
\addtolength{\cftfignumwidth}{2em}
\renewcommand{\thefigure}{%
\ifnum\value{section}=0
\thechapter.\arabic{figure}%
\else
\ifnum\value{subsection}=0
\thesection.\arabic{figure}%
\else
\ifnum\value{subsubsection}=0
\thesubsection.\arabic{figure}%
\else
\thesubsubsection.\arabic{figure}%
\fi
\fi
\fi
}
\usepackage{calc}
\begin{document}
\listoffigures
\setlength{\cftfignumwidth}{\widthof{figurename}}
\setlength{\cfttabnumwidth}{\widthof{tablename}}
\addtocontents{lof}{\protect\contentsline{figure}{\numberline{\bfseries \figurename}\textbf{Illustration}}{\textbf{Page}}}
\addtocontents{lot}{\protect\contentsline{figure}{\numberline{\bfseries \tablename}\textbf{Description}}{\textbf{Page}}}
\listoftables
\chapter{Intro}
\section{A section}
\begin{figure}[!htp]
\caption{section.figure}
\end{figure}
\subsection{A subsection}
\begin{figure}[!htp]
\caption{subsection.figure}
\end{figure}
\begin{figure}[!htp]
\caption{subsection.figure}
\end{figure}
\subsubsection{A subsubsection}
\begin{figure}[!htp]
\caption{subsubsection.figure}
\end{figure}
\subsection{A subsection}
\begin{figure}[!htp]
\caption{subsection.figure}
\end{figure}
\section{A section}
\begin{figure}[!htp]
\caption{section.figure}
\end{figure}
\begin{table}[!htp]
\caption{Another table}
\end{table}
\end{document}
编辑改良版
\documentclass{report}
\usepackage{chngcntr}
\usepackage{tocloft}
\counterwithin*{figure}{section}
\counterwithin*{figure}{subsection}
\counterwithin*{figure}{subsubsection}
\addtolength{\cftfignumwidth}{2em}
\renewcommand{\thefigure}{%
\ifnum\value{section}=0
\thechapter.\arabic{figure}%
\else
\ifnum\value{subsection}=0
\thesection.\arabic{figure}%
\else
\ifnum\value{subsubsection}=0
\thesubsection.\arabic{figure}%
\else
\thesubsubsection.\arabic{figure}%
\fi
\fi
\fi
}
\usepackage{calc}
\usepackage{xpatch}
\makeatletter
\let\@origpnumwidth\@pnumwidth
\let\@newdottedtocline\@dottedtocline%
\xpatchcmd{\@newdottedtocline}{%
\hbox{.}%
}{%
\hbox{}% Drop the dots
}{}{}
\renewcommand{\@pnumwidth}{25pt}%
\newcommand*\l@figureheading{\@newdottedtocline{2}{1.5em}{\cftfignumwidth}}
\newcommand*\l@tableheading{\@newdottedtocline{2}{1.5em}{\cfttabnumwidth}}
\makeatother
\begin{document}
\tableofcontents
\makeatletter
\listoffigures
\setlength{\cftfignumwidth}{\widthof{figurename}}
\setlength{\cfttabnumwidth}{\widthof{tablename}}
\addtocontents{lof}{\protect\contentsline{figureheading}{\numberline{\bfseries \figurename}\textbf{Illustration}}{\textbf{Page}}}
\addtocontents{lot}{\protect\contentsline{tableheading}{\numberline{\bfseries \tablename}\textbf{Description}}{\textbf{Page}}}
\listoftables
\let\@pnumwidth\@origpnumwidth
\makeatother
\chapter{Intro}
\section{A section}
\begin{figure}[!htp]
\caption{section.figure}
\end{figure}
\subsection{A subsection}
\begin{figure}[!htp]
\caption{subsection.figure}
\end{figure}
\begin{figure}[!htp]
\caption{subsection.figure}
\end{figure}
\subsubsection{A subsubsection}
\begin{figure}[!htp]
\caption{subsubsection.figure}
\end{figure}
\subsection{A subsection}
\begin{figure}[!htp]
\caption{subsection.figure}
\end{figure}
\section{A section}
\begin{figure}[!htp]
\caption{section.figure}
\end{figure}
\begin{table}[!htp]
\caption{Another table}
\end{table}
\end{document}