Familiar with Latex paper formatting in one article

I believe students who major in computer science or have written professional papers know how complicated and cumbersome it is to use Office or WPS to control the format of a paper. Sometimes the time spent on changing the paper format even exceeds the time of writing the paper, so we urgently We need to use a more professional and practical typesetting tool to meet our paper typesetting needs, so Latex came into being!

1.LaTex Overview

LaTex is a professional typesetting tool,LaTex is used around the world for scientific documents, books, and many other forms of publishing. One of the important reasons why people use LaTex is that it can separate the content and style of the paper. This is more friendly to programmers who have written programs for a long time. This allows programmers to only need Focus on the content of the paper, while the computer takes care of the formatting. Secondly, LaTex is very powerful in writing mathematical and scientific documents. It provides a wide range of input and typesetting functions for mathematical symbols, formulas, equations and symbols, making LaTex widely used for writing formulas in mathematics and algorithm papers. At the same time, LaTex and BibTex can easily manage and cite references. It allows the generation of reference lists in a consistent format and automatically handles the numbering and citations of citations. relationship, which can greatly improve the accuracy and reliability of literature citations.
Since it has so many advantages, for beginners, some people may worry that it is difficult to configure the compilation environment, is not suitable for the WYSIWYG model, and will encounter various problems after writing it. Fancy error messages are even more uncomfortable.
First of all, for the problem of configuring the compilation environment, we can avoid the most important and take the easy. Directly use LaTex’s online editor Overleaf. From now on Say goodbye to the intricacies of your local environment. Secondly, after we completely use LaTex to write an article. Basically, I have a grasp of its characteristics, and gradually become familiar with using LaTex for writing.

2.LaTex structure

After you register and log in in overleaf, you can clearly seeThe initial structure content of LaTex can be divided into an introduction area and a main text area. The preamble is located between \documentclass and \begin{document}.

2.1 Introduction area

In the introductory area, you can perform the following operations:
1. Introduce macro packages: Use the \usepackage{macro package name} command to introduce various macro packages to expand the functions of LaTex . This is similar to introducing a mature library in Java.
2. Set document properties: such as setting page size, page spacing, font, line spacing, etc.
3. Define commands: Define custom commands through \newcommand or \renewcommand to simplify reused text and formatting.

2.2 Text area

The document body is located between \begin{document} and \end{document}. In the text area,you can write the actual content of the document, including titles, paragraphs, chapters, formulas, charts, etc.. Document content can be typeset and organized using a variety of LaTex commands and environments.
Insert image description here

3. Set up Chinese editor

It should be noted here that the initial state of overleaf does not support Chinese encoding, so some operations need to be done to support Chinese. The specific operations are as follows:
1. Modify the default editor It is LuaLaTex, so it supports Chinese encoding;
2. Introduce the macro package \usepackage[fontset=ubuntu]{ctex};

4.LaTex coding basics

4.1 Add title, author, date

To add the title, author, and date to the document, you only need to add three lines of code in the introductory area, as shown below:

\title{LaTexExample} %定义文档标题
\author{author} %定义文档作者
\date{February 2014} %定义文档日期

It should be noted here that in the \date{} command, in addition to filling in the date directly, you can also use the \today command to display the latest date in real time. Now that you have specified the title, author, and date for the document, you need to use the \maketitle command in the text area to display this information on the document, as shown below:
Insert image description here

4.2 Implement bold, italics and underline

  • Bold: Bold text in LaTex is written using the \textbf{content} command.
  • Italic: Italic text in LaTex is written using the \textit{content} command.
  • Underline: Underlined text in LaTex is written using \underline{content}.

The specific implemented LaTex code and the displayed effect are as follows:
Insert image description here
One more thing to say here: If you want to break a line in the document, just leave a blank line in the LaTex text area. Implementation, no complex commands and operations required!

4.3 Add mathematical formulas

The way to add mathematical formulas can be mainly divided into in-line formulas and inter-line formulas! Inline formulas are used to write formulas as part of the text, while inline formulas are formulas that require the formula to be placed on a separate line.
To implement inline formulas in LaTex, you need to use $$ or (...); to implement interline formulas in LaTex, you can use \begin{equation}…\end{equation}. Specific examples are as follows:
Insert image description here
When you see this, you may ask, you don’t know or are not familiar with many of the command formulas here. Don’t worry, we just need to know how to use them and how to write the formulas. As for which command each formula corresponds to, just check the command information directly when using it. For details, you can check LaTex mathematical formulas.

4.4 Create a list

The list here can be divided into ordered list and unordered list. I believe everyone who has studied HTML knows that the ul tag implements an unordered list, while the ol tag implements an ordered list! The specific LaTex command to implement the list is as follows:In short, itemize corresponds to an unordered list, enumerate corresponds to an ordered list, and each item\item corresponds to an List items.

\begin{itemize}
    \item 无序列表1
    \item 无序列表2
    \item 无序列表3
    %这是定义的无序列表
\end{itemize}

\begin{enumerate}
    \item 这是有序列表1
    \item 这是有序列表2
    \item 这是有序列表3
\end{enumerate}

The specific effect is as follows:
Insert image description here

4.5 Implementation summary and multi-section chapters

Anyone who has written a paper or participated in a competition knows that an abstract is a brief summary of an article. It is very simple to introduce an abstract into LaTex. You only need to add the content of the abstract Just wrap it in \begin{abstract}…\end{abstract}, as follows:
Insert image description here
At the same time, each chapter in the paper will Multi-level titles can be implemented in LaTex using \section, \subsection (subsection of \section), and \subsubsection (subtitle of \subsection). Each additional sub is a deeper level. sub-section, the specific effect is as follows:
Insert image description here

4.6 Page change and directory generation

In LaTex, you can force a page change through the command, , that is, \clearpage. This command will force the page to change at the position where the command is read. Change page.
At the same time, after we set the chapter and its sub-chapters through \section before, we can directly use the \tableofcontents command to automatically generate the table of contents< a i=5>, the specific implementation effect is as follows:
Insert image description here

4.7 Insertion of pictures and charts

If you want to insert a picture into the document, since we are using the overleaf online editor, and the online editor cannot directly read our local picture resources, so we First, you need to upload image resources to the website. Here you can directly click the upload icon in the upper left corner. The details are as follows:
Insert image description here
After uploading the image, we can directly use The command \includegraphics can complete the upload of images. But there will be problems with the display after you upload it like this, because the image will be displayed according to the original size of the image, so it will look very awkward and uncomfortable, so we need to set the width and height of the image, as follows: < /span>

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\includegraphics[width=0.5\textwidth]{example-image} % 设置图片宽度为文本宽度的一半

\includegraphics[height=5cm]{example-image} % 设置图片高度为5cm

\includegraphics[width=3cm, height=2cm]{example-image} % 同时设置图片的宽度和高度

\end{document}

Just using \includegraphics to insert pictures still cannot meet the needs of our paper for pictures, because the pictures in the paper need to have titles. The specific implementation can be
\includegraphics[width= 0.5\textwidth]{example-image} is wrapped in \begin{figure}…\end{figure}, and some additional commands are added inside to add image titles and references, as shown below:
Insert image description here
After completing the insertion of pictures, you still need to understand the insertion of tables. Let's take a simple example as follows:
Insert image description here
The tabular (table) environment is the default method of creating tables in LaTex. You have to specify a parameter for this environment, in this case {|c|c|c|}, this tells LaTex that there are three columns, with | separators between each column, and the text in each column Needs to be centered. You can use r for right alignment and l for left alignment. The symbol & is used to specify the delimiter of table entries in China. The symbol & must be less than the number of columns. To go to the next line, we use the newline command \.
Of course, only relying on this simple syntax can only implement simple tables. Once you encounter a table that spans rows and columns, difficulties will arise. Therefore, we can use online websites to formulate tables that meet our own needs. form, and then automatically generate LaTex code. The specific website link is:Form generation website
Insert image description here

Guess you like

Origin blog.csdn.net/qq_51447436/article/details/133166531