> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-tw/geng-duo-zhu-ti/26-how-to-write-a-latex-class-file-and-design-your-own-cv-part-2.md).

# 如何撰寫 LaTeX 類別檔並設計你自己的 CV（第 2 部分）

[第 1 部分](/latex/zh-tw/geng-duo-zhu-ti/25-how-to-write-a-latex-class-file-and-design-your-own-cv-part-1.md) | 第 2 部分

**作者：Cody Herring（2013 年 6 月）**

這是以下內容的續篇： [如何撰寫 LaTeX 類別檔並設計自己的履歷（第 1 部分）](/latex/zh-tw/geng-duo-zhu-ti/25-how-to-write-a-latex-class-file-and-design-your-own-cv-part-1.md)，將進一步介紹製作履歷的更多選項，並使用類別檔來達成。

在上一篇文章中，我們建立了 2 個檔案： `cv.tex` 和 `my_cv.cls`。內容檔， `cv.tex`，其內容如下：

```latex
\documentclass{my_cv}
\begin{document}
\section{Education}
\datedsubsection{University of Nowhere}{2004-2008}
\section{Work}
\datedsubsection{ABC Limited}{2008-Now}
\end{document}
```

`my_cv.cls` 包含一些格式預設，以及一些可使用的命令：

```latex
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{my_cv}[6/6/2013 custom CV class]
\LoadClass{article}
\RequirePackage{titlesec}
\titleformat{\section}       % 自訂 \section 命令
{\Large\scshape\raggedright} % 讓 \section 標題變大（\Large），
                             % 小型大寫字母（\scshape）並靠左對齊（\raggedright）
  {}{0em}            % 可用來為所有章節加上前綴，例如「Section ...」
  {}                 % 可用來在標題前插入程式碼
  [\titlerule]       % 在標題後插入一條水平線
  \titleformat{\subsection}
  {\large\scshape\raggedright}
  {}{0em}
  {}
\newcommand{\datedsection}[2]{%
  \section[#1]{#1 \hfill #2}%
}
\newcommand{\datedsubsection}[2]{%
  \subsection[#1]{#1 \hfill #2}%
}
```

這會產生以下文件：

![圖 1.png](/files/ff2852858133a97322d64104df5c43f8fae3688b)

該 `#1` 和 `#2` 指的是傳入命令的第一個與第二個引數或參數。在一個 `\newcommand`，括號中的區段，例如： `[2]` 指的是傳入函式的參數數量。接著函式可以透過使用 `#1`, `#2`，以此類推，視函式需要多少參數而定。具有更多參數的函式會在本文後面說明。

接著我們會新增姓名與聯絡資訊區段，並繼續處理經歷及其他區段。

### 姓名與聯絡資訊

在履歷中，姓名通常位於最上方，並附上可供徵才聯絡的資訊。這將透過在類別檔中新增函式來完成。姓名可以用一個簡單的函式加入：

```latex
\newcommand{\name}[1]{%
  \centerline{\Huge{#1}}
}
```

這樣會產生置中、較大字體的姓名，只要在任何地方使用即可。可以像這樣呼叫：

```latex
\name{John Smith}
```

接下來是聯絡資訊。將以下內容加入類別檔：

```latex
\newcommand\contact[5]{%
    \centerline{%
        \makebox[0pt][c]{%
            #1 {\large\textperiodcentered} #2 {\large\textperiodcentered} #3
            \ #4 \ \ #5%
        }%
    }%
}
```

接著在文件中呼叫此函式：

```latex
\contact{123 Broadway}{London}{UK 12345}{john@smith.com}{(000)-111-1111}
```

以上內容都能漂亮地顯示，姓名與聯絡資訊如下：

![圖 2.png](/files/56ee34a78d87cc848871295fcea20deca3972411)

這樣會以良好格式顯示聯絡資訊，中間以項目符號分隔。若地址較長，必要時可透過新增第二個函式來調整：

```latex
\newcommand{\longcontact}[5]{%
    \noindent
    #1\hfill {\large\textperiodcentered}\hfill #2\hfill
    {\large\textperiodcentered}\hfill #3\\
    #4\hfill #5%
}
```

![Screenshot3.png](/files/7bfa09aa78d9339fd03f4d0f8aee54176aeaff1d)

在資訊較短時這樣看起來有點奇怪，但若地址特別長，這種做法就更有彈性。最棒的是，TeX 文件只需要極少的修改：

```latex
\longcontact{123 Broadway}{London}{UK 12345}{john@smith.com}{(000)-111-1111}
```

這正是使用類別檔的重點：讓文件內容只需做最少變更，並在外部控制呈現方式（內容如何顯示）。

### 擴充「經歷」區段

履歷不應只列出工作項目。每個項目下方還應加入對工作內容的描述。每份工作列出 3 個條列點，是細節與說明之間不錯的平衡。這可透過新增或移除節點輕鬆調整。將以下內容加入類別檔：

```latex
\newcommand{\workitems}[3]{%
    \begin{itemize}
    \item #1
    \item #2
    \item #3
    \end{itemize}%
}
```

將以下內容加入 `.tex` 檔案中：

```latex
\workitems
{開發新產品}
{生產力提升 20\%}
{成本降低 10,000 美元}
```

現在經歷區段看起來更完整一些了：

![圖 4.png](/files/c16043963b3586a6ad409cb10e5fc846dcf51bbd)

新增技能區段可讓履歷更完整。這裡沒有使用類別函式，因為它並沒有讓 LaTeX 程式碼縮短太多：

```latex
\section{技能}

\begin{tabular}{l l l l}
C\# & T-SQL & Javascript & HTML \\
XML & JSON & SOAP & REST
\end{tabular}
```

這樣會產生以下內容：

![圖 5.png](/files/4a6692f8262413d0b15081744665dac824f517a0)

### 結論

這篇分成兩部分的文章應該已為你留下了一個非常基本的履歷範本，可隨時擴充並新增區段。

完整的類別檔如下：

```latex
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{my_cv}[6/6/2013 custom CV class]
\LoadClass{article}
\RequirePackage{titlesec}

\titleformat{\section}
  {\Large\scshape\raggedright}
  {}{0em}
  {}
  [\titlerule]

  \titleformat{\subsection}
  {\large\scshape\raggedright}
  {}{0em}
  {}

\newcommand{\datedsection}[2]{%
  \section[#1]{#1 \hfill #2}%
}
\newcommand{\datedsubsection}[2]{%
  \subsection[#1]{#1 \hfill #2}%
}

\newcommand{\name}[1]{%
  \centerline{\Huge{#1}}%
}

\newcommand\contact[5]{%
    \centerline{%
        \makebox[0pt][c]{%
            #1 {\large\textperiodcentered} #2 {\large\textperiodcentered} #3
            \ #4 \ \ #5%
        }%
    }%
}

\newcommand{\longcontact}[5]{%
    \noindent
    #1\hfill {\large\textperiodcentered}\hfill #2\hfill
    {\large\textperiodcentered}\hfill #3\\
    #4\hfill #5%
}

\newcommand{\workitems}[3]{%
    \begin{itemize}
    \item #1
    \item #2
    \item #3
    \end{itemize}%
}
```

該 `.tex` 檔案如下：

```latex
\documentclass{my_cv}
\begin{document}
\name{John Smith}
\contact{123 Broadway}{London}{UK 12345}{john@smith.com}{(000)-111-1111}
\section{Education}
\datedsubsection{University of Nowhere}{2004-2008}
\section{Work}
\datedsubsection{ABC Limited}{2008-Now}
\workitems
{開發新產品}
{生產力提升 20\%}
{成本降低 10,000 美元}

\section{技能}
\begin{tabular}{l l l l}
C\# & T-SQL & Javascript & HTML \\
XML & JSON & SOAP & REST
\end{tabular}

\end{document}
```

這樣會產生以下文件：

![圖 6.png](/files/ec7b52aa93c82d57be38b04d43df3af44a795640)

本教學應可為履歷提供一個很好的起點，並保留擴充空間。

[第 1 部分](/latex/zh-tw/geng-duo-zhu-ti/25-how-to-write-a-latex-class-file-and-design-your-own-cv-part-1.md) | 第 2 部分


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-tw/geng-duo-zhu-ti/26-how-to-write-a-latex-class-file-and-design-your-own-cv-part-2.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
