LaTex插入图片、插入表格、插入公式

目录

一、插入图片

1)改变图片的大小、旋转图片

2)标签和交叉引用

3)插入单排多图无小标题共享大标题

4)单排变多排

5)图片的位置

6)图片横跨双栏

二、插入表格

1)合并单元格

2)三线表

3)表格横跨双栏

三、插入公式

1)常规使用

2)公式对齐

3)公式转行


一、插入图片

在.tex文件开头导入相应的宏包

\documentclass{article}
\usepackage{graphicx} % 导入图像的宏包、单图
\usepackage{subfigure} % 导入图像的宏包、子图
\graphicspath{
   
   {./images/}} % 告诉 LaTeX 这篇文档中的图片所存储的位置是主文档所在目录下的 images 文件夹。需要注意的是,目录的结尾也需要一个斜杠,并且路径是被包含在双大括号之间。

% 你还可以设置多个路径,如果文档的图片被存储在多个文件夹中。例如,如果有两个文件夹images1和images2,使用下面的命令:\graphicspath{ {./images1/}{./images2/} }

文中插入教程:

子图插入:(\includegraphics{1.jpg}是真正插入图片的那个命令,可以有后缀,也可以直接文件名)

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfigure}
\graphicspath{ {./images/} }

\begin{document}
	The universe is immense and it seems to be homogeneous, in a large scale, everywhere we look at.
	
	\begin{figure}
		\centering % 表示居中
		\subfigure[An example of an individual figure sub-caption.]{%
			\resizebox*{5cm}{!}{\includegraphics{1.jpg}}}\hspace{5pt}
		\subfigure[A slightly shorter sub-caption.]{%
			\resizebox*{5cm}{!}{\includegraphics{1.jpg}}}
		\caption{Example of a two-part figure with individual sub-captions
			showing that captions are flush left and justified if greater
			than one line of text.} \label{sample-figure}
	\end{figure}
	
	There's a picture of a galaxy above
\end{document}

插入单图:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfigure}
\graphicspath{ {./images/} }

\begin{document}
	The universe is immense and it seems to be homogeneous, in a large scale, everywhere we look at.
	
	\begin{figure}
		\centering % 表示居中
		\includegraphics[height=4.5cm,width=9.5cm]{1.jpg}
		\caption{Example of a two-part figure with individual sub-captions
			showing that captions are flush left and justified if greater
			than one line of text.} \label{sample-figure}
	\end{figure}
	
	There's a picture of a galaxy above
\end{document}

可以使用 \includegraphics[width=1\linewidth]{1.jpg} 获得相对高宽。

1)改变图片的大小、旋转图片

命令\includegraphics[scale=1.5]{1.jpg}会把图片lion-logo插入到文档中,额外的参数scale=1.5会把图片的大小变为原本的1.5倍。

也可以指定图片的长宽:\includegraphics[width=3cm, height=4cm]{ 1.jpg}

2)标签和交叉引用

与LaTeX文档中的许多其他元素相同(例如公式、表格等),图片也可以在文本中被引用。你只需要简单地对其添加一个标签就可以了,然后使用这个标签来在文本中引用这个图片。

\begin{figure}[h]
    \centering
    \includegraphics[width=0.25\textwidth]{1.jpg}
    \caption{a nice plot}
    \label{sample-figure}
\end{figure}

As you can see in the figure \ref{sample-figure}, the 
function grows near 0. Also, in the page \pageref{sample-figure} 
is the same example.

\label{sample-figure}这个命令设置了图片的标签。\pageref{sample-figure}这个命令会输出图片所在的页数。

一般在论文中,我们都是使用~来代替空格,保证Fig.” 和图表编号始终在一起显示,即Fig.~\ref{sample-table}

3)插入单排多图无小标题共享大标题

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfigure}
\graphicspath{ {./images/} }

\begin{document}
	The universe is immense and it seems to be homogeneous, in a large scale, everywhere we look at.
	
	\begin{figure}
	\subfigure[]{
		\includegraphics[width=2.5cm,height=2.5cm]{1.jpg} \label{Fig.1(b)}
	}
	\hspace{2mm}
	\subfigure[]{
		\includegraphics[width=2.5cm,height=2.5cm]{1.jpg} \label{Fig.1(b)}
	}	
	\hspace{2mm}
	\subfigure[]{
		\includegraphics[width=2.5cm,height=2.5cm]{1.jpg} \label{Fig.1(b)}
	}
	
	\caption{Geographical location and relationship of four types of bike stations }
	\end {figure}
	
\end{document}

注意:不要有回车enter,否则图片会自动跳到下一行

4)单排变多排

在需要多排图的后面加上 回车 就可以了

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfigure}
\graphicspath{ {./images/} }

\begin{document}
	The universe is immense and it seems to be homogeneous, in a large scale, everywhere we look at.
	
	\begin{figure}
	\centering
	\subfigure[]{
		\includegraphics[width=2.5cm,height=2.5cm]{1.jpg} \label{Fig.1(b)}
	}
	\hspace{2mm}
	\subfigure[]{
		\includegraphics[width=2.5cm,height=2.5cm]{1.jpg} \label{Fig.1(b)}
	}
	
	\subfigure[]{
		\includegraphics[width=2.5cm,height=2.5cm]{1.jpg} \label{Fig.1(b)}
	}
	\hspace{2mm}
	\subfigure[]{
		\includegraphics[width=2.5cm,height=2.5cm]{1.jpg} \label{Fig.1(b)}
	}

	\caption{Geographical location and relationship of four types of bike stations }
	\end {figure}
	
\end{document}

5)图片的位置

Latex提供了一些命令来控制图片的位置。我们可以通过使用\begin{figure}[位置选项]来控制图片的位置。位置选项可以有h、t、b、p、!这五个,分别表示以下含义:

  • h:表示放在当前位置,不过有时由于论文的格式限制,可能放不下。
  • t:表示放在页面的顶部。
  • b:表示放在页面的底部。
  • p:表示放在单独一页。
  • !:表示可以忽略一些限制,例如允许超过页面上限等。

例子:如用选项 [hbp]就表示允许浮动体出现在环境所在位置、页面底部或单独一页,但不允许出现在一页顶部。

\begin{figure*}[!htb]
...
\end{figure*}
  • 换行:和段落类似,空一行就是换行。
  • 居中:\centering
  • 图像位置自适应[!htb],关于这个的更多描述需要参照latex的图像位置设置之类的,不过该操作是很常用的。
  • 间距设置:\hspace和\vspace。
	\vspace{-0.2cm}  %调整图片与上文的垂直距离
	\setlength{\abovecaptionskip}{-0.2cm}   %调整图片标题与图距离
	\setlength{\belowcaptionskip}{-0.2cm} %调整图片标题与下文距离

6)图片横跨双栏

常规情况下,双栏文章中图片只会占其中一栏,如果希望图片横跨双栏,只需要将\begin{figure}和\begin{figure}替换为\begin{figure*}和\begin{figure*},即(表格同理)。

\begin{figure*}[!htbp]
\centering
\includegraphics[width=0.5\textwidth]{图像链接}\\
\caption{图像标题}
\label{图像标签}
\end{figure*}

二、插入表格

在线表格插入:MediaWiki 表格 转换为 LaTeX 表格 - 在线表格转换工具Create LaTeX tables online – TablesGenerator.com(两个对比修改)

表的插入和插入图片类似

\documentclass[]{interact} % 导入自己的样式,如果没有可以使用\documentclass[]{article}

\begin{document}
	
\begin{table}[!htbp]
	\centering        % 表格居中
	\label{tablename} % 大括号内定义图片标签,用于正文引用
	\caption{Caption} % 大括号内定义图片标题
	\vspace{5pt}      % 大括号内设置表格与正文之间的间距
	\begin{tabular}{l|cc|cc} % tabular定义了表格本身 {l|cc|cc}定义了表格共有6列,以及每一列的对齐方式(l左对齐,c居中,r右对齐),且第一列和第二、三列和第四、五列之间用竖线隔开。如果是三列中且没有竖线隔开就是{cccc}。
		\hline % 定义表格的横线
		~ & sa & ~ & ~ & ~ \\ \hline 
		cla & as & aw & ae & ac \\ \hline % 定义每一行单元格内容,其中,第一个单元格前不加“&”,其他每个单元格前加“&”,“\\”表示换行
		a & 11 & 12 & 12 & 13 \\ \hline
		b & 45 & 54 & 12 & 42 \\ \hline
	\end{tabular}
\end{table}
	
\end{document}

1)合并单元格

首先需要在文件首部导言区引用:(可以先不导入,如果报错在导入)

\usepackage{multirow}
  • 合并行单元格

\multirow{行数}{宽度}{单元格内容}
行数:合并的同一列单元格的行数
宽度:合并后的单元格的宽度,不指定时用*代替
单元格内容:默认左对齐,为了指定对齐方式,可以使用[\centering 居中;\raggedleft 右对齐;\raggedright 左对齐]的规则。

 \multirow{2}{*}{A} %合并同一列两行的单元格,不指定宽度,单元格内写“A”(默认左对齐)
 \multirow{2}{1cm}{A} %合并同一列两行的单元格,单元格宽度为1cm,单元格内写“A”(默认左对齐)
 \multirow{2}{*}{\centering A} %合并同一列两行的单元格,单元格宽度为1cm,单元格内写“A”且指定居中对齐
  • 合并列单元格

\multicolumn{列数}{对齐方式}{单元格内容}
列数:合并的同一行单元格的列数
对齐方式:和表格的对齐方式相似,使用"c"/“r”/"l"控制居中、右对齐和左对齐,还可以在对齐符号左右加“|”控制是否添加竖线。

 \multicolumn{2}{c}{B} %合并同一行两列的单元格,单元格内写“B”并居中
 \multicolumn{2}{r|}{B} %合并同一行两列的单元格,单元格内写“B”并右对齐,且在右侧画竖线

演示

\documentclass[]{interact} % 导入自己的样式,如果没有可以使用\documentclass[]{article}
\usepackage{multirow}
\begin{document}
	
\begin{table}[!htbp]
	\centering
	\caption{Caption}
	\label{tablename}
	\vspace{5pt}
	\begin{tabular}{cccccc}\hline
		\multirow{5}{1cm}{\centering C} &\multirow{2}{*}{Approach} &\multicolumn{2}{c}{A} &\multicolumn{2}{c}{B} \\
		\cline{3-6}   %\cline同\hline,但在大括号内指定横线跨越的列的范围,如这里是跨越第三列到第六列
		& & Acc & F1 & Acc &F1 \\ 
		\cline{2-6} 
		&a &1 &2 &3 &4 \\
		&b &5 &6 &7 &8\\
		&c &1 &2 &3 &4 \\
		\hline
		\multirow{3}{*}{\centering D}
		&d &5 &6 &7 &8\\
		&e &1 &2 &3 &4 \\
		&f &5 &6 &7 &8\\
		\hline
	\end{tabular}
\end{table}

\end{document}

2)三线表

首先需要在文件首部导言区引用

\usepackage{booktabs}

此外,只需将以上表格中的\hline或\cline{}进行替换就可以了

方法1:

\toprule[1pt] 替换表格顶部的\hline
\midrule[1pt] 替换表格中间的\hline
\bottomrule[1pt] 替换表格底部的\hline
中括号内指定了线条宽度

\begin{table}[t]
\centering
\caption{Caption} 
\label{samples}
\vspace{5pt}
\begin{tabular}{cccc}
\toprule[2pt] %顶部
A &B &C &D\\
\midrule[1pt]
1   &2 &3 &4\\
1   &2 &3 &4\\
1   &2 &3 &4\\
\bottomrule[2pt]
\end{tabular}
\end{table}

方法2:

除了用\toprule和\bottomrule替换顶部和底部的横线外,使用\cmidrule{2-4}或\cmidrule[宽度]{2-4}替换表格中间的\cline{2-4},其中大括号内指定了横线跨越的列的范围,不指定宽度会得到一个比1pt更细的线。

\begin{table}[t]
\centering
\caption{Caption} 
\label{samples}
\vspace{5pt}
\begin{tabular}{cccc}%% l:表示左对齐 r:表示右对齐 c:表示居中
\toprule[2pt]
A &B &C &D\\
\cmidrule[1pt]{2-4}
1   &2 &3 &4\\
1   &2 &3 &4\\
1   &2 &3 &4\\
\bottomrule[2pt]
\end{tabular}
\end{table}

3)表格横跨双栏

常规情况下,双栏文章中表只会占其中一栏,如果希望表横跨双栏,只需要将\begin{table}和\begin{table}替换为\begin{table*}和\begin{table*}

三、插入公式

在线公式编辑:在线LaTeX公式编辑器-编辑器 (latexlive.com)Online LaTeX Equation Editor - create, integrate and download (codecogs.com)

1)常规使用

  • 句内公式
正文$公式$正文
  • 段间公式-单行
\begin{eqnarray}
公式
\end{eqnarray}

  • 段间公式-多行
\begin{eqnarray}
公式 \\
公式 \\
公式
\end{eqnarray}

2)公式对齐

段间多行公式时,为了对齐公式,通常令多行公式在等号处对齐,操作方法是在每行公式的等号前后加&

\begin{eqnarray}
左边公式 &=& 右边公式 \\
左边公式 &=& 右边公式 \\
左边公式 &=& 右边公式
\end{eqnarray}

3)公式转行

当公式太长时,受到页面宽度的显示,可能会面临需要对公式转行的问题,可套用一下公式:(其中,\nonumber是防止公式在该行自动编号,如果需要编号可省略;&&是为了实现公式对齐

左边公式 &=& \left( {第一行公式} \right. \nonumber \\ 
		 &&  \left. {第二行公式} \right. \nonumber \\ 
		 &&  \left. {第三行公式} \right)
  • 未转行的公式
\begin{eqnarray}
A&=&B+C+M+N \\
D&=&E+F+O+P\\
A+D&=&B+C+M+N+E+F+O+P
\end{eqnarray}

  • 转行的公式
\begin{eqnarray}
A&=&B+C+M+N \\
D&=&E+F+O+P\\
A+D&=&\left({B+C+M+N} \right. \nonumber\\  
   &&\left.{+E+F+O+P} \right)  
\end{eqnarray}

猜你喜欢

转载自blog.csdn.net/qq_45100200/article/details/135191515