1. 程式人生 > >Latex 基礎教程六

Latex 基礎教程六

Latex中可以自動幫你生成目錄,使用section和subsection來生成目錄以及子目錄,示例如下圖所示:

\documentclass{article}

\begin{document}

\tableofcontents
\newpage

\section{Section}
Test

\subsection{Subsection}
Test

\end{document}

 編譯後如圖所示:

當你需要新增圖片或者表格的索引時,你也可以採取類似的操作,例如:

\documentclass{article}

\begin{document}

、、、

\begin{figure}
\caption{figure1}
\end{figure}

\begin{table}
\caption{table1}
\end{table}
、、、

\begin{appendix}
\listoffigures
\listoftables
\end{appendix}

\end{document}

編譯後得到如下圖所示:

有時候根據情況,需要在顯示目錄時顯示不同的層次,例如有的章節需要顯示到1.1.1這樣的3層子結構,有的只需要顯示到1.1這樣的兩層子結構,在latex中可以通過\setcounter{tocdepth}{X}命令,來設定目錄的級別。其中X指目錄的深度。

\setcounter{tocdepth}{1} % Show sections
\setcounter{tocdepth}{2} % + subsections
\setcounter{tocdepth}{3} % + subsubsections
\setcounter{tocdepth}{4} % + paragraphs
\setcounter{tocdepth}{5} % + subparagraphs

X=0意味著你的目錄不會展示任何內容,另外,在設定tocdepth命令時需要在文章的前言部分進行宣告。

下面是一個簡單的例子:

\documentclass{article}

\setcounter{tocdepth}{3}

\begin{document}
\tableofcontents
\newpage

\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\end{document}

編譯後如下圖所示:

如果您對目錄中標題的間距不滿意,更改目錄(通常是文件)間距的最簡單方法是使用setspace包。 首先在序言中新增\ usepackage {setspace}:

\documentclass{article}
\usepackage{setspace}


\begin{document}
\doublespacing
\tableofcontents
\singlespacing
\newpage

\section{Section1}


\section{Section2}
\subsection{Subsection2}
\subsubsection{Subsubsection3}

\end{document}

得到如下圖: