TechBlox » Latex http://techblox.fusun.ch/wordpress Solutions To A Computer Scientist's Daily Problems Tue, 14 Sep 2010 11:11:54 +0000 en-US hourly 1 http://wordpress.org/?v=3.4.1 Fancy Latex Tables http://techblox.fusun.ch/wordpress/2010/09/fancy-latex-tables/ http://techblox.fusun.ch/wordpress/2010/09/fancy-latex-tables/#comments Mon, 06 Sep 2010 12:47:56 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=214 Do you like to create funny graphics like the following for your paper?

Masters of Illustrator can probably chop-chop-compose such a thing in a flash. I, however, abruptly failed as I tried to insert formulae. Why not directly script it in latex, I thought. So I unearthed the big old latex manuals and learned about \multicolumn and \cline. Eventually, I came up with the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
\begin{tabular}{|l|c|l|c|l|}
\multicolumn{1}{c}{}
&\multicolumn{2
}{c}{$e_i$}
&\multicolumn{2}{c}{$e_{i+1}$}\\

\multicolumn{1}{c}{$D$}
&\multicolumn{2}{c}{$\overbrace{\hspace{1cm}}^{}$}
&\multicolumn{2}{c}{$\overbrace{\hspace{1cm}}^{}$} \\\cline{1-1}

$P_1$
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}   \\\cline{1-1}

$\vdots$
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{$W$}
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}   \\\cline{1-1} \cline{3-3}

$P_{i}$
&$\longleftrightarrow$
&$V_0$
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{$W$} \\\cline{3-3} \cline{1-1}\cline{5-5}

$P_{i+1}$
&$\longleftrightarrow$
&$V_1$
&$\longleftrightarrow$
&$V_0$ \\\cline{3-3} \cline{1-1} \cline{5-5}

$P_{i+2}$
&$\longleftrightarrow$
&$V_2$
&$\longleftrightarrow$
&$V_1$ \\\cline{3-3} \cline{1-1} \cline{5-5}

$\vdots$
&$\longleftrightarrow$
&$\vdots$
&$\longleftrightarrow$
&$V_2$ \\\cline{3-3} \cline{1-1}\cline{5-5}

$P_{i+k}$
&$\longleftrightarrow$
&$V_k$
&$\longleftrightarrow$
&$\vdots$ \\\cline{3-3} \cline{1-1} \cline{5-5}

$P_{i+k+1}$
& \multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}&
$\longleftrightarrow$
&$V_k$ \\\cline{1-1
} \cline{5-5}

$\vdots$
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}   \\\cline{1-1}

$P_m$
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}   \\\cline{1-1}

\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}   \\
\end{tabular
}

and

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\hline
$P_1$

&$\hdots$
&$P_{i}$
&$P_{i+1}$
&$P_{i+2}$
&$\hdots$
&$P_{i+k}$
&$\hdots$
&$P_m$ \\\hline

\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{$\updownarrow$}
& \multicolumn{1}{c}{$\updownarrow$}
& \multicolumn{1}{c}{$\updownarrow$}
& \multicolumn{1}{c}{$\hdots$}
& \multicolumn{1}{c}{$\updownarrow$}
& \multicolumn{2}{c}{} \\\cline{3-7}

\multicolumn{1}{c}{}
&
& $V_{0}$

& $V_{1}$
& $V_{2}$
& $\hdots$
& $V_{k}$
& \multicolumn{2}{c}{} \\\cline{3-7}
\end{tabular}

The trick is to create borderless cells using \multicolumn and then fill in horizontal lines with \cline. You’re welcome. Now back to work!

]]>
http://techblox.fusun.ch/wordpress/2010/09/fancy-latex-tables/feed/ 0
Default Latex Template http://techblox.fusun.ch/wordpress/2010/08/default-latex-template/ http://techblox.fusun.ch/wordpress/2010/08/default-latex-template/#comments Mon, 30 Aug 2010 09:42:56 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=81 I get frustrated every time I install latex and TeXnicCenter and wish to display some formulas or write a short essay and realize that there are no templates whatsoever that I could use. Then I get frustrated even more when I realize that I cannot even remember the most basic latex lines to start a new document. The last time that happened, I decided to add a small template here, so I – and hopefully some other dudes – shall simply copy the code and start a new latex document immediately!

There you go:

1
2
3
4
5
\documentclass[a4paper,12pt]{report}
\usepackage{amsmath,amssymb,amsthm}
\begin{document}
text   
\end{document}

The following template could be employed for a more advanced text, such as a thesis:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
\documentclass[a4paper,twoside,12pt]{scrbook}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[footnotesize,sl,SL,hang,tight]{subfigure}  % helpful package for aligning figures next to each other
\usepackage{longtable} % tables over several pages
\usepackage[font={small,sl},hang,labelfont=bf]{caption} % configure captions
\usepackage{captcont} % continue sufigures over several pages
\usepackage{booktabs} % publication quality tables for LaTeX
%\usepackage{showkeys} % shows the labels above the references for easier development
\usepackage{mathrsfs}
\ifpdfoutput{%
    \usepackage[pdftex]{graphicx}
    \usepackage[]{pdfpages} %for including full pdf pages
}{%
    \usepackage{graphicx}
}
\usepackage{wrapfig} % wraping text around figures
\usepackage{rotating} % rotate figures
\usepackage{verbatim} % multiline comment
\usepackage{algorithmic}
\usepackage[headinclude]{scrpage2} %\KOMAoptions{headinclude}

% Font packages:
\usepackage{times}
\usepackage{helvet}   % sets sans serif font
\usepackage[T1]{fontenc}
%\usepackage{lmodern}

%PDF hyperref config
\ifpdfoutput{%
    \usepackage[pdftex,
        a4paper,
        bookmarks,
    bookmarksopen=true,
    bookmarksnumbered=true,
        pdfauthor={Alfredo Albino},
        pdftitle={My Life And More},
        colorlinks,
        linkcolor=black,
        citecolor=black,
        filecolor=black,
        urlcolor=black,
        anchorcolor=black,
        menucolor=black,
        breaklinks=true,
    pageanchor=true,
        plainpages=false,
        pdfpagelabels=true
]{hyperref}
}{}

\ifpdfoutput{%
    \pdfcompresslevel=9
    \pdfoutput=1
    \DeclareGraphicsExtensions{.pdf,.png}
}{}
\bibliographystyle{alpha
}
\pagestyle{useheadings}

% A4
\topmargin -0.5in
\textheight 9.3in
\textwidth 6.3in
\oddsidemargin 0.18in
\evensidemargin -0.22in
\parskip 0.1in
\parindent 0in

\renewcommand{\arraystretch}{1.5}
\renewcommand{\baselinestretch}{1}

\begin{document}

\begin{titlepage}
    \topmargin 1.0cm
    \oddsidemargin 0.0cm
    \evensidemargin 0.0cm
    %\textwidth 6.5in
    \centering
    \Huge
    \vspace{2.0cm}
    \textbf{\textsf{My Life And More}} \\[1.5cm]
    %\includegraphics*[width=0.4\textwidth]{image} \\[1.5cm]
    \vspace{2.0cm}
    \sffamily
    \Large
    Alfredo Albino
    \\[0.8cm]
    \large
    BEST University
    \\
    August 2010
    \\[1.3cm]
    Prof. Dr. Alfons Aareweg
    \vfill
    %\includegraphics*[width=0.3\textwidth]{logo1} \hfill
    %\includegraphics*[width=0.3\textwidth]{logo2}
    \vspace{3.4cm}
\end{titlepage}
\cleardoublepage


\pagenumbering{roman}
\setcounter{page}{1}


%\include{abstract}
\chapter*{Abstract}
abstract stuff

\cleardoublepage
\cleardoublepage


%\include{acknowledgment}
\chapter*{Acknowledgment}
thanks


\tableofcontents
\cleardoublepage


\pagenumbering{arabic}


\renewcommand*{\chapterformat}{} % show chapter titles only (no numbers)



%\include{chapter1}
\chapter{Start}
\section{Now}
start

\appendix
\clearpage
%\renewcommand*{\chapterpagestyle}{myappendixpagestyle}

\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures
\cleardoublepage

\addcontentsline{toc}{chapter}{List of Tables}
\listoftables
\cleardoublepage

\clearpage
\renewcommand*{\chapterpagestyle}{empty}

%\nocite{*}
\addcontentsline{toc}{chapter}{Bibliography}
%\bibliography{bib}

\end{document}
]]>
http://techblox.fusun.ch/wordpress/2010/08/default-latex-template/feed/ 0
Advanced Formulae in Latex http://techblox.fusun.ch/wordpress/2010/05/advanced-formulae-in-latex/ http://techblox.fusun.ch/wordpress/2010/05/advanced-formulae-in-latex/#comments Thu, 27 May 2010 17:06:39 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=15 Remember when you couln’t think of the correct commands to write a certain formula in latex because it’s been a year since you did it the last time? This might help you find the light.

Vectors

Using

1
\newcommand{\ve}[1]{\mbox{\bf #1}}

in your preamble, you can easily write vectors as follows:

1
2
3
\begin{equation}
    \mathscr{L}(\ve v_i) = \ve v_i - \frac{1}{\left| N_i \right|} \sum_{j\in N_i} \ve v_j
\end{equation}

Matrices

You always need matrices. Try this code:

1
2
3
4
5
6
7
8
9
10
\begin{equation}
    \begin{pmatrix}
        A & A_k
    \end{pmatrix}
    \begin{pmatrix}
        D \\
        D_k
    \end{pmatrix}
    = 0
\end{equation}

Multi-case definition

This code comes in handy to define certain funtions or matrices:

1
2
3
4
5
6
7
8
\begin{equation}
    A_{ij} = \left\{
        \begin{array}{l l}
            1 & \quad (i,j) \in K \\
            0 & \quad \text{otherwise} \\
        \end{array}
        \right
\end{equation}
]]>
http://techblox.fusun.ch/wordpress/2010/05/advanced-formulae-in-latex/feed/ 2
Latex Fonts in Illustrator http://techblox.fusun.ch/wordpress/2010/05/adobe-illustrator-formulas-and-latex-fonts/ http://techblox.fusun.ch/wordpress/2010/05/adobe-illustrator-formulas-and-latex-fonts/#comments Thu, 27 May 2010 04:18:53 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=3 I recently wanted do insert a formula into a Adobe Illustrator figure. Since I didn’t find a way to do so directly in Illustrator and copying a formula from MS Word didn’t work properly, I wanted to copy the formula from a latex generated pdf (or ps) file. This, however, didn’t work either, as some latex fonts (CMR8, ect.) were missing. There’s probably a way to include them while generating the pdf file. But the easiest way I found was to copy all type 1 font files from my latex distribution C:\Program Files (x86)\MiKTeX 2.8\fonts\type1\public\amsfonts\cm to the windows font directory C:\Windows\Fonts. That worked. Yay. ]]> http://techblox.fusun.ch/wordpress/2010/05/adobe-illustrator-formulas-and-latex-fonts/feed/ 0