LaTeX笔记

来自百合仙子's Wiki
跳转到导航 跳转到搜索

基本命令

命令后的空白

I read that Knuth divides the
people working with \TeX{} into
\TeX{}nicians and \TeX perts.\\
Today is \today.
I read that Knuth divides the people
working with TEX into TEXnicians and
TEXperts.
Today is August 2, 2008.

保护脆弱命令

有些命令,比如 \footnote,用在比如 \section 中时需要保护,使用以下形式:

\section{I am considerate
	\protect\footnote{and protect my footnotes}}

注意:即使这样,在脚注中放中文也不行。

脚注

在标题(chapter、section等)上使用脚注时,多次编译会造成目录也带有脚注。不希望如此,可以手工编辑 .toc 文件后再编译一次。

使用footmisc宏包,可以有更多选择。 另有一个叫footnote的宏包。

引用其它文件

\input filename

宏包

footmisc

该宏包提供了许多选项,可使脚注命令 \footnote{注释} 生成多种样式的脚注。其中:

perpage 为每页脚注单独排序
stable 避免章节标题中的脚注随同章节标题出现在目录或页眉之中(这个我没有试成功
side 将脚注改为边注
multiple 给正文中两个以上的并排脚注标号之间加上分隔逗号
para 将本页的所有脚注合为一个段落
symbol 将脚注的数字序号改为 * 号等不同的符号
ragged 不采用断词等方法使脚注文本右端对齐
marginal 使脚注首行不缩格
flushmargin 类似 marginal 选项,只是脚注序号更靠近脚注
hang 使脚注文本向右缩进一段距离
norule 取消正文与脚注之间的一条短横线

注意:该宏包与hyperref不兼容,会造成 hyperref 的注释链接位置不对。

hyperref

选项 colorlinkstrue 时为彩色链接,为默认的 false 时是彩色边框。

给书签加上链接,没有默认的红色边框

\usepackage[pdfborder={0 0 0}]{hyperref}

网址链接:

\url{http://www.wikibooks.org}
\href{http://www.wikibooks.org}{wikibooks home}

注意:该宏包与footmisc不兼容,会造成 hyperref 的注释链接位置不对。

选项 hyperfootnotes=false 可以去掉这个链接。

listings

注意:中英文混排时会发生英文跑到中文后面的情况。这时可以使用转义字符(在 \lstset 中定义的)。

有例子请看示例

you can modify several parameters that will affect how the code is shown. You can put the following code anywhere in the document (it doesn't matter whether before or after \begin{document}), change it according to your needs. The meaning is explained next to any line.

\lstset{ %
language=Octave,                % choose the language of the code
basicstyle=\footnotesize,       % the size of the fonts that are used for the code
numbers=left,                   % where to put the line-numbers
numberstyle=\footnotesize,      % the size of the fonts that are used for the line-numbers
stepnumber=2,                   % the step between two line-numbers. If it's 1 each line will be numbered
numbersep=5pt,                  % how far the line-numbers are from the code
backgroundcolor=\color{white},  % choose the background color. You must add \usepackage{color}
showspaces=false,               % show spaces adding particular underscores
showstringspaces=false,         % underline spaces within strings
showtabs=false,                 % show tabs within strings adding particular underscores
frame=single,	                 % adds a frame around the code
tabsize=2,	                 % sets default tabsize to 2 spaces
captionpos=b,                   % sets the caption-position to bottom
breaklines=true,                % sets automatic line breaking
breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace
escapeinside={\%*}{*)}          % if you want to add a comment within your code
}

The last line needs an explanation. You need it if you want to add some text within the code that will not be printed. Note that, by default, comments of the language you are inserting will be printed; the command escapeinside={A}{B} will define comments for listings only. All the code between the string "A" and "B" will be ignored. In the example above, the comments for Octave start with %, and they are going to be printed in the document unless they start with %*, but you have to remember to "close" the comment with another "*".

If you add the above paragraph, the following can be used to alter the settings within the code:

\lstset{language=C,caption=Descriptive Caption Text,label=DescriptiveLabel}

来源:英文维基教科书

dirtree

画树形用的,如

效果图
\documentclass{article}
\usepackage[BoldFont,SlantFont,CJKnumber,CJKchecksingle]{xeCJK}
\usepackage{dirtree}
\begin{document}
\setCJKmainfont{宋体}
\setCJKfamilyfont{hei}{黑体}

\dirtree{%
.1 /.
.2 bin.
.2 home.
.3 jeancome.
.4 texmf.
.5 tex.
.6 latex.
.7 dirtree.
.3 jeancomeson.
.3 jeancomedaughter.
.2 usr.
}
\end{document}

代码中的双引号

加上 lstset{basicstyle=\ttfamily} 就没有问题了,不过这种情况下,字体不是原来的了。

在导言区加上:

\usepackage[T1]{fontenc}

这样可以得到正确的双引号,而且代码的字体可以保持不变。

中文支持

LaTeX#中文UTF8只是支持UTF-8的部分中文。以下代码可支持中文标题、中文书签: (如果不用hyperref包的话,不需要这样。)

\documentclass[a4paper,11pt,titlepage]{article}
\usepackage{CJKutf8}
% 这个就可以在使用 hyperref 的同时用中文标题了
\usepackage[unicode,pdfborder={0 0 0}]{hyperref}
% unicode 让标题支持 Unicode,但这样书签文件的内容就有点不好读了
\begin{document}
\begin{CJK}{UTF8}{gbsn}
% 正文部分
\end{CJK}
\end{document}

这个是支持GB18030的,但中文书签不行:

\documentclass[12pt]{article}
\usepackage{CJK}
\begin{document}
\begin{CJK*}{GB}{gbsn}
\CJKtilde % 不要这句也可以
% 正文部分
\end{CJK*}
\end{document}

/usr/share/doc/texmf/latex/latex-cjk/examples 可以找到很多例子。

LaTeX中英文混排

来源:LaTeX学习

英文中换行的时候默认会加多一个空格, 而中文排版没有这个习惯, 如果使用

\begin{CJK}{GBK}{song}
内容 English 内容
\end{CJK}

排版中文时候每行都会有个多余的空格. 为了避免这个问题建议使用

\begin{CJK*}{GBK}{song}
\CJKtilde
内容~English~内容
\end{CJK*}

这时CJK* 环境默认会吃掉后面的未受保护的空格, 如果汉字后面需要空格, 这时就要用上符号~, \CJKtilde重新定义了波浪符~的意义, 使得这个符号不再代表一个不可断行的空格, 而是一个可断行的弹性距离, 加在中文和英文之间调整它们的距离(一般是一个 CJK 字符的 1/4 大小的空格). 也就是说要得到美观的中英文混排, 须使用大量的~, 这可能减慢输入的速度, 但养成习惯就好.

另外可以用 \standardtilde 可以让 ~ 恢复原来的定义, 不过一般而言没有必要这么做的. 你可以用 \nbs(non-breakabel space,LaTex 命令 \nonbreakspace 的缩写)来生成一个不可打断的空格.

还可以使用下面的命令 进行CJK*于CJK环境的切换:

\CJKspace      CJK*---->CJK
\CJKnospace    CJK----->CJK*

参见