2013年10月26日星期六

Some Useful Commands in The "tabular" Environment

When you are making tables in LaTeX, if you want to give interpolate some fancier features besides the standard and rigid outlook, there are some commands you are most like to encounter:

  • multirow: for creating a single row spanning over multiple rows
\multirow{Number of Rows}{*}{Content}
  • multicolum: for creating a single colum spanning over multiple columns
\multicolumn{Number of Rows}{Position of Alignment}{Content}
  • cline: for creating a horizontal line break with arbitrary width
\cline{Beginning Column-Ending Column}



Reference:

http://en.wikibooks.org/wiki/LaTeX/Tables

LaTeX中文支持-CJKutf8

在之前的一篇文章中介绍过一种使用LaTeX处理中文文档的方法,即在XeLaTeX编译环境下调用fontspec多语言包。但是我们会发现XeLaTeX编译常常花费比一般LaTex编译更多的时间,而且有时候我们并不是要整篇文章都使用中文,而只是在大段英文中插入少量的中文。这里将介绍另外一种常见的在LaTeX中解决中文的方法:CJKutf8。

CJK 有两个基本宏包:
CJK 和 CJKutf8,后者针对于UTF-8编码。由于多语言并行情况下,UTF-8编码更加通用,所以我们倾向于使用后者(中文的另一种常见编码是GBK):

\usepackage{CJKutf8}

如果要在文中插入中文,使用以下命令即可:

\begin{CJK}{UTF8}{gkai}

约翰有一辆车。
\end{CJK}

\begin{CJK}后的第一个参数是编码,由于之前我们已经选定了面向UTF-8的
CJKutf8,所以这里最好就使用UTF8。

第二个参数是中文字体,可以从以下四种字体中选择:bkai,bsmi,gkai,gbsn。前两者是Big5编码的明体(其实就是宋体和楷体字),他们的字库都非常小,许多汉字都无法正常显示。后两者分别是简体中文楷体字和宋体字,大部分汉字的显示都没有问题,可以根据个人喜好加以选择。


Reference:

http://tumutanzi.com/archives/tag/cjk
http://hi.baidu.com/jerryyou517/item/b3f2f52c74bd2f9ab7326344

2013年9月4日星期三

Footnote in Tables

With the standard configuration, one might not be able to insert a footnote with the plain command:

\footnote{...}

The result is that we can see the footnote icon, but the content is nowhere in the whole article. This is because the footnote command is sheltered by the tabular environment.

To achieve the possibility of inserting footnote in tables, we can actually cover the tabular environment with another handy environment, which is provided in the "footnote" package:

\usepackage{footnote}

\begin{savenotes}
\begin{table}
\begin{tabular}{|c|c|}
...
\end{tabular}
\end{table}
\end{savenotes}

Then within the table, the footnote command can be used freely like in other parts of the text.



Reference:
http://texblog.org/2012/02/03/using-footnote-in-a-table/

2013年7月31日星期三

Underlining in LaTex

The package "ulem" provides a nice facility for employing various types of underlines, both in the text and in mathematical formulas.

Some commonly applied commands:
  • \uline{a single underline}:单下划线
  • \uuline{a double underline}:双下划线
  • \uwave{a single under wavy line}:单波浪线
  • \sout{a single deleting line}:单删除线
  • \xout{a complex deleting block}:删除区域
  • \dashuline{a single under dotted line}:单下滑虚线
  • \dotuline{a single series of under dots}:单下滑点



Reference:

2013年3月20日星期三

LaTeX中文支持-fontspec

由于LaTeX设计之初,仅仅是考虑到了拉丁字母符号的输出。当它成为流行全球的编辑工具以后,避免不了针对其他语言符号的支持,中文就是其中之一。

网上有许多LaTeX在中文环境下的编译方法,最常用的即是使用CJK宏包。近期突然发现在XeLaTeX编译下,如果使用“fontspec”包也能顺利支持中文环境。“fontspec”的使用非常方便,很重要一个原因是它能够直接调用已经转载在电脑系统里面的各种字体,而不需要另外导入。一般电脑中标配的中文字体包括黑体(Hei),楷书(Kai),仿宋(STFangsong)等,具体的名称每个系统都不相同,需要自己单个查找。如果想查看自己电脑中的所有字体,可以使用以下命令:

fc-list

此外,如果希望使用系统中不存在的字库,“fontspec”也提供了导入方法:

\fontspec[ExternalLocation=dir]{字体.ttf}
  • 基本配置
那么,如何在tex文档中使用“fontspec”呢?具体方法如下:

\usepackage{fontspec}
\setromanfont{Kai}
\setmonofont[Scale=0.8]{AppleGothic Regular}

上面的第二行设置使用的是楷书,只需要在其中把“Kai”替换为自己喜欢的自己即可。第三行的设置目的是为了获得等宽字形。

如果需要在文中使用不同于默认设置的字体,也可以使用“fontspec”命令,只需要把更改的内容放在一个大括号范围内即可:

{
\fontspec{Hei}
黑体字的内容。。。
}
  • 自动换行问题
由此可知,使用“fontspec”来编辑中文环境非常方便,但是这种方法的一个常见问题就是不能正确断行,文字内容经常突兀地跑出页面边界。因此,人们通常同时使用下面两条命令:


\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt


这样,你就可以放心地使用LaTex来编辑自己的中文文档了。但是不要忘记编译的时候选用XeLaTeX,如果还是照常实用LaTex系统会报错。以上方法已经在Mac OS的TeXShop环境下测试成功。




Reference:
http://bbs.ctex.org/forum.php?mod=viewthread&tid=41552
http://forum.ubuntu.org.cn/viewtopic.php?t=61206

2013年1月25日星期五

Suppress Page Number in LaTex

Most LaTex document classes automatically import the page numbering system, which frees the user from the boring and tiring manual numbering process.

However, we might not always hope to include the page numbers, for instance, in some short abstracts, posters, or planning including only formulas. As a result, we would then need to suppress/remove/hide page numbers. The following codes could be handful:


\maketitle
\thispagestyle{empty}


This will simply suppress the page number on the exact page where you put the code. If you already use some external templates which define the numbering mechanism, you should add one line more in order to suppress the numbers at all pages:


\maketitle
\thispagestyle{empty}
\pagestyle{empty}

LaTeX Spacing

Normally when we are using some predefined LaTex template, the margin/space information is already well-specified. Sometimes, we might want to modify them in order to better fit our constraints, e.g., restricted page numbers.

The package "geometry" does exact this job, it is often included as:

\usepackage{geometry}

To assign more flexibility on it, the following code could be applied:

\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}

Values for each space (top, bottom, left, right) could be configured by the user himself.

There are also other packages for spacing setting, for instance, "sectsty", "mdwlist" and etc, more reference could be found here.