> 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-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) | 第2部分

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

这是以下内容的续篇 [如何编写 LaTeX 类文件并设计你自己的简历（第1部分）](/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{教育}
\datedsubsection{University of Nowhere}{2004-2008}
\section{工作}
\datedsubsection{ABC Limited}{2008-Now}
\end{document}
```

`my_cv.cls` 包含一些格式默认设置，以及一些可使用的命令：

```latex
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{my_cv}[6/6/2013 自定义 CV 类]
\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/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
{开发了新产品}
{生产效率提高了 20\%}
{成本减少了 \$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 自定义 CV 类]
\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{教育}
\datedsubsection{University of Nowhere}{2004-2008}
\section{工作}
\datedsubsection{ABC Limited}{2008-Now}
\workitems
{开发了新产品}
{生产效率提高了 20\%}
{成本减少了 \$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) | 第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-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.
