2013年10月27日星期日

Maybe You’re Just Making Excuses

Maybe it's my own fault.

Maybe I led you to believe it was easy when it wasn't.

Maybe I led you to believe that my highlights started from the free throw line and not in the gym.

Maybe I made you believe that every shot I took was a game-winner, that my game was built on flash and not fire.

Maybe it's my fault that you didn't see that failure gave me strength, that my pain was my motivation.

Maybe I led you to believe that basketball was a God-given gift and not something I worked for every single day of my life.

Maybe I destroyed the game or maybe you're just making excuses.




Counter Numbering Configuration in LaTeX

When using some template to write our documents, especially those classical and well-structured ones, such as PhD Thesis, we might run into some undesirable features bound to that template. For instance, the counter of footnote is reset for each page, namely if you have 10 footnotes created by the standard "\footnote" commands all over your document, but they are distributed on 10 different pages, then the numberings will all be "1", instead of "1", "2",...,"10". This also happens for linguistic examples created by the "linguex" package, whose counter will be reset for every chapter.

In LaTeX, the objects coming with an automatic numbering, such as tables, figures, footnotes, etc., contain an internal counter definition:

  1. \newcounter{counter_name}
  2. \newcounter{counter_name}[resetting_environment]
The second differs from the first by adding a resetting environment, which appears as once the environment changes, the counter will be reset to 0. That is why some counters are continuous across the whole document, while some others are reset at certain point.


Since the initialization of the counter is embedded in the definition of each object, which is really difficult to modify directly, so in order to be completely flexible on configuring the numbering, we can use the "chngcntr" package. There are basically a pair of commands that we can use:

  • \counterwithin{1}{2} or \counterwithin*{1}{2}
    • These commands help to add a resetting environment to a counter without it
    • The first compulsory argument denotes the counter name, for instance "footnote" for footnotes, "table" for tables, "ExNo" for linguistic examples, etc.
    • The second compulsory argument denotes the environment within which you want to reset the counter, for instance, "chapter", "section", etc.
  • \counterwithout{1}{2} or \counterwithout*{1}{2}
    • These commands help to eliminate a resetting environment for a counter under its influence
    • Same as above, the first compulsory argument denotes the counter name
    • Same as above, the second compulsory argument denotes the environment within which you want to eliminate the resetting effect for a counter

The starred version, "\counterwithin*" or "\counterwithout*" will suppress the redefinition of another counter-related command "\the{counter_name}", for more details, please look at the reference.




Reference:

http://mirrors.linsrv.net/tex-archive/macros/latex/contrib/chngcntr/chngcntr.pdf
http://en.wikibooks.org/wiki/LaTeX/Counters

Common Units for Spaces in LaTeX

There are many places where we need specify exact spaces in LaTeX, for instance, inserting an image, arranging the position of several tables, etc. Normally in the template codes on Internet, people will find units such as "cm" and "in", which stand for "centimeter" and "inch" respectively. Then are there other units? And if yes, what do they mean?
  1. in - inches 
  2. mm - millimeters 
  3. cm - centimeters 
  4. pt - points (about 1/72 inch) 
  5. em - approximately the width of an "M" in the current font 
  6. ex - approximately the height of an "x" in the current font



Conflict between The "ulem" Package and Bibliography

As we mentioned in a previous article, the "ulem" package provides various convenient ways to specify underlines.

However, after importing the "ulem", one might find the bibliography changes in an unexpected way: the strings that should actually be italicized are now underlined. That is because the italicized subparts of the bibliography is configured by the "\emph" command, and with the "ulem" package, "\emph" is redefined as underlined.

To avoid the annoying conflict, we just need to specify a normal emphasis option for the "ulem" package:

\usepackage[normalem]{ulem}

This is indicated at the beginning of the "ulem" documentation.





Reference:

http://mirror.ibcp.fr/pub/CTAN/macros/latex/contrib/ulem/ulem.pdf

2013年10月26日星期六

Change the Font for Your LaTeX Document

Sometimes, it is relatively easy and intuitive to determine which PDF file is created by LaTeX, due its distinct trademark font by default, which is quite different from other popular editors such as MS Office. However, LaTeX, as a professional editor, also supports various font setting. However, it is slightly more complicated than the WYSIWYG editors.

A detailed introduction to the LaTeX font system could refer to the first reference below. Basically, it is recommended that a single document should apply a uniform font, simply because that is more formal and beautiful. Thus, what we have to modify is actually the so-called "the font family".

The fonts could be systematically grouped into three main categories: roman (rm) or serif, sans serif (sf) and monospace (tt). For each category, LaTeX provides a default font, Computer Modern Roman, Computer Modern Sans Serif, and Computer Modern Typewritter, respectively. Further more, we can use the following three variables to refer to each of them:



  • \rmdefault
  • \sfdefault
  • \ttdefault
If not specification is made, the system will apply the serif or default roman font (rm), namely the Computer Modern. If we want to change it into the default sans serif (sf), namely Computer Modern Sans Serif, or the default monospace (tt), namely Computer Modern Sans Typewriter, we can use the following commands:

\renewcommand*{\familydefault}{\sfdefault}

\renewcommand*{\familydefault}{\ttdefault}

Besides the three default font families, LaTeX also provides some pre-installed font families, such as Palatino (ppl), Times (ptm), Helvetica (phv), Courier (pcr), etc. In principle, if the specific font belongs to the "rm" category, we just need to use the following command:

\renewcommand*\rmdefault{ppl}

Otherwise, we will have to first modify the system default font family category to "sf" or "tt" with the already mentioned commands respectively, then specify the particular font in a similar way:

\renewcommand*\sfdefault{pbk}

\renewcommand*\ttdefault{pcr} 


Or if you do not want to be so disciplined, you can just assign the particular font family to the system default roman font, namely:

\renewcommand*\rmdefault{pbk}


Please note that only abbreviations are accepted. For a complete list of pre-installed font families and their abbreviations, refer to the last reference.




Reference:

http://en.wikibooks.org/wiki/LaTeX/Fonts
http://www.tug.dk/FontCatalogue/
http://www.macfreek.nl/memory/Fonts_in_LaTeX

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 有两个基本宏包:
CJKCJKutf8,后者针对于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