
私は大学の論文用の LaTeX テンプレートを作成しています。直面している問題は次のとおりです。
ある学生から、論文に表がまったく含まれておらず、表のリストが空になっていると聞きました。私は
\listoftables
その.cls
ファイルを添付し、コメントするように伝えました。しかし、表の存在を検出し、図のリスト、表のリスト、アルゴリズムのリストなどのリストを自動的に無効/有効にするにはどうしたらよいか疑問に思っています。
しばらく検索しましたが、次のようなオプションをドキュメント クラスに追加する以外に解決策は見つかりませんでした。
\newif\if@alg\@algfalse
\DeclareOption{alg}{
\@algtrue
}
\ProcessOptions\relax
\if@alg
\RequirePackage{algorithmicx}
\RequirePackage{algorithm}
\RequirePackage{algpseudocode}
\renewcommand{\thealgorithm}{\arabic{chapter}.\arabic{algorithm}}
\fi
\if@alg
\listofalgorithms
\cleardoublepage
\newpage
\fi
答え1
ユーザーが aux ファイルを強迫的に削除する習慣がある場合、フロートの有無の自動検出がうまくいかない可能性があります。(この強迫観念がどれほど一般的であるかに驚かれるでしょう...) したがって、別のアプローチを取ることをお勧めします。つまり、ユーザー自身が指定する 、、nofigures
という3 つのドキュメントクラス レベルのオプションを提供します。これらのオプションが指定されると、それぞれ図のリスト、表のリスト、アルゴリズムのリストは生成されません。notables
noalgorithms
次のコードで、この提案をより詳しく説明します。このコードでは、新しいオプションを設定してクラスを呼び出す というドキュメント クラス ファイル (もちろん、もっと想像力豊かな名前を選択することもできます) と、ドキュメント クラスを使用するサンプル ユーザー ファイルの両方myclass.cls
を設定します。report
.tex
myclass
追記: @Werner の提案により、3つのユーザーレベルマクロのコードを追加しました: \nofigures
、、\notables
および。これらは、対応するオプションをステージ\noalgorithms
で提供する代わりに、ユーザーがプリアンブルに挿入することができます。\documentclass
まず、クラス ファイルのコード (として保存されますmyclass.cls
) :
\NeedsTeXFormat{LaTeX2e}[2015/01/01]
\ProvidesClass{myclass}[2018/02/21]
% define three new documentclass-level options
\newif\ifnofigures\nofiguresfalse
\newif\ifnotables\notablesfalse
\newif\ifnoalgorithms\noalgorithmsfalse
\DeclareOption{nofigures}{\nofigurestrue}
\DeclareOption{notables}{\notablestrue}
\DeclareOption{noalgorithms}{\noalgorithmstrue}
\ProcessOptions\relax
\LoadClass[]{report}
% provide three user commands: \nofigures, \notables, \noalgorithms
% (to be used as an alternative to setting documentclass-level options)
\newcommand\nofigures{\let\ifnofigures\iftrue}
\newcommand\notables{\let\ifnotables\iftrue}
\newcommand\noalgorithms{\let\ifnoalgorithms\iftrue}
\usepackage{algorithmicx,algorithm,algpseudocode}
% load any and all other default packages
\AtBeginDocument{%
\pagenumbering{roman}
\maketitle % or, likely, something far more elaborate
\ifnofigures\else\listoffigures\fi
\ifnotables\else\listoftables\fi
\ifnoalgorithms\else\listofalgorithms\fi
\clearpage
\pagenumbering{arabic}
}
nofigures
2 番目は、サンプルのユーザー ドキュメントです。新しいドキュメント クラス オプション ( 、、notables
および)の 3 つすべてnoalgorithms
を指定すると、図、表、およびアルゴリズムのリストは作成されないことに注意してください。
\documentclass[nofigures,notables,noalgorithms]{myclass}
\title{Thoughts}
\author{A. Person}
\date{\today}
\begin{document}
xxx
\end{document}
答え2
totalcountパッケージを使うこともできます。ただし、三つ表や図のリストを取得するためのコンパイル。
\documentclass{book}
\RequirePackage[figure,table]{totalcount}
\begin{document}
\iftotaltables
\listoftables %no list of tables
\fi
\iftotalfigures
\listoffigures
\fi
\chapter{A}
\begin{figure}
\caption{a figure}
\end{figure}
\chapter{B}
blblb
\end{document}