LaTeX入门——制作一份朴实无华的pdf文档

2023-11-22 05:40

本文主要是介绍LaTeX入门——制作一份朴实无华的pdf文档,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

  • 作者、标题、日期
  • 章节和段落
  • 插入目录
  • 枚举
  • 插入图片
  • 表格
  • 排版
  • 插入代码块
  • 数学公式
  • 树形图
  • 页边距

作者、标题、日期

文章部分开头\begin{document},结尾\end{document}

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

排版示例:
在这里插入图片描述

章节和段落

\maketitle 后面加文字:出现在文章最上方。
\section{你好中国} 第一个大部分,后面加文字,解释说明用。(1)
\subsection{Hello Beijing} (1.1)
\subsubsection{Hello Dongcheng District} (1.1.1)
\paragraph{Tian'anmen Square}, \subparagraph{Chairman Mao} 针对每个section分段。

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

排版示例:
在这里插入图片描述

插入目录

\maketitle 后加入\tableofcontents 自动生成目录。
排版示例:
在这里插入图片描述

枚举


```cpp
\begin{itemize}%圆点 罗列
\item 我的第一个项目
\item 我的第二个项目
\item 我的第三个项目
\end{itemize}\begin{enumerate}%带有数字标号的罗列
\item 我的第一个项目
\item 我的第二个项目
\item 我的第三个项目
\end{enumerate}\begin{description}%不带任何符号的罗列
\item 我的第一个项目
\item 我的第二个项目
\item 我的第三个项目
\end{description}

插入图片

在导言部分加入:
注意:引言区就是指的从\documentclass 开始到\begin[document]的这个部分的区域。

\usepackage{graphicx}
  1. 在文档中插入a.jpg文件。
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{a.jpg}
\end{document}

注意:如何插入图片呢?首先将编写的tex文件放入文件夹中,再将用到的图片同样导入文件夹中,这样就可以使用该图片了。

  1. 浮动体(更常用)
    \centering表示的是里面紧跟的内容都居中
    \includegraphics[]{}表示的插入图片
    \caption设置图片的一个编号以及为图片添加标题
\begin{figure}[ht]
\centering
\includegraphics[scale=0.6]{fullscreen.png}
\caption{this is a figure demo}
\label{fig:label}
\end{figure}
-------------------------------------注	h 此处(here)t 页顶(top)b 页底(bottom)p 独立一页(page)
--------------------------------------
  1. 多图并排
    设置库:
\ifCLASSOPTIONcompsoc
\usepackage[caption=false,font=normalsize,labelfon
t=sf,textfont=sf]{subfig}
\else
\usepackage[caption=false,font=footnotesize]{subfig}
\fi

设置图片:

\begin{figure*}[!t]
\centering
\subfloat[]{\includegraphics[width=2.5in]{luna.jpg}%
\label{fig_first_case}}
\hfil
\subfloat[]{\includegraphics[width=2.5in]{luna.jpg}%
\label{fig_second_case}}
\hfil
\subfloat[]{\includegraphics[width=2.5in]{luna.jpg}%
\label{fig_third_case}}
\hfil
\subfloat[]{\includegraphics[width=2.5in]{luna.jpg}%
\label{fig_forth_case}}
\caption{Simulation results for the network.}
\label{fig_sim}
\end{figure*}

表格

使用\begin{tabular}{|l|c|r|}\end{tabular} 建立表格。
\hline 分割线。
& 列结束。
\\ 行结束。

\begin{tabular}{|l|c|r|}\hline
操作系统& 发行版& 编辑器\\\hline
Windows & MikTeX & TexMakerX \\\hline
Unix/Linux & teTeX & Kile \\\hline
Mac OS & MacTeX & TeXShop \\\hline
通用& TeX Live & TeXworks \\\hline
\end{tabular}

在这里插入图片描述

排版

段尾加 \\,表示换行。
段尾不加 \\ ,直接空一行再输入,表示换行并且段首空格。

插入代码块

无高亮
插入如下格式:

\usepackage{listings}
\usepackage{xcolor}%代码设置
\lstset{numbers=left, %设置行号位置numberstyle=\tiny, %设置行号大小keywordstyle=\color{blue}, %设置关键字颜色commentstyle=\color[cmyk]{1,0,1,0}, %设置注释颜色escapeinside=``, %逃逸字符(1左面的键),用于显示中文breaklines, %自动折行extendedchars=false, %解决代码跨页时,章节标题,页眉等汉字不显示的问题xleftmargin=1em,xrightmargin=1em, aboveskip=1em, %设置边距tabsize=4, %设置tab空格数showspaces=false %不显示空格}\begin{lstlisting}[language=R]
> matrix(1:12,nrow=3,ncol=4)[,1] [,2] [,3] [,4]
[1,]   1   4   7   10
[2,]   2   5   8   11
[3,]   3   6   9   12
\end{lstlisting}

示例:
在这里插入图片描述

数学公式

行内$xx$ ,单独公式$$xxx$$
1.方程组:

F(n)=
\begin{cases}
1 & \text{n=0 or n=1}\\
F(n-1)+F(n-2) & \text{n>1}
\end{cases}

F ( n ) = { 1 n=0 or n=1 F ( n − 1 ) + F ( n − 2 ) n>1 F(n)= \begin{cases} 1 & \text{n=0 or n=1}\\ F(n-1)+F(n-2) & \text{n>1} \end{cases} F(n)={1F(n1)+F(n2)n=0 or n=1n>1
2.矩阵

\left\{
\begin{matrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{matrix}
\right\} \tag{2}

{ 1 2 3 4 5 6 7 8 9 } (2) \left\{ \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right\} \tag{2} 147258369(2)

树形图

找了一些实用模板。

  1. 普通树状图
\documentclass[border=10pt]{standalone} \usepackage{verbatim}\begin{comment}
:Title: A simple Tree
\end{comment}\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[sibling distance=10em,every node/.style = {shape=rectangle, rounded corners,draw, align=center,top color=white, bottom color=blue!20}]]\node {Formulas}child { node {single-line} }child { node {multi-line}child { node {aligned at}child { node {relation sign} }child { node {several places} }child { node {center} } }child { node {first left,\\centered,\\last right} } };
\end{tikzpicture}
\end{document}

在这里插入图片描述
2. 决策树

\documentclass[border=10pt]{standalone} 
\usepackage{verbatim}\begin{comment}
:Title: Decision tree\end{comment}
\usepackage{tikz}
\tikzset{treenode/.style = {shape=rectangle, rounded corners,draw, align=center,top color=white, bottom color=blue!20},root/.style     = {treenode, font=\Large, bottom color=red!30},env/.style      = {treenode, font=\ttfamily\normalsize},dummy/.style    = {circle,draw}
}
\begin{document}\begin{tikzpicture}[grow                    = right,sibling distance        = 6em,level distance          = 10em,edge from parent/.style = {draw, -latex},every node/.style       = {font=\footnotesize},sloped]\node [root] {Formula}child { node [env] {equation}edge from parent node [below] {single-line?} }child { node [dummy] {}child { node [dummy] {}child { node [env] {align\\flalign}edge from parent node [below] {at relation sign?} }child { node [env] {alignat}edge from parent node [above] {at several}node [below] {places?} }child { node [env] {gather}edge from parent node [above] {centered?} }edge from parent node [below] {aligned?} }child { node [env] {multline}edge from parent node [above, align=center]{first left,\\centered,}node [below] {last right}}edge from parent node [above] {multi-line?} };\end{tikzpicture}
\end{document}

在这里插入图片描述
3. 文件树


\documentclass{minimal}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\begin{comment}
:Title: Filesystem tree
\end{comment}
\usetikzlibrary{trees}
\begin{document}\tikzstyle{every node}=[draw=black,thick,anchor=west]\tikzstyle{selected}=[draw=red,fill=red!30]\tikzstyle{optional}=[dashed,fill=gray!50]\begin{tikzpicture}[%grow via three points={one child at (0.5,-0.7) andtwo children at (0.5,-0.7) and (0.5,-1.4)},edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}]\node {texmf}child { node {doc}}		child { node {fonts}}child { node {source}}child { node [selected] {tex}child { node {generic}}child { node [optional] {latex}}child { node {plain}}}child [missing] {}				child [missing] {}				child [missing] {}				child { node {texdoc}};\end{tikzpicture}
\end{document}

在这里插入图片描述

页边距

\usepackage{geometry}
\geometry{a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm}

总结:
层次结构大概梳理:

\begin{document}\section{1}\subsection{1.1}\paragraph{}\begin{enumerate}\begin{tacular}

尾声
到这里一份朴实无华的pdf就制作完成了,基本的功能已经具备。后面有更多的需求再补充。

这篇关于LaTeX入门——制作一份朴实无华的pdf文档的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/407921

相关文章

C#实现一键批量合并PDF文档

《C#实现一键批量合并PDF文档》这篇文章主要为大家详细介绍了如何使用C#实现一键批量合并PDF文档功能,文中的示例代码简洁易懂,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言效果展示功能实现1、添加文件2、文件分组(书签)3、定义页码范围4、自定义显示5、定义页面尺寸6、PDF批量合并7、其他方法

Java实现在Word文档中添加文本水印和图片水印的操作指南

《Java实现在Word文档中添加文本水印和图片水印的操作指南》在当今数字时代,文档的自动化处理与安全防护变得尤为重要,无论是为了保护版权、推广品牌,还是为了在文档中加入特定的标识,为Word文档添加... 目录引言Spire.Doc for Java:高效Word文档处理的利器代码实战:使用Java为Wo

使用Python实现Word文档的自动化对比方案

《使用Python实现Word文档的自动化对比方案》我们经常需要比较两个Word文档的版本差异,无论是合同修订、论文修改还是代码文档更新,人工比对不仅效率低下,还容易遗漏关键改动,下面通过一个实际案例... 目录引言一、使用python-docx库解析文档结构二、使用difflib进行差异比对三、高级对比方

从入门到精通详解Python虚拟环境完全指南

《从入门到精通详解Python虚拟环境完全指南》Python虚拟环境是一个独立的Python运行环境,它允许你为不同的项目创建隔离的Python环境,下面小编就来和大家详细介绍一下吧... 目录什么是python虚拟环境一、使用venv创建和管理虚拟环境1.1 创建虚拟环境1.2 激活虚拟环境1.3 验证虚

基于C#实现PDF转图片的详细教程

《基于C#实现PDF转图片的详细教程》在数字化办公场景中,PDF文件的可视化处理需求日益增长,本文将围绕Spire.PDFfor.NET这一工具,详解如何通过C#将PDF转换为JPG、PNG等主流图片... 目录引言一、组件部署二、快速入门:PDF 转图片的核心 C# 代码三、分辨率设置 - 清晰度的决定因

Python自动化处理PDF文档的操作完整指南

《Python自动化处理PDF文档的操作完整指南》在办公自动化中,PDF文档处理是一项常见需求,本文将介绍如何使用Python实现PDF文档的自动化处理,感兴趣的小伙伴可以跟随小编一起学习一下... 目录使用pymupdf读写PDF文件基本概念安装pymupdf提取文本内容提取图像添加水印使用pdfplum

Python从Word文档中提取图片并生成PPT的操作代码

《Python从Word文档中提取图片并生成PPT的操作代码》在日常办公场景中,我们经常需要从Word文档中提取图片,并将这些图片整理到PowerPoint幻灯片中,手动完成这一任务既耗时又容易出错,... 目录引言背景与需求解决方案概述代码解析代码核心逻辑说明总结引言在日常办公场景中,我们经常需要从 W

Java+AI驱动实现PDF文件数据提取与解析

《Java+AI驱动实现PDF文件数据提取与解析》本文将和大家分享一套基于AI的体检报告智能评估方案,详细介绍从PDF上传、内容提取到AI分析、数据存储的全流程自动化实现方法,感兴趣的可以了解下... 目录一、核心流程:从上传到评估的完整链路二、第一步:解析 PDF,提取体检报告内容1. 引入依赖2. 封装

C#高效实现Word文档内容查找与替换的6种方法

《C#高效实现Word文档内容查找与替换的6种方法》在日常文档处理工作中,尤其是面对大型Word文档时,手动查找、替换文本往往既耗时又容易出错,本文整理了C#查找与替换Word内容的6种方法,大家可以... 目录环境准备方法一:查找文本并替换为新文本方法二:使用正则表达式查找并替换文本方法三:将文本替换为图

Java高效实现Word转PDF的完整指南

《Java高效实现Word转PDF的完整指南》这篇文章主要为大家详细介绍了如何用Spire.DocforJava库实现Word到PDF文档的快速转换,并解析其转换选项的灵活配置技巧,希望对大家有所帮助... 目录方法一:三步实现核心功能方法二:高级选项配置性能优化建议方法补充ASPose 实现方案Libre