我想以与 toc.ie 章节号、章节栏和该章节图表列表相同的方式格式化图表列表

我想以与 toc.ie 章节号、章节栏和该章节图表列表相同的方式格式化图表列表
\documentclass[a4,12pt]{report}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage[margin=1.5cm]{geometry}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%%%%%%%%%%%%%%%%%% fancy heading  \section %%%%%%%%%%%%%%%%%%%%%%

\titleformat{\section}[block]%              
    {\huge\bfseries%
     \tikz[overlay] \shade[left color=teal,right color=white,] (0,-1ex) rectangle (\textwidth,1em);}%    
    {\thesection}%                   
    {1em}%
    {#1}

%%%%%%%%%%%%%%%%%% fancy heading  \chapter %%%%%%%%%%%%%%%%%%%%%%%%

\newcommand*\chapterlabel{}
\titleformat{\chapter}
{\gdef\chapterlabel{}
  \normalfont\rmfamily\Huge\bfseries\scshape}
{\gdef\chapterlabel{\thechapter\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
    {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=cyan] (0,0) rectangle
        (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
        rounded corners=20pt,inner sep=11pt,
        fill=teal]
        {\color{white}\chapterlabel#1};
      \end{tikzpicture}
    };
  \end{tikzpicture}
}
\titlespacing*{\chapter}{0pt}{50pt}{0pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[titles]{tocloft}
\renewcommand{\cftdot}{\hfill}
\usepackage[most]{tcolorbox}


\newtcbox{\chapternumberbox}[1][]{%
  colback=blue!50!black,
  colupper={white},
  fontupper={\bfseries\large},
  valign=center,
  size=small,
  nobeforeafter,
  equal height group=chaptertoc,
  #1,
}




\newtcolorbox{chapternamebox}[1][]{%
  enhanced jigsaw,
  valign=center,
  interior style={left color={white!30!blue},right color={blue}},
  colframe={gray},
  boxrule={1pt},
  colupper={white},
  size=small,
  fontupper={\bfseries\large},
  nobeforeafter,
  equal height group=chaptertoc,
  #1,
}

% A wrapper command
\newcommand{\mychapternamebox}[3][]{%
  \begin{chapternamebox}[#1]
    #2\hfill#3%
  \end{chapternamebox}%
}


\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@chapter}{%
  \addcontentsline{toc}{chapter}%
  {\protect\numberline{\thechapter}#1}%
}{%
  \addtocontents{toc}{\protect\cftpagenumbersoff{chapter}}
  \addcontentsline{toc}{chapter}{\protect\chapternumberbox{\protect\chaptername{} \thechapter}\protect\mychapternamebox[width={12cm}]{#1}{\thepage}}%%
  \addtocontents{toc}{\protect\cftpagenumberson{chapter}}%
}{}{}
\makeatother
%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%

\begin{document}
\tableofcontents
\listoffigures
\listoftables
\chapter{Introduction}

\section{hockey}
\lipsum[1]
\begin{figure}
\includegraphics[scale=.5]{a}
\caption{ZnO Particles}
\end{figure}

\section{football}
\lipsum[1]
\chapter{Research Statement}
\begin{figure}
\includegraphics[scale=.5]{a}
\caption{Nano Particles}
\end{figure}


\end{document}

在此处输入图片描述

答案1

此解决方案仅将 LOF 标题添加到需要的章节。首先,它将章节标题和页码保存为全局宏。然后,如果图形计数器为零(章节中的第一个图形),它会修补图形环境以添加 LOF 标题。

请注意,这假设每个图形都有一个\caption,但我想避免修补,\caption因为这会与某些文档类别冲突。

\documentclass[a4,12pt]{report}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage[margin=1.5cm]{geometry}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%%%%%%%%%%%%%%%%%% fancy heading  \section %%%%%%%%%%%%%%%%%%%%%%

\titleformat{\section}[block]%              
    {\huge\bfseries%
     \tikz[overlay] \shade[left color=teal,right color=white,] (0,-1ex) rectangle (\textwidth,1em);}%    
    {\thesection}%                   
    {1em}%
    {#1}

%%%%%%%%%%%%%%%%%% fancy heading  \chapter %%%%%%%%%%%%%%%%%%%%%%%%

\newcommand*\chapterlabel{}
\titleformat{\chapter}
{\gdef\chapterlabel{}
  \normalfont\rmfamily\Huge\bfseries\scshape}
{\gdef\chapterlabel{\thechapter\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
    {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=cyan] (0,0) rectangle
        (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
        rounded corners=20pt,inner sep=11pt,
        fill=teal]
        {\color{white}\chapterlabel#1};
      \end{tikzpicture}
    };
  \end{tikzpicture}
}
\titlespacing*{\chapter}{0pt}{50pt}{0pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[titles]{tocloft}
\renewcommand{\cftdot}{\hfill}
\usepackage[most]{tcolorbox}


\newtcbox{\chapternumberbox}[1][]{%
  colback=blue!50!black,
  colupper={white},
  fontupper={\bfseries\large},
  valign=center,
  size=small,
  nobeforeafter,
  equal height group=chaptertoc,
  #1,
}




\newtcolorbox{chapternamebox}[1][]{%
  enhanced jigsaw,
  valign=center,
  interior style={left color={white!30!blue},right color={blue}},
  colframe={gray},
  boxrule={1pt},
  colupper={white},
  size=small,
  fontupper={\bfseries\large},
  nobeforeafter,
  equal height group=chaptertoc,
  #1,
}

% A wrapper command
\newcommand{\mychapternamebox}[3][]{%
  \begin{chapternamebox}[#1]
    #2\hfill#3%
  \end{chapternamebox}%
}


\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@chapter}{%
  \addcontentsline{toc}{chapter}%
  {\protect\numberline{\thechapter}#1}%
}{%
  \addtocontents{toc}{\protect\cftpagenumbersoff{chapter}}%
  \addcontentsline{toc}{chapter}{\protect\chapternumberbox{\thechapter}\protect\mychapternamebox[width={12cm}]{#1}{\thepage}}%
  \addtocontents{toc}{\protect\cftpagenumberson{chapter}}%
  \xdef\chaptertitle{#1}% save chapter title
  \xdef\chapterpage{\thepage}% save current page number
}{}{}

\let\oldfigure=\figure
\def\figure{\ifnum\value{figure}=0\relax
  \addtocontents{lof}{\protect\cftpagenumbersoff{chapter}}%
  \addcontentsline{lof}{chapter}{\protect\chapternumberbox{\thechapter}\protect\mychapternamebox[width={12cm}]{\chaptertitle}{\chapterpage}}%
  \addtocontents{lof}{\protect\cftpagenumberson{chapter}}%
\fi\oldfigure}
\makeatother
%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%

\begin{document}
\tableofcontents
\listoffigures
\listoftables
\chapter{Introduction}

\section{hockey}
\lipsum[1]
\begin{figure}
\includegraphics[scale=.5]{example-image-a}
\caption{ZnO Particles}
\end{figure}

\begin{figure}
\includegraphics[scale=.5]{example-image-a}
\caption{Nano Particles}
\end{figure}

\section{football}
\lipsum[1]
\chapter{Research Statement}

\end{document}

该版本使用\label\pageref来生成页码,这将延迟扩展\thepage直到页面发货。

\documentclass[a4,12pt]{report}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage[margin=1.5cm]{geometry}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%%%%%%%%%%%%%%%%%% fancy heading  \section %%%%%%%%%%%%%%%%%%%%%%

\titleformat{\section}[block]%              
    {\huge\bfseries%
     \tikz[overlay] \shade[left color=teal,right color=white,] (0,-1ex) rectangle (\textwidth,1em);}%    
    {\thesection}%                   
    {1em}%
    {#1}

%%%%%%%%%%%%%%%%%% fancy heading  \chapter %%%%%%%%%%%%%%%%%%%%%%%%

\newcommand*\chapterlabel{}
\titleformat{\chapter}
{\gdef\chapterlabel{}
  \normalfont\rmfamily\Huge\bfseries\scshape}
{\gdef\chapterlabel{\thechapter\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
    {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=cyan] (0,0) rectangle
        (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
        rounded corners=20pt,inner sep=11pt,
        fill=teal]
        {\color{white}\chapterlabel#1};
      \end{tikzpicture}
    };
  \end{tikzpicture}
}
\titlespacing*{\chapter}{0pt}{50pt}{0pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[titles]{tocloft}
\renewcommand{\cftdot}{\hfill}
\usepackage[most]{tcolorbox}


\newtcbox{\chapternumberbox}[1][]{%
  colback=blue!50!black,
  colupper={white},
  fontupper={\bfseries\large},
  valign=center,
  size=small,
  nobeforeafter,
  equal height group=chaptertoc,
  #1,
}




\newtcolorbox{chapternamebox}[1][]{%
  enhanced jigsaw,
  valign=center,
  interior style={left color={white!30!blue},right color={blue}},
  colframe={gray},
  boxrule={1pt},
  colupper={white},
  size=small,
  fontupper={\bfseries\large},
  nobeforeafter,
  equal height group=chaptertoc,
  #1,
}

% A wrapper command
\newcommand{\mychapternamebox}[3][]{%
  \begin{chapternamebox}[#1]
    #2\hfill#3%
  \end{chapternamebox}%
}


\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@chapter}{%
  \addcontentsline{toc}{chapter}%
  {\protect\numberline{\thechapter}#1}%
}{%
  \addtocontents{toc}{\protect\cftpagenumbersoff{chapter}}%
  \addcontentsline{toc}{chapter}{\protect\chapternumberbox{\thechapter}\protect\mychapternamebox[width={12cm}]{#1}{\thepage}}%
  \addtocontents{toc}{\protect\cftpagenumberson{chapter}}%
  \xdef\chaptertitle{#1}% save chapter title
  \label{chapter\thechapter}% set up \pageref
}{}{}

\let\oldfigure=\figure
\def\figure{\ifnum\value{figure}=0\relax
  \addtocontents{lof}{\protect\cftpagenumbersoff{chapter}}%
  \addcontentsline{lof}{chapter}{\protect\chapternumberbox{\thechapter}\protect\mychapternamebox[width={12cm}]{\chaptertitle}%
    {\pageref{chapter\thechapter}}}%
  \addtocontents{lof}{\protect\cftpagenumberson{chapter}}%
\fi\oldfigure}
\makeatother
%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%

\begin{document}
\tableofcontents
\listoffigures
\listoftables
\chapter{Introduction}

\section{hockey}
\lipsum[1]
\begin{figure}
\includegraphics[scale=.5]{example-image-a}
\caption{ZnO Particles}
\end{figure}

\begin{figure}
\includegraphics[scale=.5]{example-image-a}
\caption{Nano Particles}
\end{figure}

\section{football}
\lipsum[1]
\chapter{Research Statement}

\end{document}

答案2

在你的第二部分

\xpatchcmd{\@chapter}{%
  % stuff here
}{%
  % more stuff here about toc
}

加入

more stuff here about lof

也就是说,重复toc内容但使用lof文件名。

相关内容