在图片列表中添加章节名称

在图片列表中添加章节名称

我想要将章节和小节的名称包含在我的图表列表中。

举例来说,我希望看到这样的内容ToC

1. Figures                             1

但我不想1. Figures在包含数字的部分实际开始的时候显示出来。我尝试使用\section[Figures]而不是\section{Figures} ,但在前一种情况下,我仍然有部分编号。我可以去掉它吗?

编辑:我的最终目标是得到这样的东西

1. Figures                          1
    1.1. Excitation energies        1
        1.1.1. Figure 1             1
        1.1.2. Figure 2             2

ETC。

答案1

以下是部分内容expl3这是我发布的代码的按部分列出的表格(或图表)列表 - LaTeX

代码现在更短了,但目前语法LaTeXexpl3语法的混合很奇怪。我会不时地改变这一点。

最重要的功能是命令\EnableSectionsinLOFT\AppendixSectionsInLOFT

目前该文档必须编译 3 次,但我尝试将编译顺序减少到 2 次。

默认情况下,附录部分名称不会出现在LoF和中LoT

\documentclass[paper=a4,12pt]{article}%

\usepackage[demo]{graphicx}%

\usepackage{blindtext}
\usepackage{caption}
\usepackage{placeins}
\usepackage{xassoccnt}
\usepackage{morewrites}
\usepackage{xparse}

\makeatletter


\ExplSyntaxOn

\bool_new:N \g_sectionsinloft_bool
\bool_new:N \g_isappendix_bool
\bool_new:N \g_appendixinlof_bool
\bool_new:N \g_appendixinlot_bool

% Get some file handles first --> rewrite with expl3 later on

\newwrite\figurecountsout%
\newwrite\tablecountsout%

\newread\figurecountsin%
\newread\tablecountsin%

% The number of runs...
\DeclareDocumentCounter{localnumberofruns}%

\newcommand{\secfig@@voidstage}{0}%
\newcommand{\secfig@@writecounterstage}{1}%
\newcommand{\secfig@@readcounterstage}{2}%
\newcommand{\secfig@@writecontentstage}{2}%
\newcommand{\secfig@@resetstage}{3}%

\newlength{\loftsectionbeforeskipamount}%
\newlength{\loftsectionafterskipamount}%
\setlength{\loftsectionafterskipamount}{\medskipamount}%
\setlength{\loftsectionbeforeskipamount}{\medskipamount}%

\newcommand{\loftsectionbeforeskip}{\vspace{\loftsectionbeforeskipamount}}%
\newcommand{\loftsectionafterskip}{\vspace{\loftsectionafterskipamount}}%


% Some wrappers

\newcommand{\EnableSectionsInLOFT}{%
  \bool_gset_true:N \g_sectionsinloft_bool
}%

\newcommand{\DisableSectionsInLOFT}{%
  \bool_gset_false:N \g_sectionsinloft_bool
}%

\newcommand{\EnableAppendixSectionInLOF}{%
  \bool_gset_true:N \g_appendixinlof_bool
}%

\newcommand{\DisableAppendixSectionInLOF}{%
  \bool_gset_false:N \g_appendixinlof_bool
}%

\newcommand{\EnableAppendixSectionInLOT}{%
  \bool_gset_true:N \g_appendixinlot_bool
}%

\newcommand{\DisableAppendixSectionInLOT}{%
  \bool_gset_false:N \g_appendixinlot_bool
}%

\newcommand{\EnableAppendixLOFT}{%
  \EnableAppendixSectionInLOF%
  \EnableAppendixSectionInLOT%
}%


\newcommand{\DisableAppendixLOFT}{%
  \DisableAppendixSectionInLOF%
  \DisableAppendixSectionInLOT%
}%


\let\latex@@appendix\appendix

\renewcommand{\appendix}{%
  \bool_gset_true:N \g_isappendix_bool%
  \latex@@appendix%
  \DisableAppendixLOFT%
}


% Needed for correct number of sections
\DeclareDocumentCounter{totalsections}
\DeclareAssociatedCounters{section}{totalsections}%

% localnumberofruns = 1 --> write figcount file --> no adding to lof
% localnumberofruns = 2 --> Read  fig counters file and decide if a section entry is to be done
% localnumberofruns = 3 --> Last update run to the toc, do neither read nor write! Set the counter of runs to 0 then. 

\@addtoreset{figure}{section}% 
\@addtoreset{table}{section}%

\let\LaTeXStandardSection\section%

\newcommand{\StoreCounterValue}[1]{%
  \immediate\expandafter\write\csname #1countsout\endcsname{%
    \number\value{#1}%
  }%
}%

\newcommand{\writesectionnametofile}[4]{%
  \int_compare:nNnT {\csname lastsection#4\endcsname} > {\c_zero }
  {   \bool_if:NTF \g_isappendix_bool {%
      \bool_if:cT { g_appendixin#1_bool } {%
        \addtocontents{#1}{\contentsline{#2}{#3}{}}%
      }%    
    }{%
      \addtocontents{#1}{\contentsline{#2}{#3}{}}%
    }%
  }%
}

\RenewDocumentCommand{\section}{som}{%
  \IfBooleanTF{#1}{%
    \LaTeXStandardSection*{#3}%
  }{% No starred section 
    \IfValueTF{#2}{%
      \edef\@@tempashortsectionname{#2}%
    }{%
      \edef\@@tempashortsectionname{#3}%      
    }%
    \bool_if:NT \g_sectionsinloft_bool {%
      \FloatBarrier%
      \gdef\lastsectionfigures{0}%
      \gdef\lastsectiontables{0}%
      \ifnum\value{localnumberofruns} = \secfig@@writecounterstage
      \gdef\lastsectionfigures{\number\value{figure}}%
      \gdef\lastsectionfigures{\number\value{table}}%
      \ifnum\value{totalsections} > \z@
      \StoreCounterValue{figure}%
      \StoreCounterValue{table}%
      \fi
      \else
      \LoadAllStoredCounterValues{localnumberofruns}%
      \fi
    }%
    % \phantomsection Use here if hyperref is needed
    \LaTeXStandardSection[\@@tempashortsectionname]{#3}%
    \bool_if:NT \g_sectionsinloft_bool {%
      \ifnum\value{localnumberofruns} = \secfig@@writecontentstage % Only make an entry in stages >= 2
      % Generalize for other tocs as well later on using a \seq_... variable
      \writesectionnametofile{lof}{section}{\@@tempashortsectionname}{figures}%  
      \writesectionnametofile{lot}{section}{\@@tempashortsectionname}{tables}%
      \fi
    }% End of \bool_if:NT 
  }%
}


\newcommand{\LoadAllStoredCounterValues}[1]{%
  \ifnum\value{#1} = \secfig@@readcounterstage
  \read\figurecountsin to \lastsectionfigures%
  \read\tablecountsin  to \lastsectiontables%
  \fi
}%

\AtBeginDocument{%
  \bool_if:NT \g_sectionsinloft_bool {%
    \typeout{Previous Stage  \number\value{localnumberofruns}}%
    \stepcounter{localnumberofruns}%
    \typeout{Current Stage is now \number\value{localnumberofruns}}%
    \ifnum\value{localnumberofruns} = \secfig@@writecounterstage
    \immediate\openout\figurecountsout=\jobname.figcount
    \immediate\openout\tablecountsout=\jobname.tabcount
    \else
    \openin\figurecountsin=\jobname.figcount%
    \openin\tablecountsin=\jobname.tabcount%
    \fi
  }%
}%



\AtEndDocument{%
  \bool_if:NT \g_sectionsinloft_bool {%
%  \ifsectionsinloft
    \ifnum\value{localnumberofruns} = \secfig@@resetstage
    \setcounter{localnumberofruns}{\secfig@@voidstage} % Reset counters afterwards. 
    \fi
    \immediate\write\@auxout{%
      \string\setcounter{localnumberofruns}{\number\value{localnumberofruns}}
    }
    % Write the last figure counter value to the file!
    \ifnum\value{localnumberofruns} = \secfig@@writecounterstage
    \StoreCounterValue{figure}%
    \StoreCounterValue{table}%
    \immediate\closeout\figurecountsout%
    \immediate\closeout\tablecountsout%
    \fi
    \immediate\closein\figurecountsin% Close input file 
    \immediate\closein\tablecountsin% Close input file 
  }%
}%

\ExplSyntaxOff


\makeatother    


\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}%
\renewcommand{\thetable}{\arabic{section}.\arabic{table}}%

\EnableSectionsInLOFT
\begin{document}
\tableofcontents%
\listoffigures 
\listoftables
\clearpage

\section{First}
\blindtext

\begin{figure}[!ht]
\begin{center}
  \includegraphics[scale=1]{somefig}%
  \caption{First}
\end{center}
\end{figure}

\begin{figure}
\begin{center}
  \includegraphics[scale=1]{somefig}%
  \caption{Second}
\end{center}
\end{figure}

\begin{table}
\begin{tabular}{ccc}
a & small & table  \tabularnewline
\end{tabular}
\caption[Small Table]{First small table}
\end{table}

\section{Second}

\begin{figure}
  \caption{Third}
\end{figure}

\begin{figure}
  \caption{Fourth}
\end{figure}

\begin{figure}
  \caption{Fifth}
\end{figure}

\begin{figure}
  \caption{Sixth}%
\end{figure}


\section{Without figures}

\section[One with another title]{A very long, long, long section title}


\begin{figure}
  \caption{Seventh}
\end{figure}

\begin{figure}
  \caption[Eight]{Eight Section}%
\end{figure}


\section{Another section without figures}%

\blindtext

\section[Yippie]{Last one}%

\begin{table}
  \caption{dummy table}%
\end{table}

\appendix

\captionsetup{list=no}

\section{First Appendix Section}

\begin{figure}
  \caption{Appendix Figure}
\end{figure}

\begin{table}
  \caption[]{dummy table in appendix}
\end{table}

\section{Second Appendix Section}

\begin{figure}
  \caption{Appendix Figure Nr. 2}
\end{figure}

\begin{table}
  \caption{Dummy table in appendix }
\end{table}


\end{document}

下一次迭代

\documentclass[paper=a4,12pt]{article}%

\usepackage[demo]{graphicx}%

\usepackage{blindtext}
\usepackage{caption}
\usepackage{placeins}
\usepackage{xassoccnt}
\usepackage{xparse}

\makeatletter


\ExplSyntaxOn

\bool_new:N \g_sectionsinloft_bool
\bool_new:N \g_isappendix_bool
\bool_new:N \g_appendixinlof_bool
\bool_new:N \g_appendixinlot_bool


\iow_new:N \l_figurecounts_out_stream
\iow_new:N \l_tablecounts_out_stream

\ior_new:N \l_figurecounts_in_stream
\ior_new:N \l_tablecounts_in_stream

\int_new:N \l_lastfigures_int
\int_new:N \l_lasttables_int


% The number of runs...
\DeclareDocumentCounter{localnumberofruns}%

\newcommand{\secfig@@voidstage}{0}%
\newcommand{\secfig@@writecounterstage}{1}%
\newcommand{\secfig@@readcounterstage}{2}%
\newcommand{\secfig@@writecontentstage}{2}%
\newcommand{\secfig@@resetstage}{3}%

\newlength{\loftsectionbeforeskipamount}%
\newlength{\loftsectionafterskipamount}%
\setlength{\loftsectionafterskipamount}{\medskipamount}%
\setlength{\loftsectionbeforeskipamount}{\medskipamount}%

\newcommand{\loftsectionbeforeskip}{\vspace{\loftsectionbeforeskipamount}}%
\newcommand{\loftsectionafterskip}{\vspace{\loftsectionafterskipamount}}%


% Some wrappers

\newcommand{\EnableSectionsInLOFT}{%
  \bool_gset_true:N \g_sectionsinloft_bool
}%

\newcommand{\DisableSectionsInLOFT}{%
  \bool_gset_false:N \g_sectionsinloft_bool
}%

\newcommand{\EnableAppendixSectionInLOF}{%
  \bool_gset_true:N \g_appendixinlof_bool
}%

\newcommand{\DisableAppendixSectionInLOF}{%
  \bool_gset_false:N \g_appendixinlof_bool
}%

\newcommand{\EnableAppendixSectionInLOT}{%
  \bool_gset_true:N \g_appendixinlot_bool
}%

\newcommand{\DisableAppendixSectionInLOT}{%
  \bool_gset_false:N \g_appendixinlot_bool
}%

\newcommand{\EnableAppendixLOFT}{%
  \EnableAppendixSectionInLOF%
  \EnableAppendixSectionInLOT%
}%


\newcommand{\DisableAppendixLOFT}{%
  \DisableAppendixSectionInLOF%
  \DisableAppendixSectionInLOT%
}%


\let\latex@@appendix\appendix

\renewcommand{\appendix}{%
  \bool_gset_true:N \g_isappendix_bool%
  \latex@@appendix%
  \DisableAppendixLOFT%
}


% Needed for correct number of sections
\DeclareDocumentCounter{totalsections}
\DeclareAssociatedCounters{section}{totalsections}%

% localnumberofruns = 1 --> write figcount file --> no adding to lof
% localnumberofruns = 2 --> Read  fig counters file and decide if a section entry is to be done
% localnumberofruns = 3 --> Last update run to the toc, do neither read nor write! Set the counter of runs to 0 then. 

\@addtoreset{figure}{section}% 
\@addtoreset{table}{section}%



\let\LaTeXStandardSection\section%

\newcommand{\StoreCounterValue}[1]{%
  % Write expanded to stream
  \iow_now:cx {l_#1counts_out_stream} {\number\value{#1}}
}%


\newcommand{\writesectionnametofile}[4]{%
  \int_compare:nNnT {\int_use:c{l_last#4_int}} > {\c_zero }
  {   \bool_if:NTF \g_isappendix_bool {%
      \bool_if:cT { g_appendixin#1_bool } {%
        \addtocontents{#1}{\contentsline{#2}{#3}{}}%
      }%    
    }{%
      \addtocontents{#1}{\contentsline{#2}{#3}{}}%
    }%
  }%
}

\RenewDocumentCommand{\section}{som}{%
  \IfBooleanTF{#1}{%
    \LaTeXStandardSection*{#3}%
  }{% No starred section 
    \IfValueTF{#2}{%
      \edef\@@tempashortsectionname{#2}%
    }{%
      \edef\@@tempashortsectionname{#3}%      
    }%
    \bool_if:NT \g_sectionsinloft_bool {%
      \FloatBarrier%
      \int_zero:N \l_lastfigures_int
      \int_zero:N \l_lasttables_int
      \int_compare:nNnTF{\number\value{localnumberofruns}} = {\secfig@@writecounterstage} {% Only make an entry in stages >= 2
        \int_set:Nn \l_lastfigures_int {\number\value{figure}}
        \int_set:Nn \l_lasttables_int {\number\value{table}}
        \int_compare:nNnT {\number\value{totalsections} } > {\c_zero } {
          \StoreCounterValue{figure}%
          \StoreCounterValue{table}%
        }%
      }{%
        \LoadAllStoredCounterValues{localnumberofruns}%
      }%
    }%
    % \phantomsection Use here if hyperref is needed
    \LaTeXStandardSection[\@@tempashortsectionname]{#3}%
    \bool_if:NT \g_sectionsinloft_bool {%
      \int_compare:nNnT{\number\value{localnumberofruns}} = {\secfig@@writecontentstage} {% Only make an entry in stages >= 2
        % Generalize for other tocs as well later on using a \seq_... variable
        \writesectionnametofile{lof}{section}{\@@tempashortsectionname}{figures}%  
        \writesectionnametofile{lot}{section}{\@@tempashortsectionname}{tables}%
      }% End of \int_compare:nNnT
    }% End of \bool_if:NT 
  }%
}


\newcommand{\LoadAllStoredCounterValues}[1]{%
  \int_compare:nNnT {\value{#1}} = { \secfig@@readcounterstage }
  {
    \ior_get_str:NN \l_figurecounts_in_stream \l_tmpa_tl
    \ior_get_str:NN \l_tablecounts_in_stream \l_tmpb_tl
    \int_set:Nn \l_lastfigures_int {\tl_use:N \l_tmpa_tl}
    \int_set:Nn \l_lasttables_int {\tl_use:N \l_tmpb_tl}
  }
}%


\AtBeginDocument{%
  \bool_if:NT \g_sectionsinloft_bool {%
    \typeout{Previous~Stage~\number\value{localnumberofruns}}%
    \stepcounter{localnumberofruns}%
    \typeout{Current~Stage~is~now~\number\value{localnumberofruns}}%
    \int_compare:nNnT {\number\value{localnumberofruns}} = {\secfig@@writecounterstage} {%
      \iow_open:Nn \l_figurecounts_out_stream {\jobname.figcount}
      \iow_open:Nn \l_tablecounts_out_stream {\jobname.tabcount}
    }{%
      \ior_open:Nn \l_figurecounts_in_stream {\jobname.figcount}
      \ior_open:Nn \l_tablecounts_in_stream {\jobname.tabcount}
    }%
  }%
}%




\AtEndDocument{%
  \bool_if:NT \g_sectionsinloft_bool {%
    \int_compare:nNnT {\number\value{localnumberofruns}} = {\secfig@@resetstage} {%
      \setcounter{localnumberofruns}{\secfig@@voidstage} % Reset counters afterwards. 
    }   
    \immediate\write\@auxout{%
      \string\setcounter{localnumberofruns}{\number\value{localnumberofruns}} % Not expl3 yet
    }
    % Write the last figure counter value to the file!
    \int_compare:nNnT {\number\value{localnumberofruns}} = {\secfig@@writecounterstage} {%
      \StoreCounterValue{figure}%
      \StoreCounterValue{table}%
      \iow_close:N \l_figurecounts_out_stream
      \iow_close:N \l_tablecounts_out_stream
    }
    % Close the in - streams
    \ior_close:N \l_figurecounts_in_stream
    \ior_close:N \l_tablecounts_in_stream
  }%
}%

\ExplSyntaxOff


\makeatother    

% Perhaps use `chngcntr` rather...

\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}%
\renewcommand{\thetable}{\arabic{section}.\arabic{table}}%

\EnableSectionsInLOFT
\begin{document}
\tableofcontents%
\listoffigures 
\listoftables
\clearpage

\section{First}
\blindtext

\begin{figure}[!ht]
\begin{center}
  \includegraphics[scale=1]{somefig}%
  \caption{First}
\end{center}
\end{figure}

\begin{figure}
\begin{center}
  \includegraphics[scale=1]{somefig}%
  \caption{Second}
\end{center}
\end{figure}

\begin{table}
\begin{tabular}{ccc}
a & small & table  \tabularnewline
\end{tabular}
\caption[Small Table]{First small table}
\end{table}

\section{Second}

\begin{figure}
  \caption{Third}
\end{figure}

\begin{figure}
  \caption{Fourth}
\end{figure}

\begin{figure}
  \caption{Fifth}
\end{figure}

\begin{figure}
  \caption{Sixth}%
\end{figure}


\section{Without figures}

\section[One with another title]{A very long, long, long section title}


\begin{figure}
  \caption{Seventh}
\end{figure}

\begin{figure}
  \caption[Eight]{Eight Section}%
\end{figure}


\section{Another section without figures}%

\blindtext

\section[Yippie]{Last one}%

\begin{table}
  \caption{dummy table}%
\end{table}

\appendix

\captionsetup{list=no}

\section{First Appendix Section}

\begin{figure}
  \caption{Appendix Figure}
\end{figure}

\begin{table}
  \caption[]{dummy table in appendix}
\end{table}

\section{Second Appendix Section}

\begin{figure}
  \caption{Appendix Figure Nr. 2}
\end{figure}

\begin{table}
  \caption{Dummy table in appendix }
\end{table}


\end{document}

相关内容