Article Directory
1. The basic template of Latex
- The format of the code is as follows
\documentclass{ctexart}
\title{标题}
\author{作者}
\data{\today}%日期
\begin{document}
\maketitle%生成标题作者等信息
正文
\end{document}
2. Multi-level title and table of contents
- For level 1 titles
\section{标题名字}
, latex will automatically generate a serial number 1, 2, 3... - For level 2 headings
subsection{标题名字}
, used below level 1 headings, latex will automatically assign 1.1, 1.2, ... - Just
\maketitle
add a sentence after the directory\tableofcontents
3. Insert picture
-
first import the package
\usepackage{graphicx}
-
Enter the following code where the image needs to be imported
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}
-
Solution to image drift
\usepackage{float}
\usepackage{graphicx}
\begin{figure}[H]
\centering
\includegraphics[width=8cm]{图片.jpg}%图片需要和tex放在同一目录下
\caption{名字}
\end{figure}
4. Mathematical formulas
5. A collection of common commands
- \textbf{}
bold font - \Large \Huge \tiny
change font size - ~\[16pt]
Insert a blank line and specify the size of the blank line - \noindent
cancels the indentation of the first line of the paragraph - \mbox{}
add text to math formula - linespread{1.5}
1.5 times the line spacing - \songti
Chinese uses Song style. This is basically useless, because ctexart Chinese defaults to Song, and bold defaults to Hei. Therefore, when writing a Chinese paper, you don’t need to adjust the font, you only need to pay attention to the font size.
6. Enumeration
- no number
\begin{itemize}
\item Huawei
\item Xiaomi
\item Oppo
\end{itemize}
- have numbers
\begin{enumerate}
\item Huawei
\item Xiaomi
\item Oppo
\end{enumerate}
7. Insert code
- Insert C/C++ code
\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}
- Insert all types of codes (recommended to use this)
\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}
- insert python code
\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. Form
simple form
\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. References
- Superscript Add a superscript
\newcommand{\upcite}[1]{\textsuperscript{\textsuperscript{\cite{#1}}}}
after the quoted content [1]. Note that the label must exist in the\upcite{1}
\bibitem{}
- bibliography
\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}
- example code
\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}