Список НЕ показанных рисунков

Список НЕ показанных рисунков

Всякий раз, когда я использую следующий код

 \appendix
 \addcontentsline{toc}{chapter}{9 \enspace Appendices}
 \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}

чтобы избежать перечисления отдельных приложений в оглавлении, список рисунков (lof) исчезает. Я проверил, удалив указанную выше команду из приложения, lof появляется.

решение1

Вам необходимо восстановить tocdepthсчетчик после добавления с помощью \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}:

\documentclass{report}

\begin{document}
\tableofcontents
\listoffigures

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

\appendix
\addcontentsline{toc}{chapter}{9 \enspace Appendices}
\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\chapter{Appendix chapter that is not listed in the TOC}
...
%<end of appendix>
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\end{document}

Предположим, что приложение находится в самом конце вашего документа (что можетнетесли так, будьте осторожны) вы можете исправить конец документа следующим образом

\let\oldenddocument\enddocument
\def\enddocument{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
  \oldenddocument}

Затем файл

\documentclass{report}

\makeatletter
\g@addto@macro\appendix{%
  \addcontentsline{toc}{chapter}{9 \enspace Appendices}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}}
\let\ltx@enddocument\enddocument
\def\enddocument{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
  \ltx@enddocument}
\makeatother

\begin{document}
\tableofcontents
\listoffigures

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

\appendix
\chapter{Appendix chapter that is not listed in the TOC}
\end{document}

вернет тот же результат, что и выше. Обратите внимание, что также выполняется исправление, \appendixчтобы сохранить тело документа чистым:

\g@addto@macro\appendix{%
  \addcontentsline{toc}{chapter}{9 \enspace Appendices}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}}

Это должно быть сделано в любом случае. Наконец, если приложение не является заключительной частью документа, можно рассмотреть возможность обернуть приложение в среду, чтобы иметь маркер конца, следовательно, подходящее место для присоединения (например, с помощью инструкции \def\endappendix{\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}}), а затем сказать

\documentclass{book}

\makeatletter
\g@addto@macro\appendix{%
  \addcontentsline{toc}{chapter}{9 \enspace Appendices}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}}
\def\endappendix{\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}}
\makeatother

\begin{document}
\tableofcontents
\listoffigures

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

\begin{appendix}
\chapter{Appendix chapter that is not listed in the TOC}
...
\end{appendix}

\backmatter
\chapter{After the appendix}
\end{document}

Следует отметить, что это изменение стандартного интерфейса!

Связанный контент