LaTex 学习笔记(三)表格以及添加目录

LaTex 学习笔记之表格以及添加目录

下面的示例展示了如何在LaTeX中创建表,包括添加行(规则)和目录表。

Tables

首先展示一个基本的表格
\begin{center}
    \begin{tabular}{c c c}
        1 & 2 & 3 \\
        4 & 5 & 6
    \end{tabular}
\end{center}
\end{document}

结果为
在这里插入图片描述

表格环境是创建表的默认LATEX方法。您必须为该环境指定一个参数,在本例中为{c c c},该参数建议LATEX将有三列,并且每列中的文本必须居中。您还可以使用r来对文本进行右对齐,使用l来对文本进行左对齐。对齐符号&用于分隔表行内的各个表单元格。要结束一个表行,使用新的行命令\\。我们的表包含在center环境中,使其在页面的文本宽度内居中。

例如

\begin{center}
    \begin{tabular}{l r c}
        hello & word & latex is \\
        hhh & handsome & 6
    \end{tabular}
\end{center}

在这里插入图片描述

设置边框

表格环境支持水平线和垂直线(规则)作为表格的一部分

  • 要在行上方和行下方添加水平规则,请使用\hline命令
  • 要在列之间添加垂直规则,请使用垂直线参数 |

例如

\begin{center}
    \begin{tabular}{|c|c|c|}
        \hline
        hello & word & latex is \\
        \hline
        hhh & handsome & 6\\
        \hline
    \end{tabular}
\end{center}

结果为
在这里插入图片描述

注意:在LATEX中创建表可能很耗时,因此您可能希望使用TablesGenerator.com在线工具为表导出LATEX代码。

你可以用和图片差不多的方式给表格加上标题和引用。唯一的区别是,使用的不是图环境,而是表环境。

例如:

Table \ref{table:data} shows how to add a table caption and reference a table.
\begin{table}[h!]
    \centering
    \begin{tabular}{c|c}
       11  & 22 \\
       44  & 33
    \end{tabular}
    \caption{Caption}
    \label{table:data}
\end{table}

结果:
在这里插入图片描述

添加目录表

创建目录表非常简单,因为命令\tableofcontents几乎为您完成了所有工作

例如

\documentclass{article}
\title{Sections and Chapters}
\author{longlongxiao}
\date{August 2022}

\begin{document}

\maketitle

\tableofcontents

%\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{Subsection}
Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

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

\begin{center}
    \begin{tabular}{c c c}
        1 & 2 & 3 \\
        4 & 5 & 6
    \end{tabular}
\end{center}

\begin{center}
    \begin{tabular}{l r c}
        hello & word & latex is \\
        hhh & handsome & 6
    \end{tabular}
\end{center}

\begin{center}
    \begin{tabular}{|c|c|c|}
        \hline
        hello & word & latex is \\
        \hline
        hhh & handsome & 6\\
        \hline
    \end{tabular}
\end{center}

Table \ref{table:data} shows how to add a table caption and reference a table.
\begin{table}[h!]
    \centering
    \begin{tabular}{c|c}
       11  & 22 \\
       44  & 33
    \end{tabular}
    \caption{Caption}
    \label{table:data}
\end{table}
\end{document}

结果
在这里插入图片描述
点这个按钮可以下载你的论文
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是一只小小小小龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值