1.Latex的基本模板
- 代码的格式如下
\documentclass{ctexart}
\title{标题}
\author{作者}
\data{\today}%日期
\begin{document}
\maketitle%生成标题作者等信息
正文
\end{document}
2.多级标题和目录
- 1级标题用
\section{标题名字}
,latex会自动在前方生成一个序号1,2,3… - 2级标题用
subsection{标题名字}
,用在1级标题下方,latex会自动分配1.1,1.2,… - 目录在
\maketitle
后面加一句\tableofcontents
即可
3.插入图片
-
先导入包
\usepackage{graphicx}
-
在需要导入图片的位置输入如下代码
1. 第一种方式 \begin{figure}[htbp] \centering \includegraphics[width=8cm]{图片.jpg}%图片需要和tex放在同一目录下 \caption{名字} \end{figure} 2. 第二种方法 \begin{center} \includegraphics[width = .88\textwidth]{tu1.jpg} 图1\quad 名字 %\quad是一个大空格,更长的有\qquad \end{center}
-
图片漂移的解决方法
\usepackage{float}
\usepackage{graphicx}
\begin{figure}[H]
\centering
\includegraphics[width=8cm]{图片.jpg}%图片需要和tex放在同一目录下
\caption{名字}
\end{figure}
4.数学公式
5.常用指令合集
- \textbf{}
加粗字体 - \Large \Huge \tiny
改变字体的大小 - ~\[16pt]
插入空行,并指定空行的大小 - \noindent
取消段落首行的缩进 - \mbox{}
在数学公式中加入文字 - linespread{1.5}
1.5倍行距 - \songti
中文使用宋体。这个基本没什么用,因为ctexart中文默认是宋体,粗体默认是黑体。所以写中文论文时不需要调字体,只需要关注字体大小。
6.枚举
- 无数字
\begin{itemize}
\item Huawei
\item Xiaomi
\item Oppo
\end{itemize}
- 有数字
\begin{enumerate}
\item Huawei
\item Xiaomi
\item Oppo
\end{enumerate}
7.插入代码
- 插入C/C++代码
\documentclass{ctexart}
\usepackage{listings}
\lstset{language=C}%这条命令可以让LaTeX排版时将C键字突出显示
\lstset{breaklines}%这条命令可以让LaTeX自动将长的代码行换行排版
\lstset{extendedchars=false}%这一条命令可以解决代码跨页时,章节标题,页眉等汉字不显示的问题
\lstset{ showspaces=false,showstringspaces=false,showtabs=false,stepnumber=2}
\begin{document}
\begin{lstlisting}
#include <stdio.h>
int main(){
printf("hello world");
return 0;
}
\end{lstlisting}
\end{document}
- 插入所有类型的代码(推荐使用这个)
\usepackage{color}
\usepackage{listings}
\lstset{ %
language=C++, % choose the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
stepnumber=1, % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
frame=single, % adds a frame around the code
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
escapeinside={\%*}{*)} % if you want to add a comment within your code
}
\begin{lstlisting}
!!code!!
\end{lstlisting}
- 插入python代码
\documentclass[11pt]{article}
\usepackage{pythonhighlight}
\begin{document}
The following is some Python code
\begin{python}
# A comment
x = [5, 7, 10]
y = 0
for num in x:
y += num
print(y)
\end{python}
\end{document}
8.表格
简单表格
\documentclass{ctextart}
\usepackage{array}
\usepackage{caption}
\usepackage{float}
%这两条是为了保证表格中可以输入数学公式,如果没有这两条的话需要将下方的T和C选项全部换成c(表示居中)
\newcolumntype{C}{>{$}c<{$}}
\newcolumntype{T}{>{$}l<{$}}
\begin{document}
\begin{table}[H]
\centering
\caption{求解$4321x+1234y=1$}
\begin{tabular}{|T|C|C|}%一个|表示一条竖线
\hline
r & x&y \\
\hline
r_{-1}=4321 & 1 &0 \\
\hline
r_{0}=1234 & 0 &1 \\
\hline
r_{1}=619 & 1 &-3 \\
\hline
r_{2}=615 & -1 &4 \\
\hline
r_{3}=4 & 2 &-7 \\
\hline
r_{4}=3 & -307 &1075 \\
\hline
r_{5}=1 & 309 &-1082 \\
\hline
\end{tabular}
\end{table}
\end{document}
9.参考文献
- 上标
\newcommand{\upcite}[1]{\textsuperscript{\textsuperscript{\cite{#1}}}}
在引用的内容后面加上\upcite{1}
即可新增上标[1]。
需要注意的是,标号必须存在于\bibitem{}
中 - 参考文献目录
\begin{thebibliography}{99}
\bibitem{1}陈瑶瑶.新时代背景下筑牢我国粮食安全防线——评《食品安全导论》[J].食品安全质量检测学报,2022,13(19):6449-6450.DOI:10.19812/j.cnki.jfsq11-5956/ts.2022.19.036.
\bibitem{2}阎新之.谈谈粮食流通的“双轨制”[J].广西商专学报,1989(01):10-12.
\bibitem{3}王珍. 攥紧中国种子 端稳中国饭碗[N]. 中国纪检监察报,2022-08-15(008).DOI:10.28423/n.cnki.njjjc.2022.003333.
\bibitem{4}谢璐.中国粮食安全与食品安全[J].食品安全导刊,2017(09):36.DOI:10.16043/j.cnki.cfs.2017.09.022.
\bibitem{5}姜鹏.疫情前后的粮食浪费[J].北京规划建设,2022(01):184-189.
\bibitem{6}陈瑶瑶.新时代背景下筑牢我国粮食安全防线——评《食品安全导论》[J].食品安全质量检测学报,2022,13(19):6449-6450.DOI:10.19812/j.cnki.jfsq11-5956/ts.2022.19.036.
\end{thebibliography}
- 实例代码
\documentclass[10pt, a4paper, oneside,scheme=chinese]{ctexart}
%导入包
\usepackage{amsmath, amsthm, amssymb, appendix, bm, graphicx, hyperref, mathrsfs}
\usepackage{cite}
%创建命令
\newcommand{\upcite}[1]{\textsuperscript{\textsuperscript{\cite{#1}}}}
%正文
\begin{document}
这是一个引用1\upcite{1}
这是一个引用2\upcite{2}
% 参考文献
\begin{thebibliography}{99}
\bibitem{1}引用1
\bibitem{2}引用2
\end{thebibliography}
\end{document}