> For the complete documentation index, see [llms.txt](https://ayakaleaf-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://ayakaleaf-pro.ayaka.space/latex/zh-cn/geng-duo-zhu-ti/26-how-to-write-a-latex-class-file-and-design-your-own-cv-part-2.md).

# 如何编写 LaTeX 类文件并设计你自己的简历（第 2 部分）

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

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

这是……的续篇 [如何编写 LaTeX 类文件并设计你自己的简历（第一部分）](/latex/zh-cn/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}       % Customise the \section command
{\Large\scshape\raggedright} % Make the \section headers large (\Large),
                             % small capitals (\scshape) and left aligned (\raggedright)
  {}{0em}            % Can be used to give a prefix to all sections, like 'Section ...'
  {}                 % Can be used to insert code before the heading
  [\titlerule]       % Inserts a horizontal line after the heading
  \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/795dc786dcfbf4ea9e38f0f85f9bad94b43103c5)

该 `#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/ffc93b64000522d02a53822b1b4d535e233cb08b)

这会以良好格式显示联系信息，中间用项目符号分隔。如有需要，可通过添加第二个函数来适配更长的地址：

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

![Screenshot3.png](/files/bd14abb7d5d1fa79332638f3d779f148077fa924)

在信息较短时看起来有点奇怪，但如果地址特别长，这样使用会更灵活。最棒的是，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
{Developed new product}
{Improved productivity by 20\%}
{Decreased costs by \$10,000}
```

现在，经历部分看起来更充实了一些：

![图 4.png](/files/7975cd885bbc3de8e4af4d9e7185e03d7fef7d82)

添加技能部分后，简历就完整了。这一步没有使用类函数，因为它并没有大幅缩短 LaTeX 代码：

```latex
\section{Skills}

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

结果如下：

![图 5.png](/files/4aff4401de1882a77d3682250d056d84e0923dec)

### 结论

这篇分为两部分的文章应该已经为你留下了一个非常基础的简历模板，可随时扩展并添加新部分。

完整的类文件如下：

```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
{Developed new product}
{Improved productivity by 20\%}
{Decreased costs by \$10,000}

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

\end{document}
```

这会得到如下文档：

![图 6.png](/files/e4daca04d511daa2bfac03185169139981d1484b)

本教程应该能为简历提供一个很好的起点，并留有扩展空间。

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


---

# 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://ayakaleaf-pro.ayaka.space/latex/zh-cn/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.
