1. 程式人生 > >latex中如何使用figure,ref,caption

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中較為常見!