파일에 테이블이 있는지 어떻게 감지하나요?

파일에 테이블이 있는지 어떻게 감지하나요?

저는 대학 논문을 위한 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 파일을 삭제하는 습관이 있는 경우 부동 소수점의 존재 여부를 자동 감지하는 기능이 엉망이 될 수 있습니다. (이러한 집착이 얼마나 흔한지 놀라실 것입니다...) 따라서 저는 여러분에게 다른 접근 방식을 제안하고 싶습니다. 세 가지 문서 클래스 수준 옵션인 , nofiguresnotables를 제공하여 noalgorithms사용자가 직접 지정하도록 하십시오. 이러한 옵션을 지정하면 그림 목록, 테이블 목록, 알고리즘 목록이 각각 생성되지 않습니다.

다음 코드는 이 제안을 더 자세히 보여줍니다. myclass.cls새 옵션을 설정한 다음 클래스를 호출하는 문서 클래스 파일(더 상상력이 풍부한 이름을 자유롭게 선택할 수 있습니다!) report과 문서 클래스를 .tex사용하는 샘플 사용자 파일을 모두 설정합니다 myclass.

\nofigures부록: @Werner의 제안에 따라 세 가지 사용자 수준 매크로 인 \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, notables및 -- 이 모두 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}

관련 정보