Showing posts with label latex. Show all posts
Showing posts with label latex. Show all posts

Friday, October 4, 2013

LaTeX Typesetting Hacks (Continuously Updating)

This list of knowledge is a collection of common problems encountered in everyday typesetting. The solution is either seen by reading package manuals of LaTeX related websites. But here I would like to give a list of clear reference (let's do it in factory mode). I've evaluated different solutions and try to make the hacks as simple as possible.

  • By default, hyperref packages creates a colorful border for links. To remove it,

    %remove colorful borders on links without updating the package
    \hypersetup{%
        pdfborder = {0 0 0}
    }
  • How to use "List of Algorithms" as toc title and "Algorithms" for single title instead of "List of Listings" while using listings package?

    %listing customization
    \renewcommand{\lstlistingname}{Algorithm}% Listing -> Algorithm
    \renewcommand{\lstlistlistingname}{List of \lstlistingname s}% List of Listings -> List of Algorithms
  • How not to break hypen in bibliography?

    %bibliography no break hypen
    \makeatletter
    \newcommand*\bibhyphen{\hbox{-}\nobreak\hskip\z@skip}
    \makeatother
    \newcommand*\bibdash{\rule[0.48ex]{2em}{0.14ex}\space}
  • How to add bibliography to the table of contents?

    \usepackage[nottoc]{tocbibind} %add bibliography to toc
  • How to use "bibliography" instead of "references"?

    \renewcommand{\refname}{Bibliography}
  • How to enlarge margin paragraph width without using geometry package since it rewrites all the default layout values?

    %set twice as default
    \setlength{\marginparwidth}{2\marginparwidth}
  • How to center texts?

    %maybe you are looking for \vspace{2cm} too?
    \begin{center}
    This is centered text.
    \end{center}
  • How to give remarks in red?

    \usepackage{color}
    %you can define a macro \remark in the preamble
    \newcommand{\remark}[1]{{\color{red}REMARK: #1}}
    %then in the document
    \remark{This is a remark in red.}
  • To include Chinese/Japanese/Korean letters or characters along with pdflatex, use CJK package. Alternatively, one can choose xelatex. See CJK Doc. Notice CJK env uses two extra options to specify the encodings and font family. One can check out supported font family by checking the folder /usr/share/texmf/tex/latex/CJK/UTF8 or similar. If the font parameter is empty, the default value given in CJK.enc will be selected. On my machine, I have c70bkai.fd installed in that folder. One can also refer install CJK support to see how to manually install a CJK font to the tex tree.

    \usepackage{CJK}
    \begin{CJK}{UTF8}{bkai}
    漢字
    \end{CJK}
    %to merge CJK with another environment, embed that environment within CJK, such as
    \begin{CJK}{UTF8}{bkai}
    \marginpar{
    丁香
    }
    \end{CJK}
  • An example of including a centered figure with caption and label.

    \usepackage{grahpicx}
    \begin{figure}[ht]
    \centering
    \includegraphics{pic.jpg}
    \caption{sample picture}
    \label{fig:sample-pic}
    \end{figure}
  • How to put two pictures side by side with each of its own caption and label?

    \usepackage{subfigure}
    \begin{figure}[ht]
    \centering
    \subfigure[Caption a]{
    \includegraphics[width=.45\linewidth]{img1.png}
    \label{fig:imga}
    }
    \hspace{.2in}
    \subfigure[Caption b]{
    \includegraphics[width=.45\linewidth]{img2.png}
    \label{fig:imgb}
    }
    \caption{Two figures}%
    \label{fig:2-fig}
    \end{figure}
  • How to introduce plain codes?

    \usepackage{verbatim}
    \begin{verbatim}
    int sched_setscheduler(pid_t pid, int policy,
                           const struct sched_param *param);
    \end{verbatim}
  • How to include "Acknowledgements"?

    %do it as a section
    \section*{Acknowledgements}
    \addcontentsline{toc}{section}{Acknowledgements}
      
  • Customize figure caption. This caption will remove "Fig.", and the separator is set as space instead of the default colon.

    \renewcommand{\figurename}{}
    \usepackage[labelsep=space]{caption}

Wednesday, April 3, 2013

tikz: Plotting Functions

Use plot (in tikz package) to draw functions in $\mathrm{\LaTeX}$.

\usepackage{tikz,amsmath}

The example below generates this graph.

\begin{tikzpicture}[scale=0.5]
\draw[->] (0,0) -- (8,0) node[right] {$x$};
\draw[->] (0,0) -- (0,10) node[above] {$f(x)$};
\draw (1.5,0) -- (1.5,0.1) node[below] {$\frac{3}{2}$};
\draw (2.25,0) -- (2.25,0.1) node[below] {$\frac{5}{2}$};
\draw[dotted] (3,9) -- (3,0)  node[below] {$3$};
\draw [domain=0:3] plot (\x,{4/3 * \x*\x*\x - 8*\x*\x+15*\x}) node[right] {$\frac{4}{3}x^3-8x^2+15x$};
\draw [domain=3:6] plot (\x,{9*exp(3-\x)}) node[right] {$9e^{3-x}$};
\end{tikzpicture}

Saturday, January 12, 2013

LaTeX: Positioning Treaky Footnotes

Footnotes to Paragraph/Section Titles

When you put foonotes in paragraph titles or section titles, you will get complaints from LaTeX. The following fixes this and puts no footnotes in the table of contents.

\paragraph[foo-title]{foo-title \protect\footnote{bar-footnote}}
\section[foo-title]{foo-title \protect\footnote{bar-footnote}}

Footnotes to Captions

\begin{figure}
\includegraphics[]{foo.eps}
\caption[bar-title]{bar-title \footnotemark}
\end{figure}
\footnotetext{Here goes your foot note text}

Sunday, August 19, 2012

Using pdfpages For A beamer Slide

Here is a real example. It simply chooses the specified pages. One might want to get rid of the pages for special effects (e.g. shadowing) to get a printable version.
\documentclass{beamer}
\usepackage{grffile}  %to treat the spaces in the file name if needed%
\usepackage{pdfpages} %the package to do the combination job%
\begin{document}
{
\setbeamercolor{background canvas}{bg=} %set background blank
\setbeamertemplate{navigation symbols}{} %remove navi symbols
\includepdf[pages={1,2,7,12,18,22,24,28,33-45,49,52-76}]{handout-06_fair_ctl_model_checking.pdf}
}
\end{document}

Thursday, March 29, 2012

LaTeX: Creating Doubled Quine Corners

Quine corners are the symbols to enclose Church numerals. In LaTeX, one can create a macro to achieve it.

\documentclass{article}
\usepackage{amsmath}
\def \quine #1{
 \mbox{$\ulcorner$\hspace{-4pt}$\ulcorner$}
 #1
 \mbox{$\urcorner$\hspace{-4pt}$\urcorner$}
}
\begin{document}
$\quine i$
\end{document}

An equivalent way follows

%church number of lambda terms
\def \ch #1{
  \ulcorner #1 \urcorner
}

%quine corners for numerals
\def \quine #1{
   \ch  {\mbox{\hspace{-4pt}} \ch{ #1} \mbox{\hspace{-4pt}}}
}
The result is like $$\ulcorner \hspace{-4pt} \ulcorner n \urcorner \hspace{-4pt} \urcorner$$