【latex使用相关】latex基本入门和个人需求

参考:一份其实很短的 LaTeX 入门文档Latex的公式输入Latex 设置页码位置 (包括 pdfpages)使用Latex编辑算法伪代码Latex写论文中,算法过长,需要分页显示的方法latex中让图片放在指定文字段落后

目录

1、基本

中英文混排

作者、标题、日期

控制行文段落

字体设置

分段

设置页边距

设置页眉页脚

插入图片

设置图片位置于代码中指定文字下面

2、数学公式相关

上下标

分数

输入大于等于和小于等于号

输入求和公式

3、算法伪代码

伪代码分页显示

4、自己乱七八糟的需求

设置section内容居左

将日期设置为英文

把图片默认编号从中文的“图”修改为“Figure”

5、遇到的奇奇怪怪的问题

字体大小问题


1、基本

特殊字符需要使用\转义

中英文混排

\documentclass[UTF8]{ctexart}
\begin{document}
你好,world!
\end{document}

作者、标题、日期

\documentclass[UTF8]{ctexart}
\title{你好,world!}
\author{Liam}
\date{\today}
\begin{document}
\maketitle
你好,world!
\end{document}

控制行文段落

\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}

字体设置

\textbf{文字} # 加粗
\emph{文字} # 斜体
\underline{文字} # 加下划线

分段

默认是有首行缩进2字符,要分段的话,两次换行即可,即两端之间空一格。

设置页边距

下面的代码需要加在导言区

\usepackage{geometry} % 设置页边距的宏包
\geometry{a4paper,margin=1in}

设置页眉页脚

下面的代码需要加在导言区,{}表示无设置内容

\usepackage{fancyhdr} % 设置页眉页脚的宏包
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0pt} %改为0pt即可去掉页眉下面的横线
\renewcommand{\footrulewidth}{0pt} %改为0pt即可去掉页脚上面的横线

插入图片

\begin{document}

\begin{figure} 
\centering 
\includegraphics[width=\textwidth]{文件名.pdf} # 文件路径
\caption{图片名称} # 图片名称,我这里的环境默认是中文的“图1 fit”
\label{} # 设置标签
\end{figure}

\end{document}

***将visio的图片插入latex中【去除空白部分】【用Adobe Acrobat无法去除pdf空白部分的解决方法】

设置图片位置于代码中指定文字下面

导言区添加:

\usepackage{float}

使用\begin{figure} [H]代替\begin{figure} 

2、数学公式相关

需要在导言区添加宏包:

\usepackage{amsmath}

上下标

下标:使用a$_{b}$,则显示为a$_{b}$

分数

根式用 \sqrt{·} 来表示,分式用 \frac{·}{·} 来表示(第一个参数为分子,第二个为分母)。

输入大于等于和小于等于号

在导言区添加宏包:

\usepackage{amsmath}
\usepackage{amssymb}

正文中,大于等于号使用:\geqslant;小于等于号使用:\leqslant。

输入求和公式

正文部分使用:

\begin{equation*}
  s = \sum_{下界}^上界 式子
\end{equation*}

如:

\begin{equation*}
  OPT[i] = \sum_{j=1}^iOPT[j-1]*OPT[i-j]
\end{equation*}

显示为:

3、算法伪代码

导言区添加:

\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}

正文:

\begin{document}
%% 写算法伪代码或者流程的前期准备
\renewcommand{\algorithmicrequire}{\textbf{Input:}}  % 使用Input代替默认的Require
\renewcommand{\algorithmicensure}{\textbf{Output:}} % 使用Output代替默认的Ensure


\begin{algorithm}[ht]
  \caption{xxxxx} % 算法名称
  \begin{algorithmic}[1] % 每行显示行号
    \Require
      A:xxxxxxxxx; B: xxxxxxxx
    \Ensure
      xxxxxxx
    \Function {xxxxx(函数名)}{$x1,x2,x3$} % 输入参数
      \If {$条件$}
      \State \Return $返回值$
      \EndIf
      \State $xx1 \gets {xxxx2}$ % 显示为xx1 <—— xxxx2

    
    \EndFunction
  \end{algorithmic}
\end{algorithm}

\end{document}

伪代码分页显示

在导言区添加:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}

\makeatletter
\newenvironment{breakablealgorithm}
  {% \begin{breakablealgorithm}
   \begin{center}
     \refstepcounter{algorithm}% New algorithm
     \hrule height.8pt depth0pt \kern2pt% \@fs@pre for \@fs@ruled
     \renewcommand{\caption}[2][\relax]{% Make a new \caption
       {\raggedright\textbf{\ALG@name~\thealgorithm} ##2\par}%
       \ifx\relax##1\relax % #1 is \relax
         \addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##2}%
       \else % #1 is not \relax
         \addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##1}%
       \fi
       \kern2pt\hrule\kern2pt
     }
  }{% \end{breakablealgorithm}
     \kern2pt\hrule\relax% \@fs@post for \@fs@ruled
   \end{center}
  }
\makeatother

用\begin{breakablealgorithm}和\end{breakablealgorithm}替换伪代码中的\begin{algorithm}[ht]和\end{algorithm}

4、自己乱七八糟的需求

设置section内容居左

\begin{document}

\ctexset { section = { format={\Large \bfseries } } } % 使\section内容居左

\end{document}

将日期设置为英文

\begin{document}

\ctexset { today=old } % 使日期显示为英文格式

\end{document}

把图片默认编号从中文的“图”修改为“Figure”

在导言区添加:

\usepackage{caption}

正文添加:

\begin{document}
% 设置figure的格式
\captionsetup[figure]{labelfont={bf},labelformat={default},labelsep=period,name={Figure}}


\end{document}

5、遇到的奇奇怪怪的问题

字体大小问题

Font shape `OMX/cmex/m/n' in size <10.53937> not available
(Font)    size <10.95> substituted.

在导言区添加宏包

\usepackage{lmodern} % http://ctan.org/pkg/lm

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值