-
LaTex 中的流程图设计 与 代码块的显示
流程图设计
- 其实这玩意的设计吗,真的不如你用WPS 绘个图,然后直接插入.这个实在是,太难以调整了
\documentclass{article}
\usepackage{CJKutf8}
\usepackage{tikz}
\begin{document}
\begin{CJK}{UTF8}{gbsn} % 设置中文字体
\begin{tikzpicture}[node distance=2cm, every node/.style={rectangle, draw}]
% 定义流程图节点
\node (start) {开始};
\node (process1) [below of=start] {操作};
\node (decision) [below of=process1] {判断};
\node (process2a) [below left of=decision, node distance=3cm] {操作};
\node (process2b) [below right of=decision, node distance=3cm] {操作};
\node (end) [below of=process2a] {结束};
% 连接节点
\draw[->] (start) -- (process1);
\draw[->] (process1) -| (decision);
\draw[->] (decision) -- node[left] {条件} (process2a);
\draw[->] (decision) -- node[left] {条件} (process2b);
\draw[->] (process2a) -- (end);
\draw[->] (process2b) |- (process1);
\end{tikzpicture}
\end{CJK}
\end{document}
页眉页脚码的设计
- 默认页码:LaTeX默认情况下会自动为每一页的底部中央添加一个页码
自定义页码样式 \pagestyle{}命令
- LaTeX提供了几种内置的页码样式,如plain(默认),headings和empty
- \pagenumbering{}命令
\thispagestyle{} 命令
- 单独设置某一页的页码样式
- 例如,\thispagestyle{empty}可以在某一页上隐藏页码
- 一般用不到就是了
页眉和页脚
\pagestyle{fancy}
\fancyhf{} % 清空当前的页眉页脚设置
\fancyhead[C]{这是页眉 居中} % 居中显示的页眉内容
\fancyhead[L]{这是页眉 居左} % 居左显示的页眉内容
\fancyhead[R]{这是页眉 居右} % 居右显示的页眉内容
\fancyfoot[C]{这是页脚 居中} % 居中显示的页脚内容
\fancyfoot[L]{\thepage } % 居左显示的页脚内容
\fancyfoot[R]{这是页脚 居右} % 居右显示的页脚内容
完整代码
\documentclass{article}
\usepackage{CJKutf8}
\usepackage{fancyhdr}
\usepackage{lipsum}
\begin{document}
\begin{CJK}{UTF8}{gbsn}
\pagestyle{fancy}
\fancyhf{} % 清空当前的页眉页脚设置
\fancyhead[C]{这是页眉 居中} % 居中显示的页眉内容
\fancyhead[L]{这是页眉 居左} % 居左显示的页眉内容
\fancyhead[R]{这是页眉 居右} % 居右显示的页眉内容
\fancyfoot[C]{这是页脚 居中} % 居中显示的页脚内容
\fancyfoot[L]{\thepage } % 居左显示的页脚内容
\fancyfoot[R]{这是页脚 居右} % 居右显示的页脚内容
% 设置标题
\title{LaTeX中设置页眉、页脚和页码示例}
\author{River Chandler}
\date{\today}
\maketitle
% 示例内容
\section{示例}
\lipsum[1-100] % 使用lipsum宏包生成示例文本
\end{CJK}
\end{document}
实际应用案例
- 要求
- 首页
- 页眉左 问题选项
- 页眉中 队伍号
- 页眉右 页码
- 页眉线
- 标题
- 姓名
- 日期
- 仅包含一个summary
- 目录页
- 目录页符合一般目录页要求
- 目录页不计入页码
- 目录页仅包含目录
- 目录页页眉页脚与首页相同
- 正文页
- 正文页页眉页脚要求与首页相同
- 设置每段开头空格
- section subsection 等标题加粗
- 首页
- \usepackage{fancyhdr}: fancyhdr 宏包提供了一种自定义页眉和页脚的方式
- \usepackage{tocloft}: tocloft 宏包允许对目录(table of contents)进行自定义格式设置
- \usepackage{titlesec}: titlesec 宏包提供了一种自定义标题格式的方式
- \usepackage{lipsum}: lipsum 宏包提供了一些虚拟的拉丁文段落(Lorem Ipsum)用于排版测试
- \pagestyle{fancy}:设置页面样式为自定义的"fancy"样式
- \fancyhf{}:清除默认的页眉和页脚设置
- \fancyhead[L]{Problem number}:设置页眉的左侧内容为"Problem number"
- \fancyhead[C]{team number}:设置页眉的中间内容为"team number"
- \fancyhead[R]{\thepage}:设置页眉的右侧内容为当前页数
- \renewcommand{\headrulewidth}{0.4pt}:定义页眉的横线宽度为0.4pt
\documentclass{article}
\usepackage{fancyhdr}
\usepackage{tocloft}
\usepackage{titlesec}
\usepackage{lipsum}
% 设置页眉页脚
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Problem choose}
\fancyhead[C]{team number}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
% 设置标题格式
\titleformat{\section}{\normalfont\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\bfseries}{\thesubsection}{1em}{}
% 设置段落首行缩进
\setlength{\parindent}{2em}
\begin{document}
% 首页
\thispagestyle{fancy}
\pagenumbering{gobble} % 目录页不计入页码
\begin{center}
\textbf{TITLE}
\vspace{1em}
\textbf{Team Number}
\vspace{1em}
\textbf{Problem Choose}
\vspace{3em}
\centering{\textbf{{\fontsize{18}{14}\selectfont
Summary
}}}
\end{center}
\lipsum[1-2]
% 目录页
\newpage
\pagenumbering{gobble} % 目录页不计入页码
\tableofcontents
\thispagestyle{fancy}% 这行代码必须在\tableofcontents 下面
% 正文页
\newpage
\pagenumbering{arabic} % 正文页开始计入页码
\section{frist section}
\lipsum[1-5]
\subsection{frist frist}
\lipsum[1-5]
\section{second section}
\lipsum[1-5]
% 其他章节以此类推
\end{document}
代码块的显示
- listing 宏包
- \usepackage{biblatex} % 导入biblatex宏包
- \usepackage{appendix} % 导入appendix宏包
\begin{lstlisting}
# Python example
def hello_world():
print("Hello, World!")
print("Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!")
hello_world() # call hello_world
\end{lstlisting}
附赠完整模版
\documentclass{article}
\usepackage{fancyhdr}
\usepackage{tocloft}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage{biblatex} % 导入biblatex宏包
\usepackage{appendix} % 导入appendix宏包
\usepackage{listings}
\usepackage{geometry}
% 设置页面布局
\geometry{
left=3cm,
right=3cm,
top=3cm,
bottom=2cm,
}
\lstset{
language=Python,
numbers=left,
frame=single,
breaklines=true,
breakatwhitespace=false,
basicstyle=\small\ttfamily,
showspaces=false, % 显示空格
}
% 设置页眉页脚
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Problem choose}
\fancyhead[C]{team number}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
% 设置标题格式
\titleformat{\section}{\normalfont\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\bfseries}{\thesubsection}{1em}{}
% 设置段落首行缩进
\setlength{\parindent}{2em}
\begin{document}
% 首页
\thispagestyle{fancy}
\pagenumbering{gobble} % 目录页不计入页码
\begin{center}
\textbf{TITLE}
\vspace{1em}
\textbf{Team Number}
\vspace{1em}
\textbf{Problem Choose}
\vspace{3em}
\centering{\textbf{{\fontsize{18}{14}\selectfont
Summary
}}}
\end{center}
\lipsum[1-2]
% 目录页
\newpage
\pagenumbering{gobble} % 目录页不计入页码
\tableofcontents
\thispagestyle{fancy}% 这行代码必须在\tableofcontents 下面
% 正文页
\newpage
\pagenumbering{arabic} % 正文页开始计入页码
\section{frist section}
{\fontsize{12}{14}\selectfont
\lipsum[1-5]\cite{ref1}
}
\subsection{frist frist}
\lipsum[1-5]\cite{ref2}
\section{second section}
\lipsum[1-5]
\newpage
\begin{thebibliography}{9}
\bibitem{ref1} Author A. Title of the paper. Journal name, year.
\bibitem{ref2} Author B. Title of the book. Publisher, year.
\end{thebibliography}
\newpage
\appendix % 标记后续部分为附录
\section*{Appendix}
This is the content of the appendix.
\begin{lstlisting}
# Python example
def hello_world():
print("Hello, World!")
print("Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!","Hello, World!")
hello_world() # call hello_world
\end{lstlisting}
\end{document}