
私は LaTeX で独自のドキュメント クラスを作成していますが、クラスが使用されたときにこのタイトルを自動的に表示するにはどうすればよいかという問題があります。
このようにコーディングすべきでしょうか?
\AtBeginDocument{%
\vspace*{-0.4in}\noindent
{\Large\bfseries School name here} \\
{\large\sffamily college name here} \\[0.2in]
{\Large\sffamily department name here} \\[0.2in]
{\Large\sffamily Subjectcode, subject name here} \\[0.2in]
{\Large\sffamily school year here} \\[0.2in]
\vspace{0.2in}
}
答え1
はい。そんな感じです。
あなたのプロフィールを閲覧したところ、独自のクラスまたはパッケージを作成して、そのクラスまたはパッケージを使用するたびにヘッダーが自動的に読み込まれるようにすることに興味があるかもしれないことがわかりました。問題の原因はわかります。試験などを作成するときに、投稿したようなヘッダーを入力する時間を短縮したいのかもしれません (学校のテスト用紙のテンプレートなど)。
これを行うにはいくつかのオプションがあり、ここでは 2 つを挙げます。
1. 頻繁に使用するコードをすべて別のファイルに保存し、コピーそしてペースト必要に応じて。
2. パッケージまたはクラスファイルを作成するすでにいくつかの助けが与えられていますが、私はまた、投稿を紹介したいと思いますスタイル/クラスチュートリアル関連する質問もあります\documentclass{letter}に画像ヘッダーを配置する。
オプション2と、ここに投稿したリンクにあるリンクを使用して、独自のドキュメントクラスを作成しました。自動化する最初のページに学校のヘッダーを含め、クラスの試験と学校のメモ用の他のページにはヘッダーを含めません。特定の問題に対しては、次の内容のクラス ファイルを作成できます。
ヘッダーを変更せずに、ヘッダーを単に最初のページに表示したい場合は、次のようにします。
\ProvidesClass{myclass}[2012/09/03 version 0.01 My exam class] \NeedsTeXFormat{LaTeX2e}[1996/06/01]% \PassOptionsToClass{\CurrentOption}{article} \ProcessOptions \relax \LoadClass{article} \RequirePackage[margin=1in]{geometry} \AtBeginDocument{ \begin{center} \sffamily {\Large\textbf{School Name}} {\large\textbf{Name of College}}\\ {\large Name of Department}\\ {\large Subject code, subject name}\\ {\large SY 2012-2013} \end{center} \noindent Name: \makebox[3in]{\hrulefill} \hfill Section: \makebox[2in]{\hrulefill}\\ } \endinput
上部の余白を使用してスペースを節約したい場合は、次のようにします。
\ProvidesClass{myclass}[2012/09/03 version 0.01 My exam class] \NeedsTeXFormat{LaTeX2e}[1996/06/01]% \PassOptionsToClass{\CurrentOption}{article} \ProcessOptions \relax \LoadClass{article} \RequirePackage[margin=1in]{geometry} \RequirePackage{fancyhdr} %% This sets the header of the first page of the letter \fancypagestyle{firstpage}{% \fancyhf{} % clear all six fields \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt} \fancyhead[C]{ \parbox[t][]{4in}{ \centering \sffamily {\Large\textbf{School Name}}\\ {\large\textbf{Name of College}}\\ {\large Name of Department}\\ {\large Subject code, subject name}\\ {\large SY 2012-2013} }} } \fancypagestyle{followingpage}{% \fancyhf{} % clear all six fields \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt} } \pagestyle{followingpage} % followingpage is the default page style \AtBeginDocument{\thispagestyle{firstpage} % the page style on the first page \geometry{headheight=1in,headsep=0.1in} \noindent Name: \makebox[3in]{\hrulefill} \hfill Section: \makebox[2in]{\hrulefill}\\ } \endinput
更新: 9月4日。以下は、私がここに投稿したクラスをテストするための MWE です。
\documentclass{myclass}
\usepackage{lipsum}
\begin{document}
\lipsum[1-20]
\end{document}
以下は、私が投稿した 2 番目のクラスの出力です。サイズは必要に応じて調整できますが、アイデアはそのままです。