latex中如何使用figure,ref,caption

\documentclass{article}
%注意需要导包
\usepackage{caption}
\usepackage{graphicx, subfig}
\begin{document}
 \begin{figure}
  \centering
  \includegraphics[width=.8\textwidth]{1.png} %1.png是图片文件的相对路径
  %\includegraphics[width=.8\textwidth]{Figure\1.png}
  \caption{best} %caption是图片的标题
  \label{img} %此处的label相当于一个图片的专属标志,目的是方便上下文的引用
\end{figure}
\end{document}
 

\ref最强大的功能在于引用
\label的作用是给这个标题定义一个供latex本身识别的编号, 方便其它地方引用。
比如在后文里要引用这幅图那么你在latex代码里应该输入重点内容:
This is figure \ref {img1}
这样做的好处是不用管这幅图是文中的第几幅图, 总能给出正确编号. (如果不加宏包就会显示图片的编号 加入宏包就会有超链接 点击可以跳转)

下列宏包的作用是为有超链接的地方设定样式:
\usepackage[colorlinks,linkcolor=red,anchorcolor=blue,citecolor=green]{hyperref}
%文件中可以有超链接的宏包并且可以为其设定样式

但是在我们使用{hyperref}的时候可能会遇到这样的错误:Improper alphabetic constant,在ctex中较为常见!

猜你喜欢

转载自blog.csdn.net/huang_shao1/article/details/82978210
今日推荐