為文檔類別建立靜態標題

為文檔類別建立靜態標題

我正在 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

是的。類似的事情。

我瀏覽了您的個人資料,發現您可能有興趣編寫自己的類別或套件,以便每當您使用您的類別或套件時,您的標頭都會自動載入。我可以看出你的問題來自哪裡。您可能想要減少鍵入標題的時間,例如您每次想要進行考試或類似內容時發布的標題(可能是您的學校考卷範本或類似內容)。

您有多種選擇可以做到這一點,我列出了兩個。

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}

以下是我發布的第二堂課的輸出。您可以調整尺寸以滿足您的需要,但想法就在那裡。

在此輸入影像描述

相關內容