LaTeX简单常用方法笔记

时间:2022-07-23
本文章向大家介绍LaTeX简单常用方法笔记,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

简单用用吧,为了完成作业,具体用法可自行搜索

推荐LaTeX在线编辑器: https://cn.overleaf.com/

API参考手册: http://www.personal.ceu.hu/tex/latex.htm


标题:title{标题} 作者:author{作者} 学号:studentid{123} 正文:

begin{document}
...内容...
end{document}

制作首页:maketitle;如果没有这个,你的author之类的信息是不会显示的 中文支持:

usepackage{ctex} % 导入中文宏
摘要部分

中文摘要和关键词:

begin{abstract}         %摘要部分
smallcentering这是一篇关于勾股定理的小论文。%small 是使用缩小字体,centering是使内容居中
partextbf{Keywords:} keyword1, keyword2, keyword3
end{abstract}

英文摘要和关键词:

% 由于此时是中文环境,需要定义一个新的英文摘要
newcommand{enabstractname}{Abstract}
newenvironment{enabstract}{%
    parsmall
    noindentmbox{}hfill{bfseries enabstractname}hfillmbox{}par
    vskip 2.5ex}{parvskip 2.5ex}  
begin{enabstract}
    This is the abstract in English.
    centering
    textbf{Keywords:} Abstract, LaTeXe, English
  end{enabstract}

自动目录:

tableofcontents  %表示目录部分开始
section{勾股定理在古代}  %目录的前缀页面都会自动排版不需要手动排版
section{勾股定理的近代形式}
addcontentsline{toc}{section}{参考文献}  %用来添加文献的标准方式
section{附录}  %要写的附录

加粗:textbf{文字} 斜体:emph{文字} 下划线:underline{文字} 不缩进:noindent 段落结束换行:par 空白行:{parvskip 2.5ex} 图片设置英文题注:

begin{figure}[h!]
	centering
	includegraphics[scale=0.5]{img/Communication Model}
     renewcommand{figurename}{Fig} % 设置英文题注
	caption{Communication Model}
	label{fig:Communication Model}
end{figure}

表格设置英文题注:

% 主要也是这两句
renewcommand{tablename}{Tab}
caption{English title}

表格:

begin{table}[htbp]
  centering
    begin{tabular}{|c|c|c|c|}
    hline
        & multicolumn{3}{|c|}{Overall classification results (%)} \
    hline
       Descriptors          & KTH   & UCF sports & TV human interaction \
    hline
    Trajectory & 91.67 & 74.64 & 46.43 \
    HOG   & 86.11 & 69.88 & 44.52 \
    MBH   & 96.3 & 72.74 & 45.88 \
    hline
     hline
    Combined & 96.3 & 81.07 & 55.4 \
    hline
    end{tabular}%
    caption{An example table}
  label{t1}%
end{table}%

引用:内容内容cite{ref1}内容内容citep{ref1}

设置引用右上标:

% 添加:
newcommandmyciteup[1]{{setcitestyle{square,super}cite{#1}}} % 使引用为上标
%使用时:
123456 myciteup{ref1}

参考文献:

I always thought something was fundamentally wrong with the universe citep{ref1}
bibliographystyle{plain}
bibliography{ref/references}

% 文献具体内容在 ref/references.bib 中,内容格式(BibTeX)如下:
@book{ref1,
  title={The Hitchhiker's Guide to the Galaxy},
  author={Adams, D.},
  isbn={9781417642595},
  url={http://books.google.com/books?id=W-xMPgAACAAJ},
  year={1995},
  publisher={San Val}
}

章:chapter{名称} 小节:section{名称} 亚节:subsection{名称} 三级标题:subsubsection{三级标题}

另起一页:newpage 插入图片:

begin{figure}[h!]
centering
includegraphics[scale=1.7]{img/universe} % 图片文件img/universe.jpg
caption{The Universe}
label{fig:universe}
end{figure}

标签:label{名称a},常与ref{名称a}同用 伪代码:

先导入包:usepackage[lined,boxed,commentsnumbered]{algorithm2e}
再添加代码:
begin{algorithm}[H]
  KwData{this text}
  KwResult{how to write algorithm with LaTeX2e }
  initialization;
  While{not at end of this document}{
    read current;
    eIf{understand}{
      go to next section;
      current section becomes this one;
    }{
      go back to the beginning of current section;
    }
  }
  caption{How to write algorithms 1}
end{algorithm}

导入其他tex:input{a.tex} 目录:makecontents 各种列表:listtables、listfigures、listalgorithms 设置页码:

pagenumbering{arabic} %  阿拉伯数字
setcounter{page}{1} % 数字1

简单公式:

行内公式:
$ c = sqrt{a^{2}+b_{0}^{2}+e^{x}} $
行间公式:
$$ c = sqrt{a^{2}+b_{0}^{2} +e^{x}} $$

常用数学公式代码:
xfxuezhang.cn/index.php/archives/121

复杂公式并编号:

begin{equation} 
mathbf{X} = left(begin{array}{ccc} 
x_{11} & x_{12} & ldots \ 
x_{21} & x_{22} & ldots \ 
vdots & vdots & ddots end{array} right) 
end{equation} 

换行:\ 空格:

完整测试实例(仅供参考啊,实际有很多配置的):

% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode

documentclass[11pt]{article} % use larger type; default would be 10pt
%documentclass[master,twoside]{article}
usepackage[utf8]{inputenc} % set input encoding (not needed with XeLaTeX)

%%% PAGE DIMENSIONS
usepackage{geometry} % to change the page dimensions
geometry{a4paper} % or letterpaper (US) or a5paper or....
% geometry{margin=2in} % for example, change the margins to 2 inches all round
% geometry{landscape} % set up the page for landscape
%   read geometry.pdf for detailed page layout information

% 导入中文宏 eabstract
usepackage{ctex}
usepackage{graphicx} % support the includegraphics command and options 
usepackage{natbib}
% usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent

% 算法以及列表环境
RequirePackage{cases,listings}
RequirePackage{fancyvrb}
RequirePackage{algorithmic}

%%% PACKAGES
usepackage[lined,boxed,commentsnumbered]{algorithm2e}
usepackage{booktabs} % for much better looking tables
usepackage{array} % for better arrays (eg matrices) in maths
usepackage{paralist} % very flexible & customisable lists (eg. enumerate/itemize, etc.)
usepackage{verbatim} % adds environment for commenting out blocks of text & for better verbatim
usepackage{subfig} % make it possible to include more than one captioned figure/table in a single float
% These packages are all incorporated in the memoir class to one degree or another...

%%% HEADERS & FOOTERS
usepackage{fancyhdr} % This should be set AFTER setting up the page geometry
pagestyle{fancy} % options: empty , plain , fancy
renewcommand{headrulewidth}{0pt} % customise the layout...
lhead{}chead{}rhead{}
lfoot{}cfoot{thepage}rfoot{}

%%% SECTION TITLE APPEARANCE
usepackage{sectsty}
allsectionsfont{sffamilymdseriesupshape} % (See the fntguide.pdf for font help)
% (This matches ConTeXt defaults)

%%% ToC (table of contents) APPEARANCE
usepackage[nottoc,notlof,notlot]{tocbibind} % Put the bibliography in the ToC
usepackage[titles,subfigure]{tocloft} % Alter the style of the Table of Contents
renewcommand{cftsecfont}{rmfamilymdseriesupshape}
renewcommand{cftsecpagefont}{rmfamilymdseriesupshape} % No bold!

%%% END Article customizations




%%% The "real" document content comes below...

title{Freshness optimization of dense relay cache network data based on edge computing}
author{The Author}


begin{document}
maketitle


begin{abstract}         %摘要部分
    smallcentering这是一篇关于勾股定理的小论文。%small 是使用缩小字体,centering是使内容居中
    partextbf{Keywords:} keyword1, keyword2, keyword3
end{abstract}

% 由于此时是中文环境,需要定义一个新的英文摘要
newcommand{enabstractname}{Abstract}
newenvironment{enabstract}{%
    parsmall
    noindentmbox{}hfill{bfseries enabstractname}hfillmbox{}par
    vskip 2.5ex}{parvskip 2.5ex}  
begin{enabstract}
    This is the abstract in English.
    centering
    textbf{Keywords:} Abstract, LaTeXe, English
end{enabstract}


tableofcontents  %表示目录部分开始
section{勾股定理在古代}  %目录的前缀页面都会自动排版不需要手动排版
section{勾股定理的近代形式}
addcontentsline{toc}{section}{参考文献}  %用来添加文献的标准方式
section{附录}  %要写的附录


section{First section}

Your text goes here.

subsection{A subsection}
subsubsection{三级标题}

More text.

begin{figure}[h!]
centering
includegraphics[scale=1.7]{img/universe}
caption{The Universe}
label{fig:universe}
end{figure}


begin{algorithm}[H]
  KwData{this text}
  KwResult{how to write algorithm with LaTeX2e }
  initialization;
  While{not at end of this document}{
    read current;
    eIf{understand}{
      go to next section;
      current section becomes this one;
    }{
      go back to the beginning of current section;
    }
  }
  caption{How to write algorithms 1}
end{algorithm}




section{Conclusion}
``I always thought something was fundamentally wrong with the universe'' citep{ref1}


$ c = sqrt{a^{2}+b_{0}^{2}+e^{x}} (1)$
$$ c = sqrt{a^{2}+b_{0}^{2} +e^{x}} $$


begin{equation} 
mathbf{X} = left(begin{array}{ccc} 
x_{11} & x_{12} & ldots \ 
x_{21} & x_{22} & ldots \ 
vdots & vdots & ddots end{array} right) 
end{equation} 

renewcommandbibname{Reference}
bibliographystyle{plain}
bibliography{ref/references}

end{document}