可能重复:
如何根据文档类别配置定理?
我希望在加载书籍类时,以及在加载文章类时执行此操作。我可以使用某种条件来执行此操作吗?
我尝试过,但是失败了。
\makeatletter%
\@ifclassloaded{book}{%
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhead{}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\fancyhead[LE]{\bfseries\leftmark}
\fancyhead[RO]{\bfseries\rightmark}
\fancyfoot{}
\fancyfoot[LE,RO]{\bfseries\thepage}
\fancyfoot[LO,RE]{Régis}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}
\addtolength{\headheight}{0.5pt}
\fancypagestyle{plain}{%
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
}
\typeout{Using book class.}%
}{%
\@ifclassloaded{article}{%
% \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhead{}
% \renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\fancyhead[R]{\bfseries\rightmark}
\fancyfoot{}
\fancyfoot[R]{\bfseries\thepage}
\fancyfoot[L]{Régis}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}
\addtolength{\headheight}{0.5pt}
\fancypagestyle{plain}{%
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
}
\typeout{Using article class.}%
}{%
\@ifclassloaded{report}{%
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhead{}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\fancyhead[L]{\bfseries\leftmark}
\fancyhead[R]{\bfseries\rightmark}
\fancyfoot{}
\fancyfoot[R]{\bfseries\thepage}
\fancyfoot[L]{Régis}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}
\addtolength{\headheight}{0.5pt}
\fancypagestyle{plain}{%
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
}
\typeout{Using report class.}%
}{%
\typeout{Error: Unsupported class: 'article' or 'report' or 'book' are suported.}\QUITHERE
}%
}%
\makeatother%
答案1
这应该可以让你开始。只需将适当的设置添加到BookHeader
、ArticleHead
和ReportHead
。在这三个中,你可以使用#1
来引用传递给 的内容\SetHeaders
。
如果使用书籍、文章或报告以外的类别,则以下内容旨在退出。如果不需要,您可以删除 \QUITHERE 宏。
\documentclass{article}
\newcommand*{\BookHeader}[1]{% Add any customizations for book class here.
\typeout{Using book class.}%
}%
\newcommand*{\ArticleHead}[1]{% Add any customizations for article class here.
\typeout{Using article class.}%
}%
\newcommand*{\ReportHead}[1]{% Add any customizations for report class here.
\typeout{Using report class.}%
}%
\makeatletter%
\newcommand*{\SetHeaders}[1]{%
\@ifclassloaded{book}{\BookHeader{#1}%
}{\@ifclassloaded{article}{\ArticleHead{#1}%
}{\@ifclassloaded{report}{\ReportHead{#1}}{%
\typeout{Error: Unsupported class: 'article' or 'report' or 'book' are suported.}\QUITHERE
}}}%
}%
\makeatother%
\SetHeaders{foo}%
\begin{document}
Testing...
\end{document}