分类 ‘LaTeX’ 的归档

安装LaTeX的包的方法(ubuntu)

十一月 2, 2008

Installation in a texmf Tree
For a more permanent installation, you can place the files of the the pgf package (see the previous subsection
on how to obtain them) in an appropriate texmf tree.
When you ask TEX to use a certain class or package, it usually looks for the necessary files in so-called
texmf trees. These trees are simply huge directories that contain these files. By default, TEX looks for files
in three different texmf trees:
2
• The root texmf tree, which is usually located at /usr/share/, c:\texmf\, or
c:\Program Files\TeXLive\texmf\.
• The local texmf tree, which is usually located at /usr/local/share/, c:\localtexmf\, or
c:\Program Files\TeXLive\texmf-local\.
• Your personal texmf tree, which is located in your home directory.
You should install the packages either in the local tree or in your personal tree, depending on whether
you have write access to the local tree. Installation in the root tree can cause problems, since an update of
the whole TEX installation will replace this whole tree.
Inside whatever texmf directory you have chosen, create the sub-sub-sub-directory texmf/tex/latex/pgf
and place all files in it. Then rebuild TEX’s filename database. This done by running the command texhash
or mktexlsr (they are the same). In MikTeX, there is a menu option to do this.
If you want to be really tidy, you can place the documentation in the directory texmf/doc/latex/pgf.
For a more detailed explanation of the standard installation process of packages, you might wish to
consult http://www.ctan.org/installationadvice/. However, note that the pgf package does not come
with a .ins file (simply skip that part).

Include source code in Latex with “Listings”

十一月 2, 2008

This article was gotten from  http://texblog.wordpress.com/2008/04/02/include-source-code-in-latex-with-listings/

First include the “listings”-package into your document:

\usepackage{listings}

Basics

Now you have basically two possibilities. Either you type/copy your source code directly into the Latex document:

\begin{lstlisting}
place your source code here
\end{lstlisting}

The other possibility is to directly include the source file:

\lstinputlisting{filename.java}

This is particularly useful if you are still editing your source code. Obviously, Latex will always include the latest version of the source while generating the PDF-file.

Supported languages

The listings package does not only support java source code, but there is an exhaustive list of languages which are known to the package:
ABAP (R/2 4.3, R/2 5.0, R/3 3.1, R/3 4.6C, R/3 6.10), ACSL Ada (83, 95), Algol (60, 68), Ant, Assembler (x86masm), Awk (gnu, POSIX), bash, Basic (Visual), C (ANSI, Handel, Objective, Sharp), C++ (ANSI, GNU, ISO, Visual), Caml (light, Objective), Clean, Cobol (1974, 1985, ibm), Comal 80, csh, Delphi, Eiffel, Elan, erlang, Euphoria, Fortran (77, 90, 95), GCL, Gnuplot, Haskell, HTML, IDL (empty, CORBA), inform, Java (empty, AspectJ), JVMIS, ksh, Lisp (empty, Auto), Logo, make (empty, gnu), Mathematica (1.0, 3.0), Matlab, Mercury, MetaPost, Miranda, Mizar, ML, Modula-2, MuPAD, NASTRAN, Oberon-2, OCL (decorative, OMG), Octave, Oz, Pascal (Borland6, Standard, XSC), Perl,PHP, PL/I,Plasm, POV,Prolog, Promela,Python, R,Reduce, Rexx,RSL, Ruby, S (empty, PLUS), SAS, Scilab, sh, SHELXL, Simula (67, CII, DEC, IBM), SQL, tcl (empty, tk), TeX (AlLaTeX, common, LaTeX, plain, primitive), VBScript, Verilog, VHDL (empty, AMS), VRML (97), XML, XSLT.

Custom code formatting

You can customise the way how your code is displayed by using:

\lstset{…}

The following is a list of parameters, which can be used inside the previous command

language=Octave -> choose the language of the code
basicstyle=\footnotesize -> the size of the fonts used for the code
numbers=left -> where to put the line-numbers
numberstyle=\footnotesize -> size of the fonts used for the line-numbers
stepnumber=2 -> the step between two line-numbers.
numbersep=5pt -> how far the line-numbers are from the code
backgroundcolor=\color{white} -> sets background color (needs package)
showspaces=false -> show spaces adding particular underscores
showstringspaces=false -> underline spaces within strings
showtabs=false -> show tabs within strings through particular underscores
frame=single -> adds a frame around the code
tabsize=2 -> sets default tab-size to 2 spaces
captionpos=b -> sets the caption-position to bottom
breaklines=true -> sets automatic line breaking
breakatwhitespace=false -> automatic breaks happen at whitespace
morecomment=[l]{//} -> displays comments in italics (language dependent)

If you are using several parameters, they have to be separated by commas.
Example:

\lstset{numbers=left, stepnumber=2, frame=single,}

You might want to have a caption as well as reference the listing later:

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

For an exhaustive list of available options to customize your included source code, refer to the documentation on CTAN.

Tricks

The following will draw a frame around your source code with a blue shadow (you will need the color-package).

\lstset{frame=shadowbox, rulesepcolor=\color{blue}}

If you want closed frames on each page, use the following command sequence:

\begin{framed}
\begin{lstlisting}…\end{lstlisting}
or \lstinputlisting{…}
\end{framed}

如何让表格中一个单元格的文字换行(转贴)

十月 28, 2008

问题:如何同时让表格同一行一个单元格的文字能垂直居中?比如说文字超长超出页面范围需要分行显示

答:(来源于smth)

方案一:

\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}
%然后使用&\tabincell{c}{}&就可以在表格中自动换行

%比如这么用
\begin{tabular}{|c|c|}
\hline
1 & the first line \\
\hline
2 & \tabincell{c}{haha\\ heihei\\zeze} \\
\hline
\end{tabular}

注:好用,已试过,以下为一例子,可直接存为.tex文件编译运行

\documentclass[a4paper,12pt]{article}
\usepackage{CJK}
\begin{document}
\begin{CJK*}{GBK}{song}

\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}
%然后使用&\tabincell{c}{}&就可以在表格中自动换行

%比如这么用
\begin{tabular}{|c|c|}
\hline
1 & the first line \\
\hline
2 & \tabincell{c}{haha\\ heihei\\zeze \\fgf \\asgr} \\
\hline
\end{tabular}

\end{CJK*}
\end{document}

方案二:

\usepackage{longtable}