LaTeX简单常用方法笔记,附模板

2021-06-11 18:36:29 浏览数 (2)

简单用用吧,为了完成作业,3~5分太香了

具体用法可自行搜索

推荐LaTeX在线编辑器:

代码语言:javascript复制
https://cn.overleaf.com/

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

代码语言:javascript复制
begin{document}
...内容...
end{document}

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

代码语言:javascript复制
usepackage{ctex} % 导入中文宏
摘要部分

中文摘要和关键词:

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

英文摘要和关键词:

代码语言:javascript复制
% 由于此时是中文环境,需要定义一个新的英文摘要
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}

自动目录:

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

表格:

代码语言:javascript复制
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}

参考文献:

代码语言:javascript复制
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{名称} 小节:p{名称} 亚节:subp{名称} 三级标题:subsubp{三级标题}

另起一页:newpage 插入图片:

代码语言:javascript复制
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}同用 伪代码:

代码语言:javascript复制
先导入包: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 p;
      current p becomes this one;
    }{
      go back to the beginning of current p;
    }
  }
  caption{How to write algorithms 1}
end{algorithm}

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

代码语言:javascript复制
pagenumbering{arabic} %  阿拉伯数字
setcounter{page}{1} % 数字1

简单公式:

代码语言:javascript复制
行内公式:
$ c = sqrt{a^{2} b_{0}^{2} e^{x}} $
行间公式:
$$ c = sqrt{a^{2} b_{0}^{2}  e^{x}} $$


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

复杂公式并自动编号:

代码语言:javascript复制
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}

换行:\ 空格:

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

代码语言:javascript复制
% !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}
allpsfont{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  %表示目录部分开始
p{勾股定理在古代}  %目录的前缀页面都会自动排版不需要手动排版
p{勾股定理的近代形式}
addcontentsline{toc}{p}{参考文献}  %用来添加文献的标准方式
p{附录}  %要写的附录




p{First p}


Your text goes here.


subp{A subp}
subsubp{三级标题}


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 p;
      current p becomes this one;
    }{
      go back to the beginning of current p;
    }
  }
  caption{How to write algorithms 1}
end{algorithm}








p{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}

0 人点赞