Chinaunix首页 | 论坛 | 博客
  • 博客访问: 776472
  • 博文数量: 217
  • 博客积分: 2401
  • 博客等级: 大尉
  • 技术积分: 2030
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-16 06:58
个人简介

怎么介绍?

文章分类

全部博文(217)

文章存档

2023年(2)

2022年(3)

2021年(28)

2020年(12)

2019年(5)

2018年(5)

2017年(5)

2016年(3)

2015年(6)

2014年(12)

2013年(16)

2012年(9)

2011年(6)

2010年(15)

2009年(30)

2008年(59)

我的朋友

分类:

2008-05-04 12:18:20

How to reference a figure or table within a LaTeX document

By Alvin J. Alexander, devdaily.com

Being able to automatically reference a figure within a Latex document is a very cool thing. This referencing capability lets you easily give readers the exact number of a figure, or tell them what page number a figure is located on with the use of a few simple commands (\label, \ref, and \pageref). The same technique works for referencing other objects within a Latex document, including tables and equations.

To begin with, let's assume that we have a figure defined somewhere in a Latex document like this:

\pagebreak
\begin{figure}[here]
\includegraphics[width=0.9\textwidth]{images/JobInformationDialog.jpg}
\caption{A prototype of the Job Information dialog}
\label{fig:jobInfoDialog}
\end{figure}

Let's further assume that as it turns out, in the current version of my document, this is figure 11-1 in the document, and it appears on page 69.

Now, somewhere else in my document I want to make a reference to this figure. If I just want to refer to the figure number, I can get it to appear by writing Latex text like this:

Please see Figure ~\ref{fig:JobInformationDialog} for a prototype blah blah blah

When I create my output document, such as when I create a PDF with pdflatex, this results in the following output:

Please see Figure 11-1 for a prototype blah blah blah

Pretty easy, eh?

Now, if I further want to refer to the page number that the image resides on, I can make a reference like this:

Please see Figure ~\ref{fig:JobInformationDialog} on page ~\pageref{fig:JobInformationDialog} for a prototype blah blah blah

If I now compile this statement with pdflatex I'll end up with a PDF that has this output:

Please see Figure 11-1 on page 69 for a prototype blah blah blah

The \ref and \pageref commands make it very easy to refer to figures that contain labels. As you've seen, the text referenced by the \ref and \pageref commands must match the text used within the label command. (It seems to be a convention to begin this text with the string "fig:". This isn't really necessary, but because these labels must be unique within a document, it helps to organize your labels, and separate your labels for figures from your labels for tables and equations.

This way of referencing things is very powerful, because you can use the same technique to makes reference to other objects, like tables and equations.

阅读(2444) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~