本文主要是介绍LaTeX入门——制作一份朴实无华的pdf文档,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- 作者、标题、日期
- 章节和段落
- 插入目录
- 枚举
- 插入图片
- 表格
- 排版
- 插入代码块
- 数学公式
- 树形图
- 页边距
作者、标题、日期
文章部分开头\begin{document}
,结尾\end{document}
。
\documentclass[UTF8]{ctexart}
\title{你好,world!}
\author{Liam}
\date{\today}
\begin{document}
\maketitle
你好,world!
\end{document}
排版示例:
章节和段落
\maketitle
后面加文字:出现在文章最上方。
\section{你好中国}
第一个大部分,后面加文字,解释说明用。(1)
\subsection{Hello Beijing}
(1.1)
\subsubsection{Hello Dongcheng District}
(1.1.1)
\paragraph{Tian'anmen Square}
, \subparagraph{Chairman Mao}
针对每个section分段。
\documentclass[UTF8]{ctexart}
\title{你好,world!}
\author{Liam}
\date{\today}
\begin{document}
\maketitle
\section{你好中国}
中国在 East Asia.
\subsection{Hello Beijing}
北京是 capital of China.
\subsubsection{Hello Dongcheng District}
\paragraph{Tian'anmen Square}
is in the center of Beijing
\subparagraph{Chairman Mao}
is in the center of 天安门广场。
\subsection{Hello 山东}
\paragraph{山东大学} is one of the best university in 山东。
\end{document}
排版示例:
插入目录
在\maketitle
后加入\tableofcontents
自动生成目录。
排版示例:
枚举
```cpp
\begin{itemize}%圆点 罗列
\item 我的第一个项目
\item 我的第二个项目
\item 我的第三个项目
\end{itemize}\begin{enumerate}%带有数字标号的罗列
\item 我的第一个项目
\item 我的第二个项目
\item 我的第三个项目
\end{enumerate}\begin{description}%不带任何符号的罗列
\item 我的第一个项目
\item 我的第二个项目
\item 我的第三个项目
\end{description}
插入图片
在导言部分加入:
注意:引言区就是指的从\documentclass 开始到\begin[document]的这个部分的区域。
\usepackage{graphicx}
- 在文档中插入a.jpg文件。
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{a.jpg}
\end{document}
注意:如何插入图片呢?首先将编写的tex文件放入文件夹中,再将用到的图片同样导入文件夹中,这样就可以使用该图片了。
- 浮动体(更常用)
\centering
表示的是里面紧跟的内容都居中
\includegraphics[]{}
表示的插入图片
\caption
设置图片的一个编号以及为图片添加标题
\begin{figure}[ht]
\centering
\includegraphics[scale=0.6]{fullscreen.png}
\caption{this is a figure demo}
\label{fig:label}
\end{figure}
-------------------------------------注 h 此处(here)t 页顶(top)b 页底(bottom)p 独立一页(page)
--------------------------------------
- 多图并排
设置库:
\ifCLASSOPTIONcompsoc
\usepackage[caption=false,font=normalsize,labelfon
t=sf,textfont=sf]{subfig}
\else
\usepackage[caption=false,font=footnotesize]{subfig}
\fi
设置图片:
\begin{figure*}[!t]
\centering
\subfloat[]{\includegraphics[width=2.5in]{luna.jpg}%
\label{fig_first_case}}
\hfil
\subfloat[]{\includegraphics[width=2.5in]{luna.jpg}%
\label{fig_second_case}}
\hfil
\subfloat[]{\includegraphics[width=2.5in]{luna.jpg}%
\label{fig_third_case}}
\hfil
\subfloat[]{\includegraphics[width=2.5in]{luna.jpg}%
\label{fig_forth_case}}
\caption{Simulation results for the network.}
\label{fig_sim}
\end{figure*}
表格
使用\begin{tabular}{|l|c|r|}
和 \end{tabular}
建立表格。
\hline
分割线。
&
列结束。
\\
行结束。
\begin{tabular}{|l|c|r|}\hline
操作系统& 发行版& 编辑器\\\hline
Windows & MikTeX & TexMakerX \\\hline
Unix/Linux & teTeX & Kile \\\hline
Mac OS & MacTeX & TeXShop \\\hline
通用& TeX Live & TeXworks \\\hline
\end{tabular}
排版
段尾加 \\
,表示换行。
段尾不加 \\
,直接空一行再输入,表示换行并且段首空格。
插入代码块
无高亮
插入如下格式:
\usepackage{listings}
\usepackage{xcolor}%代码设置
\lstset{numbers=left, %设置行号位置numberstyle=\tiny, %设置行号大小keywordstyle=\color{blue}, %设置关键字颜色commentstyle=\color[cmyk]{1,0,1,0}, %设置注释颜色escapeinside=``, %逃逸字符(1左面的键),用于显示中文breaklines, %自动折行extendedchars=false, %解决代码跨页时,章节标题,页眉等汉字不显示的问题xleftmargin=1em,xrightmargin=1em, aboveskip=1em, %设置边距tabsize=4, %设置tab空格数showspaces=false %不显示空格}\begin{lstlisting}[language=R]
> matrix(1:12,nrow=3,ncol=4)[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
\end{lstlisting}
示例:
数学公式
行内$xx$
,单独公式$$xxx$$
1.方程组:
F(n)=
\begin{cases}
1 & \text{n=0 or n=1}\\
F(n-1)+F(n-2) & \text{n>1}
\end{cases}
F ( n ) = { 1 n=0 or n=1 F ( n − 1 ) + F ( n − 2 ) n>1 F(n)= \begin{cases} 1 & \text{n=0 or n=1}\\ F(n-1)+F(n-2) & \text{n>1} \end{cases} F(n)={1F(n−1)+F(n−2)n=0 or n=1n>1
2.矩阵
\left\{
\begin{matrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{matrix}
\right\} \tag{2}
{ 1 2 3 4 5 6 7 8 9 } (2) \left\{ \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right\} \tag{2} ⎩⎨⎧147258369⎭⎬⎫(2)
树形图
找了一些实用模板。
- 普通树状图
\documentclass[border=10pt]{standalone} \usepackage{verbatim}\begin{comment}
:Title: A simple Tree
\end{comment}\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[sibling distance=10em,every node/.style = {shape=rectangle, rounded corners,draw, align=center,top color=white, bottom color=blue!20}]]\node {Formulas}child { node {single-line} }child { node {multi-line}child { node {aligned at}child { node {relation sign} }child { node {several places} }child { node {center} } }child { node {first left,\\centered,\\last right} } };
\end{tikzpicture}
\end{document}
2. 决策树
\documentclass[border=10pt]{standalone}
\usepackage{verbatim}\begin{comment}
:Title: Decision tree\end{comment}
\usepackage{tikz}
\tikzset{treenode/.style = {shape=rectangle, rounded corners,draw, align=center,top color=white, bottom color=blue!20},root/.style = {treenode, font=\Large, bottom color=red!30},env/.style = {treenode, font=\ttfamily\normalsize},dummy/.style = {circle,draw}
}
\begin{document}\begin{tikzpicture}[grow = right,sibling distance = 6em,level distance = 10em,edge from parent/.style = {draw, -latex},every node/.style = {font=\footnotesize},sloped]\node [root] {Formula}child { node [env] {equation}edge from parent node [below] {single-line?} }child { node [dummy] {}child { node [dummy] {}child { node [env] {align\\flalign}edge from parent node [below] {at relation sign?} }child { node [env] {alignat}edge from parent node [above] {at several}node [below] {places?} }child { node [env] {gather}edge from parent node [above] {centered?} }edge from parent node [below] {aligned?} }child { node [env] {multline}edge from parent node [above, align=center]{first left,\\centered,}node [below] {last right}}edge from parent node [above] {multi-line?} };\end{tikzpicture}
\end{document}
3. 文件树
\documentclass{minimal}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\begin{comment}
:Title: Filesystem tree
\end{comment}
\usetikzlibrary{trees}
\begin{document}\tikzstyle{every node}=[draw=black,thick,anchor=west]\tikzstyle{selected}=[draw=red,fill=red!30]\tikzstyle{optional}=[dashed,fill=gray!50]\begin{tikzpicture}[%grow via three points={one child at (0.5,-0.7) andtwo children at (0.5,-0.7) and (0.5,-1.4)},edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}]\node {texmf}child { node {doc}} child { node {fonts}}child { node {source}}child { node [selected] {tex}child { node {generic}}child { node [optional] {latex}}child { node {plain}}}child [missing] {} child [missing] {} child [missing] {} child { node {texdoc}};\end{tikzpicture}
\end{document}
页边距
\usepackage{geometry}
\geometry{a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm}
总结:
层次结构大概梳理:
\begin{document}\section{1}\subsection{1.1}\paragraph{}\begin{enumerate}\begin{tacular}
尾声
到这里一份朴实无华的pdf就制作完成了,基本的功能已经具备。后面有更多的需求再补充。
这篇关于LaTeX入门——制作一份朴实无华的pdf文档的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!