LaTeX Tips
Back to homepage
LaTeX Tips
Contents:
● Math
● Page Settings
● Slides
● Tables
● Figures
● Algorithms
● Bibliography
● PDF
● Fonts
Math
Compound math symbols
To produce a compound math symbold, e.g., a right arrow with, e.g., the text 'Lemma 1.2' on
top, use:
$\stackrel{\mbox{\tiny Lemma 1.2}}{\Rightarrow}$
Another example:
$\stackrel{def}{\equiv}$
Overbrace/Underbrace
To have math with overbrace or underbrace, use:
$\overbrace{x+y}^{sum}=\underbrace{x \cdot y}_{\mbox{product}}$
Multi-valued Functions
http://www.eng.tau.ac.il/~gabriels/latextips.html(第 1/10 页)2008-5-29 10:19:17
LaTeX Tips
To state a multi valued function, use:
$$
z = \left\{
\begin{array}{ll}
1 & x >0 \\
0 & \mbox{otherwise}
\end{array}
\right.
$$
Equation arrays with (some) equation numbers
The eqnarray environment produces a math-mode environment with an array of 3 columns
aligned {rcl}. E.g.
\begin{eqnarray}
|O| & \leq & |O \setminus A| + |A| \leq \label{eq:start} \\
& \leq & |A| + |A| \leq \nonumber \\
& \leq & 2|A|
\end{eqnarray}
Notice the \nonumber on the second line which omits the number. If all lines should be number-
less, you can use \begin{eqnarray*} instead of \begin{eqnarray}.
Page Settings
Fullpage
In order to have text written on entire page, consider using the fullpage package, with the
additional
\addtolength{\voffset}{-1.0cm}
\addtolength{\textheight}{3.5cm}
Line Numbers
In order to have line numbers on the output, consider using the (somewhat buggy, but pretty
straightforward) lineno package.
http://www.eng.tau.ac.il/~gabriels/latextips.html(第 2/10 页)2008-5-29 10:19:17
LaTeX Tips
Put \linenumbers to have linenumbers run through the entire document, or \pagewiselinenumbers
to have linenumbers reset to 1 at every page. Put either of these commands where you want
the linenumbers to begin.
Watermarks and 'draft' version
In order to have a watermark sentence (e.g. ''Draft''), use the draftcopy package, with the
additional parameters:
\usepackage[...]{draftcopy}
Where instead of [...] use a comma-separated list of parameters taken from the following:
none Dont print DRAFT across any page
first Print DRAFT across first page only
firsttwo Print DRAFT across two first pages only
all print DRAFT across all pages
bottom print DRAFT on the bottom of all pages
bottomafter print DRAFT on the bottom of all pages following the ones who have DRAFT across
light print DRAFT in light gray
dark print DRAFT in dark gray
In order to choose the sentence printed (instead of DRAFT), use the command
\draftcopyName{...}{...}
where the first argument is the sentence to be printed, and the second argument is the scaling
factor (start from about 50). This command should appear before the \begin{document}
command.
Slides
printing slides k-up
To print slides in k-up, use the unix command
psnup -r -k presentation.ps presentation_k.ps
http://www.eng.tau.ac.il/~gabriels/latextips.html(第 3/10 页)2008-5-29 10:19:17
LaTeX Tips
Tables
vertical spacing - space between rows
To adjust the vertical space between rows, i.e. - increase the space between the text and the
top/bottom \hline commands, put the following in the preamble:
% Adds a space between the text and the [T]op \hline
\newcommand\T{\rule{0pt}{3.1ex}}
% Adds a space between the text and the [B]ottom \hline
\newcommand\B{\rule[-1.7ex]{0pt}{0pt}}
one can then use \T and/or \B inside a cell in the row, i.e. after some text in the row, to get
extra space between the text and the \hline. These commands will not work if placed between
rows. E.g.
\begin{tabular}{ll}
\hline
% \T and \B would not work if it is placed here (needs to go inside cell)
Col1 \T \B & Col2 \\
\hline
$\sqrt{\frac{1}{2}}$ \T & more space from top \verb+\hline+ \\
$\sqrt{\frac{1}{2}}$ & no added space \\
$\sqrt{\frac{1}{2}}$ \B & more space from bottom \verb+\hline+ \\
\hline
\end{tabular}
and
\begin{tabular}{ll}
\hline
Col1 & Col2 \\
\hline
$\sqrt{\frac{1}{2}}$ & no extra space from top \verb+\hline+ \\
$\sqrt{\frac{1}{2}}$ & no added space \\
$\sqrt{\frac{1}{2}}$ & no extra space from bottom \verb+\hline+ \\
\hline
\end{tabular}
http://www.eng.tau.ac.il/~gabriels/latextips.html(第 4/10 页)2008-5-29 10:19:17
LaTeX Tips
Figures
Images with math (via xfig)
To create images using xfig with math text, do the following:
In xfig:
● Choose text, and make sure the following settings are set:
m Under Text Flags in the bottom, make sure the Special Flag is Special (and not
Normal). This can be automated by using the flag
-specialtext -latexfonts -startlatexFont default
when invoking xfig.
m In Pen Color, make sure the color is Default (and not Black which is usually the
case when you start xfig).
● Write the text you like. If you want to write in math mode, make sure to write things
between \$'s.
● Save the image as .fig file.
● Export the image to both .pstex and .pstex_t. In new versions of xfig this is done
automatically by choosing Combined PS/LaTeX (both parts).
Afterwards:
● Make sure the two generated files are in your working directory.
● Use the graphics package.
● Use the following code to insert a figure named fig.pstex_t, with a scaling factor 0.5
\begin{figure}[h]
\begin{center}
\scalebox{0.5}{\input{fig1.pstex_t}}
\caption{This is figure 1}
\label{fig:fig1}
\end{center}
\end{figure}
Inserting an .eps figure
\documentclass{article}
http://www.eng.tau.ac.il/~gabriels/latextips.html(第 5/10 页)2008-5-29 10:19:17
LaTeX Tips
\usepackage{pstricks}
\usepackage{pst-plot}
\usepackage{epsfig}
\begin{document}
\begin{figure}[h]
\centerline{
\epsfig{file=epsfig.eps, scale=0.5}
}
\caption{Some EPS figure}
\label{fig:fig1}
\end{figure}
\end{document}
Converting PStricks/pstex_t to EPS
Assuing the pstricks-figure/pstex_t is in file figfile, use a latex file (say, texfigfile.tex) containing:
\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-plot}
\usepackage{epsfig}
\begin{document}
\thispagestyle{empty} % omits page numbers.
\input{figfile}
\end{document}
The \thispagestyle{empty} is necessary for the bounding box to be defined properly by dvips.
Then do
latex texfigfile.tex
dvips texfigfile.dvi -E
Note: the generated file might be a .ps file. However, one can still insert it like any other .eps
figure.
Images with pdflatex
Converting images to .pdf
When using pdflatex, images should be converted to .pdf.
● Converting .eps to .pdf:
http://www.eng.tau.ac.il/~gabriels/latextips.html(第 6/10 页)2008-5-29 10:19:17
LaTeX Tips
use epstopdf.
Note that you might need to adjust the bounding box of the .eps file before performing the
epstopdf. This can be done manually by opening the .eps file in GhostView, checking the
coordinates of the lower-left and upper-right boundries of the actual figure, opening the .
eps file in any text editor, and changing the bounding box to the correct coordinates.
● Converting .pstex_t and .pstex directly to .pdf:
use the UNIX script pstex2pdf defined by:
#!/bin/csh
echo "epstopdf $1.pstex"
epstopdf $1.pstex
perl -p -i -e "s/.pstex//;" $1.pstex_t
Inserting an image
One should add to the preamble
\usepackage{epsfig}
\usepackage{graphics}
To insert an image, named e.g. pdffig.pdf, use:
\begin{figure}[h]
\centerline{
\includegraphics[scale=0.5]{pdffig}
}
\caption{Some caption}
\label{fig:pdffig1}
\end{figure}
Note that the 'original' files, i.e., the .pstex_t|.pstex|.eps files, should be present in the working
directory as well.
pstex missing
When using the Combined PS/LaTeX format in exporting from xfig, two files are generated:
[figname].pstex - contains the graphical information. This is basically an .eps file.
[figname].pstex_t - contains the latex text information.
http://www.eng.tau.ac.il/~gabriels/latextips.html(第 7/10 页)2008-5-29 10:19:17
LaTeX Tips
The [figname].pstex_t file uses \includegraphics{[figname].pstex} to include the graphical info.
When compiling from different directories, it is important to make sure that right path appears
in the \includegraphics command, namely, that it has the form \includegraphics{PATH/[figname].
pstex}
Algorithms
General use
To use the algorithm environment, use the packages
\usepackage{algorithm}
\usepackage{algpseudocode}
An example of an algorithm is given by:
\begin{algorithm}{}
\caption{MyAlgorithmName (...arguments...)}
\label{alg:myalgorithmname}
\begin{algorithmic}[1]
\For{all ...}
\State do ...
\EndFor
\State return ...
\end{algorithmic}
\end{algorithm}
Changing the type of caption
Sometimes one wants to use the algorithm environment so that instead of Algorithm, one has
a different caption, e.g. Protocol, Heuristic, etc. To do this, use the line
\floatname{algorithm}{[New Name]}
just before the algorithm code. E.g., to produce a Protocol, use
\floatname{algorithm}{Protocol}
\begin{algorithm}{}
\caption{MyProtocolName (...arguments...)}
\label{alg:myprotocolname}
http://www.eng.tau.ac.il/~gabriels/latextips.html(第 8/10 页)2008-5-29 10:19:17
LaTeX Tips
\begin{algorithmic}[1]
...
\end{algorithmic}
\end{algorithm}
Bibliography
Using a BibTeX file
To insert the bibliography from a .bib file (e.g. mybib.bib), add the commands
\bibliographystyle{plain}
\bibliography{mybib}
For different styles, see http://www.cs.stir.ac.uk/~kjt/software/latex/showbst.html
Producing all entries in the .bib file
To produce the list of all entries in the .bib file, add the command
\nocite{*}
just before the \bibliography{mybib} command, where the bibliography file is mybib.bib.
PDF
From .tex to A4 .pdf
To produce a pdf for paper size A4, make sure the \documentclass command is defined
properly, e.g.,
\documentclass[a4paper,11pt]{article}
Use dvips with the switch
-G0 -Ppdf -t A4Size
http://www.eng.tau.ac.il/~gabriels/latextips.html(第 9/10 页)2008-5-29 10:19:17
LaTeX Tips
followed by ps2pdf with the switch
-sPAPERSIZE=a4
This solves the problem of having incorrect header/footer margins.
Fonts
User Defined Font Size
Sometimes, the predefined \normalsize, \small, \huge, etc., font sizes do not suffice. To produce
a userdefined font size one can use the command:
\newcommand{\myfontsize}{\fontsize{9}{11}\selectfont}
where the first argument gives the height of the font (in pt), and the second argument gives the
height of the line (in pt).
E.g., the above \myfontsize produces a fontsize that is between \small and \tiny.
http://www.eng.tau.ac.il/~gabriels/latextips.html(第 10/10 页)2008-5-29 10:19:17
www.eng.tau.ac.il
LaTeX Tips
本文档为【LaTeX Tips】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。