latex基本程序

基本结构 

导言区pre:文档类型、调用宏包、文档格式
正文区:文字、公式、表格、图片、参考文献、章节结构

%导言区
\documentclass{artical}
%\documentclass{14pt,a4paper}{artical}
%\documentclass{twocolumn}{artical}
\usepackage{geometry}
%\usepackage{subfigure}
\usepackage{fancyhdr}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{mutirow}
%\usepackage{ctex}
\title{My first document}
\author{Ding Yueyue}
\data{\today}

% 正文区
\begin{document}
\maketitle   生成封面标题
Hello world  正文内容
\end{document}

\documentclass[12pt, letterpaper]{article}  
\usepackage[utf8]{inputenc}
\usepackage{comment} 

% Title
\title{Document Title}
\author{Nobody \thanks{Somebody}}
\date{Some Date}
 
\begin{document}

\begin{titlepage}
\maketitle
\end{titlepage}

\tableofcontents

\begin{abstract}
This is a simple paragraph at the beginning of the 
document. A brief introduction about the main subject.
\end{abstract}

First document. This is a simple example, with no 
extra parameters or packages included.
 
% Comments 
\begin{comment}
This text won't show up in the compiled pdf
this is just a multi-line comment. Useful
to, for instance, comment out slow-rendering
while working on the draft.
\end{comment}

\end{document} 

一个LaTex文件分为两个部分:导言和正文。 在\begin{document}和\end{document }之间的是文档的正文内容。 在\begin{document}之前的命令称为preamble(导言)。 在preamble中通常定义文档的格式、语言等。上文所示LaTex文档其结构如下图所示:

\documentclass[12pt, letterpaper]{article}   
文档类型            正文字号默认10pt    纸张 a4paper   格式article book report slides
\usepackage[utf8]{inputenc}       在编译LaTex文件时要导入的扩展包        
\usepackage{comment} 

% Title   设置封面格式
\title{Document Title}                           题目
\author{Nobody \thanks{Somebody}}   作者
\date{Some Date}                                 日期
 
\begin{document}                       正文开始   

\begin{titlepage}                          
\maketitle                   
\end{titlepage}   
生成封面

\tableofcontents   
生成文档目录

\begin{abstract}         摘要开始
This is a simple paragraph at the beginning of the 
document. A brief introduction about the main subject.
\end{abstract}      结束

First document. This is a simple example, with no 
extra parameters or packages included.
 
% Comments         
\begin{comment}       评论开始
This text won't show up in the compiled pdf
this is just a multi-line comment. Useful
to, for instance, comment out slow-rendering
while working on the draft.
\end{comment}}
从百分号%开始到这一个行结束的部分是LaTex文件的注释内容,
不在编译后生成的pdf文档中显示。
在\begin{comment}和\end{comment }之间的内容也不在编译后生成的pdf文档中显示。

# $ % ^ & _ { } \  要想在生成的文档中显示保留字符,要在这些字符前加反斜杠 \ 
$\backslash$ 是输出\ ;  \\ 是换行 ;  数学公式环境的$ \sim $是插入波浪线.

多文件编译

  毕业论文篇幅较长,单一文件的编译方式不太方便,可按照文档的逻辑层次,把整个文档分成多个,提供的\include{filename}命令可用来导入另一个文件的内容作为一个章节,文件名不用带.tex扩展名。\include{filename}命令会在命令之前和之后使用\clearpage或\cleardoublepage另起新页,并将文件内容贴到\include{filename}命令所在位置。或者:\input{filename1}

  

\clearpage或\cleardoublepage
\include{filename}    ;内容
\clearpage或\cleardoublepage

Arial字体的使用

  • 先定义新字体Arial:\newfontfamily\sectionef{Arial}
  • 在需要使用Arial字体的地方输入命令:\sectionef

设置标题

英文标题字体采用Arial,中文标题采用黑体
一级标题居中,小三号
二级标题左对齐,四号
三级标题subsubsection

\usepackage{titlesec}
\newfontfamily\sectionef{Arial}                                        % 设置Arial字体        
% \newCJKfontfamily\sectioncf{STXihei}                                % 设置黑体
\titleformat{\section}{\center\zihao{-3}\heiti\sectionef}{            % 设置一级标题居中,中文字体为黑体,英文字体为Arial,字号为小三号
第\,\thesection\,章}{1em}{}
\titleformat*{\subsection}{\zihao{4}\heiti\sectionef}                % 设置二级标题中文字体为黑体,英文字体为Arial字号为四号

zize{} black 

设置页边距,页眉,页脚


页边距左右均为3.2 cm,上下均为3.8 cm
页眉居中,显示当前章标题
页脚居中,显示当前页码
封面不显示页码,中英文摘要和目录页码采用大写罗马格式,正文及参考文献采用小写阿拉伯格式
由于titlesec宏包会改变页眉章标题格式,所以需要重新定义页眉章标题格式,如果没有引入titlesec宏包,可采用\fancyhead[C]{\leftmark}完成页眉居中显示当前章标题。
 

\usepackage{geometry}		  %宏包 几何参数										
\geometry{left=3.2cm,right=3.2cm,top=3.8cm,bottom=3.8cm}			% 设置页边距
\usepackage{fancyhdr}												% 设置页眉
\pagestyle{fancy}	
\fancyhf{}
\cfoot{\thepage}													% 设置页码
\renewcommand{\sectionmark}[1]{\markboth{第\thesection 章\quad 		% 设置页眉内容为章标题
\ #1}{}}

\pagenumbering{digit type} 

页码数字类型:
arabic      阿拉伯数字(1,2,3,4),默认样式

roman      小写罗马数字(i,ii,iii,iv)
Roman     大写罗马数字(I,II,III,IV)

 alph         小写拉丁字母(a,b,c,d)
  Aiph         大写拉丁字母(A,B,C,D)
 

\setcounter{page}{page number}           设置页码
 \thispagestyle{empty}                            当前页不标页码

\begin{document}

%% Making title page
\begin{titlepage}
\maketitle
\thispagestyle{empty}   封面不标
\end{titlepage}

%% Contents
\pagenumbering{roman}    
\tableofcontents         目录小罗马

\newpage
\pagenumbering{arabic}   正文阿拉伯
\setcounter{page}{1} 
在封面不标记页码,目录页使用小写罗马数字标记页码,正文部分使用阿拉伯数字标记页码

段落行间距

\documentclass[UTF8]{article}
\usepackage{setspace}            调用{setspace}扩展包

\begin{document}

%%双倍行间距 
\begin{spacing}{2.0}
段落内容。
\end{spacing}

%%单倍行间距 
\begin{spacing}{1.0}
段落内容。
\end{spacing}

\end{document}


 分段:正文空行即分段
\seciton{},\subsection{},\subsubsection{}  放到对应位置即可
*不参加编号,适用于章节、图表等。 \subsubsection*{} ;
在文本中插入公式:$equation$  空格:\quad

数学公式


单独成行的公式,不编号*
\begin{equation*}
具体公式
\end{equation*}
多行排列的公式:
\begin{equation}  
\begin{aligned}      多行用一个编号
&   对齐位置
\\   换行位置
\end{aligned}
\end{equation}

(2)
\begin{align}          每行都编号,可分别引用
&   对齐
\\   换行
\end{align}

(equation \ref{eq:k})放到文中引用的位置
\begin{equation}
\label{eq:k}    引用公式的标识(非排序)
具体公式
\end{equation}

矩阵
导言:调用宏包amsmath
\begin{pmatrix}
&     矩阵元素分隔   \cdots  横向省略
\\   换行                    \vdots  竖向省略    \ddots  斜向省略
\end{pmatrix} 

\begin{equation}   公式可嵌套矩阵
\end{equation}  

\hspace{1cm}   段落间空白
\vspace{5pt}

\begin{center} 居中
...
\end{center}

\begin{flushleft} 左对齐
...
\end{flushleft}

\begin{flushright}右对齐
...
\end{flushright}
\fbox{A}       给文字加线框

\hfill 

\fbox{
  Use $\backslash fbox$ environment for creating line box.
}

\begin{center}
\fbox{
  Box lies in center. However  
}
\end{center}

\begin{center}
\fbox{ 
  \parbox{\textwidth}{ 
    \begin{center}
      This is a \\
      Full size box  \\
    \end{center}
  } 
}
\end{center}

\begin{center}
\fbox{ 
  \parbox{0.4\textwidth}{ 
    \begin{center}
      This is a \\
      Small size box  \\
    \end{center}
  } 
}
\end{center}

图片插入及引用

首先将图片存在和正文.tex同一文件夹下,或单独建立子文件夹

单图片

\usepackage[pdftex]{graphicx}    宏包
% 设置图片文件存放路径
\graphicspath{{../figures}      路径

\begin{document}
% 在正文中引用图片时使用\ref 
(Figure \ref{fig:foo}) 
\begin{figure}[options]  %options插入位置:!h(here),!t(top),!b(bottem),!p(漂浮),htp(优先级)
%设置对齐格式
\centering     %图片居中
%指定图形宽高和图形名称           
\includegraphics[width=0.8,height=2.5]{foo.png}  %如果在Fig子文件夹里用:{Fig/foo.png}
% [scale=0.3] ; [height=2.5in] ;[width=0.5,textwidth,angle=30]
\caption{Foo}     %设置标题 
\label{fig:foo}   %标记图片正文引用名称
\end{figure}
 
\end{document}

插入图片并在文中通过图片编号引用图片

多图片(子图)宏包 \usepackage{subfigure}
\subfigure[subcaption.]{\includegraphics[wide=0.3\columnwith]{fig/1.png}}
\subfigure[subcaption.]{\includegraphics[wide=0.3\columnwith]{fig/1.png}}
                  [子标题]
子图程序之间插入空行,文档图片换行
\label{subfig:m}    放其中一个子图后面,就可以单独引用

表格 

\begin{table}[htp]
 \centering
 \begin{tabular}{llr}   
 \hline
 \multicolumn{2}{c}{Item} \\
 \cline{1-2}
 Animal    & Description & Price (\$) \\
 \hline
 Gnat      & per gram    & 13.65      \\
          & each        & 0.01       \\
 Gnu       & stuffed     & 92.50      \\
 Emu       & stuffed     & 33.33      \\
 Armadillo & frozen      & 8.99       \\
 \hline
 \end{tabular}
\label{tab:table1}     标签
\caption{TableCaption} 表头
\end{table}
表格的引用: \ref{tab:table1}

 单元格对齐方式
\begin{tabular}{c|c|c|c|c}
& & & & \\  一行五个元素
\hline
\cline{1-2}
\end{tabular}

{c|c|c|c|c} %5列数据,每列居中,是|有4个纵向的分割线
&&&&&&&  % &为单元格分界 ;\hline 横向分割线(全列);\cline{1-2} 横向分割线(1-2列)
\begin{tabular}{p{0.1cm}}{p{0.1cm}}{p{2.5cm}}{p{5.5cm}}{p{2.1cm}}  单元格置顶  宽度


\usepackage{multirow}      
multirow{数量_OF_ROWS}{WIDTH}{CONTENT}               行合并 CONTENT:合并后的显示内容
multicolumn{数量_OF_COLUMNS}{ALIGNMENT}{CONTENT}   列合并 ALIGNMENT:对齐方式c
直接放到要合并的地方


表格行距、字体大小:(整体大小修改)
\tiney\scriptsize\footnotesize\small\normalsize\large\Large\LARGE\huge\Huge

\begin{tabular}{c}
\hline
Normal  \\
\hline  
  smallskip(under the characters)  \\ \noalign{\smallskip} 
\hline  \noalign{\smallskip} 
smallskip(over the characters) \\ 
\hline  \noalign{\medskip} 
 medskip  \\
\hline  \noalign{\bigskip}
 bigskip  \\
\hline
  0.5cm \\[0.5cm]  
\hline   
\end{tabular}

Latex中默认的线条宽度是0.4pt, 如果想要使用粗一点的线条,可以使用 booktabs环境包. 这需要在Latex文档的导言部分添加命令:  \usepackage{booktabs}  

\begin{table}[h]
\centering
\begin{tabular}{ccc}
\toprule
Name & ID & Gender\\
\midrule
Tom & 001& Male\\
Rose & 002& Female\\
\bottomrule
\end{tabular}
\caption{这是一张三线表}
\end{table} 

参考文献 

cite{rerf1}

(1)短文     便捷
\begin{thebibliography}{99}  最多99个文献
        \bibitem{ref1}author ;title,etl
\end{thebibliography}{99}
(2) 常规      方便管理
建立references.bib文件,在正文对应的位置放置\bibliography{references}
bib中的格式:artical,book,boolet,conference,inbook,mastersthesis,phdthesis, 


@artical{li2020towards}     使用谷歌学术或者百度学术 引用——bibtext格式
title
authou
journal

按要求调整文献格式
\bibliographystyle{options}
常用格式:plain,unsrt,alpha,abbrv,ieeetr,acm,siam,apalike, 期刊提供的.bst格式(qikan.bst)
\bibliograyhystyle{qikan}
参考文献的格式:
~\cite{name1@2022}    ~为空半格,\cite常用理科期刊
~\citep{name3@2022}                      \citep常用人文期刊

跨文本引用

多章节或正文+附件
导言:
\usepackage{xr}
\externaldocument{texfile}  texfile:要读取的文件名
交叉引用
\ref{tex:Lcompare}
附件:
\appendix
\counterwithin{figure}{section}  图片
\counterwithin{table}{section} 设置报个
\counterwithin{equation}{section} 设置公式

模板

下载模板,把正文填充到里面

在线版latex
www.overleaf.com
在线编辑、多人共享、在线投稿、网速影响


 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值