Labels and cross-references · ฉลากและการอ้างอิงข้าม
Never write "see Section 3" by hand
- If you write a number by hand and later add a section, every number is wrong.
- LaTeX solves this with labels. Tag something:
- The name
sec:methodsis just a nickname you choose.
อย่า ever เขียน "ดูiption 3" ด้วยมือ
- หากคุณเขียนตัวเลขด้วยมือและภายหลังเพิ่มบทเรียนใหม่ ทุกตัวเลขจะผิด
- LaTeX แก้ปัญหานี้ด้วย labels tagging某สิ่ง:
\section{Methods}\label{sec:methods}
- ชื่อ
sec:methodsเป็นเพียงชื่อเล่นที่คุณเลือก
Refer to it anywhere
- Then point at it with
\ref— LaTeX inserts the current number:
- The
~is a space that never breaks across lines, so "Section" and its number stay together.
อ้างอิงถึงมันได้ทุกที่
- จากนั้นชี้ไปที่มันด้วย
\ref— LaTeX จะแทรก หมายเลขปัจจุบัน:
As shown in Section~\ref{sec:methods}, ...
~เป็นช่องว่างที่ไม่แตกหักข้ามบรรทัด ดังนั้น "Section" และหมายเลขของมันจะอยู่ด้วยกัน
It needs two passes
- On the first compile LaTeX learns the numbers; on the second it fills them in.
- Our Run does this for you automatically. (The same trick powers a table of contents.)
มันต้องใช้สองรอบ compilation
- รอบแรก LaTeX เรียนรู้หมายเลข; รอบที่สองมันเติมตัวเลขลงไป
- Run ของเราทำสิ่งนี้ให้คุณอัตโนมัติ (เทคนิคเดียวกันนี้ขับเคลื่อนสารบัญ)
Common mistakes
- Put
\label{...}after what you want to name, then refer to it with\ref{...}. - Compile twice so cross-references settle to the right numbers.
ข้อผิดพลาดที่พบบ่อย
- วาง
\label{...}หลังสิ่งที่ต้องการตั้งชื่อ, แล้วอ้างอิง它以\ref{...} - Compile สองครั้งเพื่อให้ cross-references Settled to the right numbers
Label the Methods section with \label{sec:methods}, then refer to it from the last line with \ref{sec:methods}. LaTeX fills in the correct number for you. · กำหนดชื่อส่วน Methods ด้วย \label{sec:methods} จากนั้นอ้างอิงถึงมันในบรรทัดสุดท้ายด้วย \ref{sec:methods}. LaTeX จะเติมเลขที่ถูกต้องให้โดยอัตโนมัติ
The same numbering machinery builds a table of contents. Add \tableofcontents as the first line of the body — LaTeX lists every section automatically. · ระบบการกำหนดหมายเลขเดียวกันนี้ยังสร้าง สารบัญ ได้ เพิ่ม \tableofcontents เป็นบรรทัดแรกของเนื้อหา — LaTeX จะแสดงทุกส่วนโดยอัตโนมัติ