latex表格使用总结

文章详细介绍了如何在LaTeX文档中使用`tabular`,`longtable`,`booktabs`,`multirow`,`array`,`diagbox`等宏包创建和格式化表格,包括基本布局、跨页表格、带有注释和复杂格式的表格示例。
摘要由CSDN通过智能技术生成

参考博客
https://blog.csdn.net/TH_guan/article/details/124878398

测试了一下latex里面表格的用法

\documentclass{article}
\usepackage{booktabs} % 导入三线表需要的宏包
\usepackage{booktabs} % 导入三线表需要的宏包
\usepackage{longtable}% 导入跨页表格所需宏包
\usepackage{graphics}
\usepackage{threeparttable}
\usepackage[UTF8]{ctex} 
\usepackage{multirow}
\usepackage{array}
\usepackage{diagbox}
\usepackage{amsmath}
\begin{document}
	
%%%%%%%%%%% 1 %%%%%%%%%%%%%%
	\begin{tabular}{ccc}% 其中,tabular是表格内容的环境;c表示centering,即文本格式居中;c的个数代表列的个数
		\toprule %[2pt]设置线宽     
		a & b  &  c \\ %换行
		\midrule %[2pt]  
		1 & 2 & 3 \\
		4 & 5 & 6 \\
		7 & 8 & 9 \\
		\bottomrule %[2pt]     
	\end{tabular}
	
%%%%%%%%%%% 2 %%%%%%%%%%%%%%
\begin{longtable}{ccc}% 其中,tabular是表格内容的环境;c表示centering,即文本格式居中;c的个数代表列的个数
	\toprule %[2pt]设置线宽     
	a & b  &  c \\ %换行
	\midrule %[2pt]  
	1 & 2 & 3 \\
	4 & 5 & 6 \\
	7 & 8 & 9 \\
	\bottomrule %[2pt]     
\end{longtable}


%%%%%%%%%%% 3 %%%%%%%%%%%%%%
\begin{tabular}{|c|c|c|c|r|l|} \hline % 其中,|c|表示文本居中,文本两边有竖直表线。
	aaaaa & bbbbb & ccccc & ddddd & eeeee & fffff  \\ \hline
	1 & 2 & 3 & 4 & 5 & 6  \\ \hline
	7 &	8 &	9 &	10 & 11 & 12\\ \hline
	13 & 14 & 15 & 16 &	17 & 18\\ \hline
\end{tabular}

%%%%%%%%%%%4 %%%%%%%%%%%%%%
\begin{table}[!ht] % [!ht]表格在文本中放置的位置参数(努力放在当前位置,实在放不下,将放在下一页的顶部)
	\centering % 表格整体居中
	\caption{表格标题}
	\begin{tabular}{|c|c|c|c|r|l|} \hline % 其中,|c|表示文本居中,文本两边有竖直表线。
		aaaaa & bbbbb & ccccc & ddddd & eeeee & fffff  \\ \hline
		1 & 2 & 3 & 4 & 5 & 6  \\ \hline
		7 &	8 &	9 &	10 & 11 & 12\\ \hline
		13 & 14 & 15 & 16 &	17 & 18\\ \hline
	\end{tabular}
\end{table}


%%%%%%%%%%%5 %%%%%%%%%%%%%%
\begin{table}[!ht]
	
	\resizebox{\textwidth}{!}{ % 表格环境外部设置(头)
		\begin{tabular}{|c|c|c|c|r|l|} \hline % 其中,|c|表示文本居中,文本两边有竖直表线。
			aaaaa & bbbbb & ccccc & ddddd & eeeee & fffff  \\ \hline
			1 & 2 & 3 & 4 & 5 & 6  \\ \hline
			7 &	8 &	9 &	10 & 11 & 12\\ \hline
			13 & 14 & 15 & 16 &	17 & 18\\ \hline
		\end{tabular}
	}% 外部环境设置(尾)
	
\end{table}

%%%%%%%%%%%6 %%%%%%%%%%%%%%

\centering
\begin{threeparttable}
	\begin{tabular}{|c|c|c|c|c|c|} \hline
		
		班级层次&平均值	&个案数	&标准偏差	&最小值&最大值\\ \hline
		1&	53.74&	77	&29.819&	4	&96\\ \hline
		2	&57.60	&119&	28.971&	4	&100\\ \hline
		3	&58.94&	119&	29.930	&0&	100\\ \hline
		总计	&57.16	&315	&29.520&	0&	100\\ \hline
	\end{tabular}
	注: 1代表学习成绩低的同学;2代表学习层次居中的同学;3代表学习层次较好的同学。
\end{threeparttable}


%%%%%%%%%%%7 %%%%%%%%%%%%%%
\begin{tabular}{|p{6cm}<{\raggedleft}|p{4cm}<{\raggedright}|p{4cm}<{\centering}|} \hline
	
	汉字文本文本文本文本&汉字文本文本文本文本汉字文本文本文本文本&汉字文本文本文本文本汉字文本文本文本文本汉字文本文本文本文本\\ \hline
	汉字文本&汉字文本&汉字文本\\ \hline
	aaaaaaaaa&aaaaaaaaa&aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ \hline
	111111111&111111111&111111111111111111111111111111111111\\ \hline
	
\end{tabular}



%%%%%%%%%%8%%%%%%%%%%%%%%

\begin{table}[!ht]
	
	\center
	\begin{tabular}{|c|c|c|c|}\hline
		\multicolumn{1}{|c|}{\multirow{2}{*}{aaaa}} & \multicolumn{3}{c|}{bbbb}\\ \cline{2-4}
		& cccc  & dddd & eeee \\ \hline
		\multirow{2}{*}{aaaa}& 50 & 86 & 122  \\ \cline{2-4}
		\multirow{2}{*}{ }& 5 & 78  & 107   \\ \hline
		3& 25 & 48  & 101  \\ \hline
		4& 28 & 60 & 106  \\ \hline
	\end{tabular}
	
\end{table}


%%%%%%%%%%9%%%%%%%%%%%%%%
\centering
\begin{threeparttable}
	\begin{tabular}{|c|c|c|c|c|c|} \hline
		
		\diagbox{班级层次}{班级层次}&平均值	&个案数	&标准偏差	&最小值&最大值\\ \hline
		1&	53.74&	77	&29.819&	4	&96\\ \hline
		2	&57.60	&119&	28.971&	4	&100\\ \hline
		3	&58.94&	119&	29.930	&0&	100\\ \hline
		总计	&57.16	&315	&29.520&	0&	100\\ \hline
	\end{tabular}
	注: 1代表学习成绩低的同学;2代表学习层次居中的同学;3代表学习层次较好的同学。
\end{threeparttable}

	
%%%%%%%%%%%% 10 %%%%%%%%%%%%%%%%
\begin{table*}[!ht]
	%\usepackage{multirow}
	\center
	\caption{不同层次学生显著性分析}
	\begin{threeparttable}
		\resizebox{\linewidth}{!}{ 
			\begin{tabular}{|c|c|c|c|c|c|c|c|} \hline
				
				
				\multirow{2}{*}{} &\multirow{2}{*}{(I) 班级层次} &\multirow{2}{*}{(J) 班级层次} &\multirow{2}{*}{平均值差值 (I-J)} &\multirow{2}{*}{标准 错误} &\multirow{2}{*}{显著性} &\multicolumn{2}{c|}{95\% 置信区间}\\ \cline{7-8}
				
				\multirow{2}{*}{}&\multirow{2}{*}{} &\multirow{2}{*}{} &\multirow{2}{*}{} &\multirow{2}{*}{} &\multirow{2}{*}{} &上限&下限   \\ \hline
				
				\multirow{6}{*}{塔姆黑尼}&\multirow{2}{*}{1} &2&	-3.856	&4.313	&.753&	-14.26&	6.55  \\ \cline{3-8}
				\multirow{6}{*}{}&\multirow{2}{*}{} & 3	&-5.201&4.368&	.553&	-15.74&	5.34 \\ \cline{2-8}
				
				\multirow{6}{*}{}&\multirow{2}{*}{2} &1&	3.856&	4.313&	.753&	-6.55&	14.26  \\ \cline{3-8}
				\multirow{6}{*}{}&\multirow{2}{*}{} &  3&	-1.345	&3.819&	.979	&-10.53&	7.84\\ \cline{2-8}
				
				\multirow{6}{*}{}&\multirow{2}{*}{3} &1&	5.201&	4.368&	.553	&-5.34&	15.74  \\ \cline{3-8}
				\multirow{6}{*}{}&\multirow{2}{*}{} & 2	&1.345&	3.819&	.979&	-7.84	&10.53 \\ \hline
				
				\multirow{2}{*}{邓尼特 t(双侧)} & 1&	3	&-5.201&4.321	&.384&	-14.83	&4.43 \\ \cline{2-8}
				\multirow{2}{*}{} & 2&	3&	-1.345	&3.830	&.917	&-9.88	&7.19\\ \hline
				
			\end{tabular}
		}	
		\begin{tablenotes}
			\item[1] 1代表学习成绩低的同学;2代表学习层次居中的同学;3代表学习层次较好的同学。
		\end{tablenotes}
	\end{threeparttable}
\end{table*}


%%%%%%%%%%%% 11 %%%%%%%%%%%%%%%%
$$
\begin{array}{|c|c|c|c|}
	\hline   \text { 序号 }& \text { 对比方法 } & \text { 方法版本 } & \text { 方法官方地址 } \\
	\hline  1& \text { FastMNN } & 1.10 .0 & \begin{array}{l}
		\text { https://bioconductor.org/packages/ } \\
		\text { release/bioc/html/batchelor.html }
	\end{array}  \\
	\hline 2 &\text { Harmony } & 0.1 .0 & \begin{array}{l}
		\text { https://github.com/immunogenomics/harmony } \\
	\end{array}  \\
	\hline 3 & \text { Seurat }3 & 4.1 .1 & \text { https://satijalab.org/seurat/ }  \\
	\hline 4 &\text { Liger } & 1.0 .0 & \text { https://github.com/welch-lab/liger }  \\
	\hline 5 &\text { INSCT } & 0.0 .2 & \text { https://github.com/lkmklsmn/insct } \\
	\hline 6 &\text { BERMUDA } & \text {无版本号 } & \begin{array}{l}
		\text { https://github.com/txWang/BERMUDA } \\
	\end{array}  \\
	\hline 7 &\text { BBKNN } & 1.5 .1 & \text { https://github.com/Teichlab/bbknn } \\
	\hline 8 & \text { Scanorama } & 1.7 .2 & \begin{array}{l}
		\text { https://github.com/brianhie/scanorama } \\
	\end{array}  \\
	\hline 9 &\mathrm{scVI} & 0.8 .1 & \begin{array}{l}
		\text { https://github.com/scverse/scvi-tools } \\
	\end{array}  \\
	\hline 10 & \text { carDEC } & 1.0 .3 & \begin{array}{l}
		\text { https://github.com/jlakkis/CarDEC } \\
	\end{array} \\
	\hline 11 & \text { scDML } & 0.0 .1 & \begin{array}{l}
		\text { https://github.com/eleozzr/scDML } \\
	\end{array} \\
	\hline
\end{array}
$$

%%%%%%%%%%%%%%% 12%%%%%%%%%%%%%%%%%%%%%%%%%%%

{
	\renewcommand{\arraystretch}{1.2}
	\begin{table}
		\caption{测试表格
			\label{Table:测试}}
		$\begin{array}{|c|c|c|c|}
			\hline   \text { 序号 }& \text { 对比方法 } & \text { 方法版本 } & \text { 方法官方地址 } \\
			\hline  1& \text { FastMNN } & 1.10 .0 & \begin{array}{l}
				\text { https://bioconductor.org/packages/ } \\
				\text { release/bioc/html/batchelor.html }
			\end{array}  \\
			\hline 2 &\text { Harmony } & 0.1 .0 & \begin{array}{l}
				\text { https://github.com/immunogenomics/harmony } \\
			\end{array}  \\
			\hline 3 & \text { Seurat }3 & 4.1 .1 & \text { https://satijalab.org/seurat/ }  \\
			\hline 4 &\text { Liger } & 1.0 .0 & \text { https://github.com/welch-lab/liger }  \\
			\hline 5 &\text { INSCT } & 0.0 .2 & \text { https://github.com/lkmklsmn/insct } \\
			\hline 6 &\text { BERMUDA } & \text {无版本号 } & \begin{array}{l}
				\text { https://github.com/txWang/BERMUDA } \\
			\end{array}  \\
			\hline 7 &\text { BBKNN } & 1.5 .1 & \text { https://github.com/Teichlab/bbknn } \\
			\hline 8 & \text { Scanorama } & 1.7 .2 & \begin{array}{l}
				\text { https://github.com/brianhie/scanorama } \\
			\end{array}  \\
			\hline 9 &\mathrm{scVI} & 0.8 .1 & \begin{array}{l}
				\text { https://github.com/scverse/scvi-tools } \\
			\end{array}  \\
			\hline 10 & \text { carDEC } & 1.0 .3 & \begin{array}{l}
				\text { https://github.com/jlakkis/CarDEC } \\
			\end{array} \\
			\hline 11 & \text { scDML } & 0.0 .1 & \begin{array}{l}
				\text { https://github.com/eleozzr/scDML } \\
			\end{array} \\
			\hline
		\end{array}$
	\end{table}
}




\end{document}

结果如下
在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

注意最后两个例子,其实我用latex识别公式识别出的内容

\begin{array)
*****
\end{array}

这其中的部分,使用

$$
\begin{array)
*****
\end{array}
$$

还是

\begin{table}
\begin{array)
*****
\end{array}
\end{table}

把这部分内容包起来看自己需要,我目前发现前者没有办法给表加标题和引用,所以使用后者会更好一点

记录一个自己补充的表格,结果如下

\begin{array}{lll}
	\text { Leiden Group } & \text { Markers } & \text { Cell Type } \\
	\hline 0 & \text { IL7R } & \text { CD4 T cells } \\
	\hline 1 & \text { CD14, LYZ } & \text { CD14+ Monocytes } \\
	\hline 2 & \text { MS4A1 } & \text { B cells } \\
	\hline 3 & \text { CD8A } & \text { CD8 T cells } \\
	\hline 4 & \text { GNLY, NKG7 } & \text { NK cells } \\
	\hline 5 & \text { FCGR3A, MS4A7 } & \text { FCGR3A+ Monocytes } \\
	\hline 6 & \text { FCER1A, CST3 } & \text { Dendritic Cells } \\
	\hline 7 & \text { PPBP } & \text { Megakaryocytes } \\
	\hline
\end{array}
LaTeX中,可以使用\caption命令来设置表格的标题。根据引用中的示例代码,如果将\caption命令放在tabular环境之前,则表格标题会出现在表格上方;如果将\caption命令放在tabular环境之后,则表格标题会出现在表格下方。 另外,如果希望在表格标题前不显示序号,可以使用\caption*命令,如引用所示的示例代码。 总结起来,LaTeX中设置表格标题的格式的方法如下: 1. 将\caption命令放在tabular环境之前,表格标题会出现在表格上方; 2. 将\caption命令放在tabular环境之后,表格标题会出现在表格下方; 3. 使用\caption*命令可以在表格标题前不显示序号。 这些方法可以根据需要选择使用,以满足不同的排版要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [如何在LaTex当中给表格命名](https://blog.csdn.net/meowcyanimpostor/article/details/120810571)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [latex论文格式大全(一篇完整论文latex源文件,内容为网上资源)](https://download.csdn.net/download/m0_46384757/85631332)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值