前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >LaTeX基础操作

LaTeX基础操作

原创
作者头像
esse LL
修改2024-03-12 16:12:27
1700
修改2024-03-12 16:12:27
举报
文章被收录于专栏:操作系统实验操作系统实验

LaTeX基础操作

一个简单的LaTeX文档通常包括导言区(preamble)和正文区(document body),导言区定义文档的类型、使用的宏包等

代码语言:latex
复制
\documentclass{article} % 定义文档类型为article
\begin{document}
Hello, LaTeX! % 这是正文区的内容
\end{document}

\documentclass指定文档的类别,比如articlebookreport

格式

  • 粗体:\textbf{文本}
  • 斜体:\emph{文本}\textit{文本}
  • 下划线:\underline{文本}(需要使用ulem宏包)
  • 脚注:\footnote{脚注内容}

标题

创建标题:\section\subsection\subsubsection

例如,\section{Introduction}会创建一个名为“Introduction”的标题

使用\section\subsection等命令定义的标题可以通过\tableofcontents命令自动生成目录

可以使用titlesec宏包自定义标题的字体、大小、间距等样式

段落

使用空行分隔不同的段落,使用\\进行强制换行

多个空格在LaTeX中通常被视为一个空格,插入多个空格使用\hspace{}命令

使用centerflushleftflushright环境设置居中、左对齐或右对齐

可以通过调整\parskip(段落间距)和\parindent(首行缩进)的值来改变段落的间距和缩进

列表

无序列表(itemize环境)

有序列表(enumerate环境)

每个列表项使用\item命令开始

代码语言:latex
复制
\begin{itemize}
  \item 第一项
  \item 第二项
\end{itemize}

调整列表间距:\itemsep(项间距)和\parsep(段落间距)

列表之间可以嵌套形成层级结构

自定义列表项的标签:使用\renewcommand自定义命令

表格

tabular列格式:lcr分别表示左对齐、居中对齐和右对齐,X表示列自动延伸

{c|c|c}表示三列居中对齐,列之间用竖线分隔

每一行数据用\\分隔,每一列数据用&分隔

代码语言:latex
复制
\begin{tabular}{c|c|c}
  A & B & C \\
  1 & 2 & 3 \\
\end{tabular}

跨行或跨列的单元格:\multirow\multicolumn

booktabs:设置表格线条

tabularx:指定表格的总宽度,并自动调整列宽以适应

图片

导言区加载graphicx宏包:

代码语言:latex
复制
\usepackage{graphicx}

正文区使用\includegraphics命令插入图片

代码语言:latex
复制
\includegraphics[选项]{文件名}

选项用来指定图片的各种属性,如大小、缩放比例等,文件名包括扩展名

图片大小与缩放

使用widthheight选项来指定图片的宽度和高度

代码语言:latex
复制
\includegraphics[width=5cm, height=4cm]{example.png}

插入图片宽度与文本宽度相同,高度自动调整,保持原始横纵比例:

代码语言:latex
复制
\includegraphics[width=\textwidth]{example.png}

缩放图片,设定scale比例:

代码语言:latex
复制
\includegraphics[scale=0.5]{example.png}

图片位置与对齐

figure环境

代码语言:latex
复制
\begin{figure}[htbp]
  \centering
  \includegraphics{example.png}
  \caption{示例图片}
  \label{fig:example}
\end{figure}

[htbp]是位置选项,h表示“此处”,t表示“顶部”,b表示“底部”,p表示“独立一页”

\centering居中,\caption设置标题,\label添加标签引用

图片旋转与裁剪

设置angle角度,trim边距,clip裁剪

代码语言:latex
复制
\includegraphics[angle=45, trim=1cm 2cm 3cm 4cm, clip]{example.png}

设置图片顺时针旋转45度,并从四边分别裁剪掉1厘米、2厘米、3厘米和4厘米

数学公式

行内公式:$1 \div 2$

单独公式:equation环境

引用

在文档中引用章节、图片、表格等

代码语言:latex
复制
% 为章节、图表等对象添加标签
\section{引言}\label{sec:intro}
\begin{figure}[htbp]
\centering
\includegraphics{example.png}
\caption{示例图片}\label{fig:example}
\end{figure}

% 在文中进行交叉引用,自动生成编号
As mentioned in Section \ref{sec:intro} and shown in Figure \ref{fig:example}, ...

自定义命令

代码语言:latex
复制
\newcommand{\mycontact}{esse LL \\ CS Department \\ contact@example.com}

自定义环境

三个参数:环境开始的代码、环境内容的代码和环境结束的代码

代码语言:latex
复制
% 自定义环境
\newenvironment{myenv}{\begin{quote}}{\end{quote}}

% 使用自定义环境
\begin{myenv}
这是自定义环境的内容。
\end{myenv}

高级应用

使用BibTeX管理参考文献

使用Makefile自动化编译等

使用LaTeX的Beamer类制作幻灯片

使用TikZ宏包绘制复杂的图形

使用PGFPlots宏包制作数据可视化图表

dp1A4排版

代码语言:LaTeX
复制
\documentclass[a4paper]{article}  
\usepackage[margin=1cm]{geometry} % 调整页边距为1cm  
\usepackage{enumitem} % 用于定制列表样式  
\usepackage{array} % 用于定制表格样式  
  
\begin{document}  
  
\begin{center}  
\Large{\textbf{Chess Offensive and Defensive Strategies Cheatsheet}}  
\end{center}  
  
\section*{Offensive Strategies}  
\begin{itemize}[leftmargin=*, nosep]  
  \item \textbf{King Hunt}:  
    \begin{itemize}[nosep]  
      \item Use your pieces to restrict the king's movement.  
      \item Create mating threats to force weaknesses.  
    \end{itemize}  
  \item \textbf{Pawn Breaks}:  
    \begin{itemize}[nosep]  
      \item Advance pawns to create weaknesses in the enemy camp.  
      \item Use pawn breaks to open lines for your pieces.  
    \end{itemize}  
  \item \textbf{Piece Activation}:  
    \begin{itemize}[nosep]  
      \item Move your pieces towards the center and kingside.  
      \item Avoid piece isolation.  
    \end{itemize}  
\end{itemize}  
  
\section*{Defensive Strategies}  
\begin{itemize}[leftmargin=*, nosep]  
  \item \textbf{King Safety}:  
    \begin{itemize}[nosep]  
      \item Castle early to protect the king.  
      \item Avoid exposing the king to attacks.  
    \end{itemize}  
  \item \textbf{Pawn Structure}:  
    \begin{itemize}[nosep]  
      \item Maintain a solid pawn structure to prevent weaknesses.  
      \item Avoid pawn islands.  
    \end{itemize}  
  \item \textbf{Piece Protection}:  
    \begin{itemize}[nosep]  
      \item Don't leave your pieces unprotected.  
      \item Use pawns to shield your important pieces.  
    \end{itemize}  
\end{itemize}  
  
\end{document}

dp2制作幻灯片

代码语言:LaTeX
复制
\documentclass{beamer}  
\usetheme{Madrid} % 使用Madrid主题,这是一个简洁的主题  
\usecolortheme{dolphin} % 使用dolphin颜色主题,与Madrid主题搭配  
  
\title{Chess Strategy: The Semi-Open Game with Rook on the Seventh Rank}  
\author{Your Name}  
\date{\today}  
  
\begin{document}  
  
\begin{frame}  
  \titlepage % 显示标题页  
\end{frame}  
  
\begin{frame}{Introduction to the Strategy}  
  \begin{itemize}  
    \item The semi-open game is a type of chess opening  
    \item It involves the deployment of the rooks on the seventh rank  
    \item This strategy aims to control the center and prepare for attack  
  \end{itemize}  
\end{frame}  
  
\begin{frame}{Key Elements of the Strategy}  
  \begin{enumerate}  
    \item Quick development of pieces  
    \item Control of key squares in the center  
    \item Preparation of the attack on the king  
  \end{enumerate}  
\end{frame}  
  
\begin{frame}{Example of Play}  
  % 这里可以插入棋盘和棋子的图片,或者使用其他方式展示游戏示例  
  \begin{center}  
    \includegraphics[width=0.5\textwidth]{chess_board_example.png}  
  \end{center}  
  \begin{itemize}  
    \item Starting position  
    \item Moves that demonstrate the strategy  
    \item Resulting position  
  \end{itemize}  
\end{frame}  
  
\begin{frame}{Conclusion}  
  \begin{itemize}  
    \item The semi-open game with rook on the seventh rank is a powerful strategy  
    \item It requires careful planning and execution  
    \item With practice, it can lead to successful games  
  \end{itemize}  
\end{frame}  
  
\begin{frame}[allowframebreaks]  
  \frametitle{References}  
  % 这里可以列出参考书籍、网站等  
  \begin{thebibliography}{9}  
    \bibitem{chessbook} \emph{Chess Strategy for Beginners}. Chess Publishing House, 2023.  
    \bibitem{chesswebsite} "Chess Openings Explained". \url{https://www.chess.com/openings}. Accessed on \today.  
  \end{thebibliography}  
\end{frame}  
  
\end{document}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • LaTeX基础操作
    • 格式
      • 标题
        • 段落
          • 列表
            • 表格
              • 图片
                • 图片大小与缩放
                • 图片位置与对齐
                • 图片旋转与裁剪
              • 数学公式
                • 引用
                  • 自定义命令
                    • 自定义环境
                      • 高级应用
                        • dp1A4排版
                          • dp2制作幻灯片
                          领券
                          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
                          http://www.vxiaotou.com