插播一条关于LATEX的学习

本文介绍了LaTeX的基础知识,包括文档结构、基本语法(如标题、作者、日期、数学公式、图片插入、列表、表格和边框),以及如何使用LaTeX进行文档编排,如创建摘要、章节结构和添加目录。
摘要由CSDN通过智能技术生成

Hi~各位小伙伴,由于日常需要大量使用Word和PPT,其中最令人苦恼的事情莫过于是排版!!因此,决定学习一款文字排版工具以减轻这部分的工作量,提高工作效率——LATEX

一 认识latex基本语法

eg.1 

\documentclass[12pt, letterpaper]{article}   ///告诉latex这是什么文档使用多大字体
\title{My first LaTeX document}              ///标题
\author{Hubert Farnsworth\thanks{Funded by the Overleaf team.}}  ///thank后面括号内接脚注
\date{August 2022}
\begin{document}                           ///具体内容的开端提示
\maketitle
We have now added a title, author and date to our first \LaTeX{} document!
                                          ///这里的这一行是一条注释。 不会在文档中排版
\end{document}                            ///具体内容的结束提示

 eg.2

Some of the \textbf{greatest}
discoveries in \underline{science} 
were made by \textbf{\textit{accident}}.

        以上代码分别为:加粗、下划线、斜体的相应命令。

        其中,一个有趣的命令就是:\emph{argument}在普通文本中,强调的文本是斜体的,但如果在斜体文本中使用,则此行为会相反。

  eg.3 插入图片

\documentclass{article}
\usepackage{graphicx}% LaTeX package to import graphics
\graphicspath{{images/}} % configuring the graphicx package
 
\begin{document}
The universe is immense and it seems to be homogeneous, 
on a large scale, everywhere we look.

\includegraphics{universe}  
 
There's a picture of a galaxy above.
\end{document}

其中,includegraphcs 命令由% Graphicx 包提供(实现)\includegraphics { Universe }

若需要使用该安装包,则需要在overleaf里面使用 \usepackage{graphicx}

eg.4

\documentclass{article}
\usepackage{graphicx}
\graphicspath{{images/}}
 
\begin{document}

\begin{figure}[h]
    \centering
    \includegraphics[width=0.75\textwidth]{mesh}
    \caption{A nice plot.}
    \label{fig:mesh1}
\end{figure}
 
As you can see in figure \ref{fig:mesh1}, the function grows near the origin. This example is on page \pageref{fig:mesh1}.

\end{document}
  • \includegraphics[width=0.75\textwidth]{mesh}:这种形式\includegraphics指示LaTeX将图形的宽度设置为文本宽度的 75%,其值存储在命令中\textwidth
  • \caption{A nice plot.}:顾名思义,该命令设置图形标题,可以放置在图形的上方或下方。如果您创建图形列表,则该标题将在该列表中使用。
  • \label{fig:mesh1}:要在文档中引用此图像,请使用命令为其指定标签\label。该标签用于生成图像的编号,并与下一个命令结合使用,您可以引用它。
  • \ref{fig:mesh1}:此代码将替换为与参考图相对应的编号。

以上代码可以得到以下图片:

 eg.5 创建列表{环境以where might be开头和结尾}

   无序列表:由itemize环境产生的

\documentclass{article}
\begin{document}
\begin{itemize}
  \item The individual entries are indicated with a black dot, a so-called bullet.
  \item The text in the entries may be of any length.
\end{itemize}
\end{document}

  

  有序列表:使用以下环境创建enumerate

\documentclass{article}
\begin{document}
\begin{enumerate}
  \item This is the first entry in our list.
  \item The list numbers increase with each entry we add.
\end{enumerate}
\end{document}

注意:每个条目面前必须有/item ,该命令会自动生成从 1 开始的数字有序列表标签值。

eg.6 将数学添加到latex当中

1.内联数学模式

\documentclass[12pt, letterpaper]{article}
\begin{document}
In physics, the mass-energy equivalence is stated 
by the equation $E=mc^2$, discovered in 1905 by Albert Einstein.
\end{document}

可以使用以下分隔符对之一:\( ... \)$ ... $\begin{math} ... \end{math},如以下示例所示:

\documentclass[12pt, letterpaper]{article}
\begin{document}
\begin{math}
E=mc^2
\end{math} is typeset in a paragraph using inline math mode---as is $E=mc^2$, and so too is \(E=mc^2\).
\end{document}

 2.外嵌数学模式

\documentclass[12pt, letterpaper]{article}
\begin{document}
The mass-energy equivalence is described by the famous equation
\[ E=mc^2 \] discovered in 1905 by Albert Einstein. 

In natural units ($c = 1$), the formula expresses the identity
\begin{equation}
E=m
\end{equation}
\end{document}

 更全面的例子:

\documentclass{article}
\begin{document}
Subscripts in math mode are written as $a_b$ and superscripts are written as $a^b$. These can be combined and nested to write expressions such as

\[ T^{i_1 i_2 \dots i_p}_{j_1 j_2 \dots j_q} = T(x^{i_1},\dots,x^{i_p},e_{j_1},\dots,e_{j_q}) \]
 
We write integrals using $\int$ and fractions using $\frac{a}{b}$. Limits are placed on integrals using superscripts and subscripts:

\[ \int_0^1 \frac{dx}{e^x} =  \frac{e-1}{e} \]

Lower case Greek letters are written as $\omega$ $\delta$ etc. while upper case Greek letters are written as $\Omega$ $\Delta$.

Mathematical operators are prefixed with a backslash as $\sin(\beta)$, $\cos(\alpha)$, $\log(x)$ etc.
\end{document}

注意:dots表示省略号

此外,同样可以使用包equation*提供的环境amsmath,需要将以下行添加到文档序言中:

\usepackage{amsmath}% For the equation* environment
\documentclass{article}
\usepackage{amsmath}% For the equation* environment
\begin{document}
\section{First example}

The well-known Pythagorean theorem \(x^2 + y^2 = z^2\) was proved to be invalid for other exponents, meaning the next equation has no integer solutions for \(n>2\):

\[ x^n + y^n = z^n \]

\section{Second example}

This is a simple math expression \(\sqrt{x^2+1}\) inside text. 
And this is also the same: 
\begin{math}
\sqrt{x^2+1}
\end{math}
but by using another command.

This is a simple math expression without numbering
\[\sqrt{x^2+1}\] 
separated from text.

This is also the same:
\begin{displaymath}
\sqrt{x^2+1}
\end{displaymath}

\ldots and this:
\begin{equation*}
\sqrt{x^2+1}
\end{equation*}
\end{document}

二 如何使用latex进行文档编排

eg.1 摘要

\documentclass{article}
\begin{document}
\begin{abstract}
This is a simple paragraph at the beginning of the 
document. A brief introduction about the main subject.
\end{abstract}
\end{document}

摘要之后需要插入段落进去,那么

  • 如何通过按两次“回车”键、结束当前行并插入后续空白行来创建新段落;
  • 如何通过使用命令插入手动换行符(\\双反斜杠)来开始新行而不开始新段落;或者,使用该\newline命令,具体而言,也就是命令\\\newline的差别

eg.2 用于根据类构建文档的命令book:

\documentclass{book}
\begin{document}

\chapter{First Chapter}

\section{Introduction}

This is the first section.

Lorem  ipsum  dolor  sit  amet,  consectetuer  adipiscing  
elit. Etiam  lobortisfacilisis sem.  Nullam nec mi et 
neque pharetra sollicitudin.  Praesent imperdietmi nec ante. 
Donec ullamcorper, felis non sodales...

\section{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra 
sollicitudin.  Praesent imperdiet mi necante...

\subsection{First Subsection}
Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\section*{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem...
\end{document}

注意:章节又可以进一步分为\subsection{...}\subsubsection{...}。节、小节等的编号是自动的,但可以通过使用相应命令的所谓加星号版本来禁用,该命令末尾有星号 (*),例如\section*{...}\subsection*{...}可以通过添加“ * ”来禁止自动添加编号

此外,LaTeX 文档类提供以下分段命令,每个特定类都支持相关子集:

  • \part{part}
  • \chapter{chapter}
  • \section{section}
  • \subsection{subsection}
  • \subsubsection{subsubsection}
  • \paragraph{paragraph}
  • \subparagraph{subparagraph}

但值得注意的是:命令\part以及\chapter仅在和文档类中可用。

eg.3 创建表格

\begin { center } 
\begin { tabular }{ ccc } 
 cell1 & cell2 & cell3 \\  
 cell4 & cell5 & cell6 \\   
 cell7 & cell8 & cell9    
 \end { tabular } 
\end { center }

其中,tabular是用来创建表格的命令,{c c c}该参数建议latex创建三列,并且每列中的文本必须居中。

“ c ”代表居中,“ r ”代表右对齐,“ l ”代表左对齐;

" & "是对齐符号,用于划分表格行内的各个表格单元格;

“ // “是结束表格行;

最后,表格包含在一个center环境中,使其在页面文本宽度内居中。

eg.4 添加边框

  • 要在列之间添加垂直线,请使用垂直线参数|
  • 水平线:\hline
  • 参数是{|c|c|c|}声明三个(居中)列,每个列由垂直线 | 分隔;通常\hline在第一行上方和最后一行下方放置一条水平线。(如下图)
    \begin { center } 
    \begin {表格}{ |c|c|c| }  
     \hline 
     cell1 & cell2 & cell3 \\  
     cell4 & cell5 & cell6 \\  
     cell7 & cell8 & cell9 \\  
     \hline 
    \end {表格} 
    \end { center }
\begin{center}
 \begin{tabular}{||c c c c||} 
 \hline
 Col1 & Col2 & Col2 & Col3 \\ [0.5ex] 
 \hline\hline     *加了两个横线
 1 & 6 & 87837 & 787 \\ 
 \hline
 2 & 7 & 78 & 5415 \\
 \hline
 3 & 545 & 778 & 7507 \\
 \hline
 4 & 545 & 18744 & 7560 \\
 \hline
 5 & 88 & 788 & 6344 \\ [1ex] 
 \hline
\end{tabular}
\end{center}

eg.5 标题、标签和参考文献

Table \ref{table:data} shows how to add a table caption and reference a table.
\begin{table}[h!]
\centering
\begin{tabular}{||c c c c||} 
 \hline
 Col1 & Col2 & Col2 & Col3 \\ [0.5ex] 
 \hline\hline
 1 & 6 & 87837 & 787 \\ 
 2 & 7 & 78 & 5415 \\
 3 & 545 & 778 & 7507 \\
 4 & 545 & 18744 & 7560 \\
 5 & 88 & 788 & 6344 \\ [1ex] 
 \hline
\end{tabular}
\caption{Table to test captions and labels.}
\label{table:data}
\end{table}

eg.6 添加目录

\documentclass{article}
\title{Sections and Chapters}
\author{Gubert Farnsworth}
\date{August 2022}
\begin{document}
  
\maketitle
  
\tableofcontents

\section{Introduction}
   
This is the first section.
      
Lorem  ipsum  dolor  sit  amet,  consectetuer  adipiscing  
elit.   Etiam  lobortisfacilisis sem.  Nullam nec mi et 
neque pharetra sollicitudin.  Praesent imperdietmi nec ante. 
Donec ullamcorper, felis non sodales...
       
\section*{Unnumbered Section}
\addcontentsline{toc}{section}{Unnumbered Section}  

*手动添加目录命令:\addcontentsline 命令用于手动向目录添加一个条目。
它的语法是 \addcontentsline{<文件类型>}{<节类型>}{<标题>}。
在这里,toc 表示目录文件(table of contents),
section 表示该条目的类别是节(section),
Unnumbered Section 是要显示在目录中的标题。

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra 
sollicitudin.  Praesent imperdiet mi necante...

\section{Second Section}
       
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra 
sollicitudin.  Praesent imperdiet mi necante...
\end{document}

章节、小节和章节自动包含在目录中。要手动添加条目(例如未编号的部分),请使用\addcontentsline示例中所示的命令。 

转载学习 持续更新补充

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值