~~ODT~~ ====== LaTeX ====== - my standard-[[code:latex:preamble]] - my [[code:latex:minimal document]] ===== Subversion information ===== \usepackage{svn-multi} add \svnidlong {$HeadURL$} {$LastChangedDate$} {$LastChangedRevision$} {$LastChangedBy$} in document. set the subversion property svn:keywords of them to HeadURL LastChangedDate LastChangedRevision LastChangedBy commit! the information can be added to the document, see my [[code:latex:preamble]] on how to do that... More information on LaTeX and Subversion can be found in [[http://www.tug.org/pracjourn/2007-3/kalderon-svnmulti/kalderon-svnmulti.pdf|this article]] by [[http://markelikalderon.com/|Mark Eli Kalderon]] in the PracTeX Journal 2007. ===== embedded movies in the resulting pdf ===== Fast way: \usepackage{movie15} with the according [[http://www.ctan.org/tex-archive/macros/latex/contrib/movie15/doc/movie15.pdf|manual]] (pdf, 460 kB) Longer way: a walkthrough to a pdf with playable movie is described [[latex:movies|here]]. ===== Authors with multiple institutions/affiliations ===== \documentclass{article} \usepackage{hyperref} \newcommand{\footremember}[2]{% \footnote{#2} \newcounter{#1} \setcounter{#1}{\value{footnote}}% } \newcommand{\footrecall}[1]{% \footnotemark[\value{#1}]% } \title{How to bowl properly} \author{% The Dude\footremember{alley}{Holly Star Lanes Bowling Alley}% \and Walter Sobchak\footremember{trailer}{probably in a trailer park}% \and Jesus Quintana\footrecall{alley} \footnote{Mexico?}% \and Uli Kunkel\footrecall{trailer} \footnote{Germany?}% } \begin{document} \maketitle The whole example is taken from \href{http://anthony.liekens.net/index.php/LaTeX/MultipleFootnoteReferences}{anthony liekens}\ldots \end{document} [expanded a bit from [[http://anthony.liekens.net/index.php/LaTeX/MultipleFootnoteReferences|anthony liekens]]] ===== Footnotes in Tables ===== ==== minipage ==== \documentclass{article} \usepackage{threeparttable} \usepackage{booktabs} \usepackage{lipsum} \begin{document} \lipsum[1] \begin{table}[h] \centering \begin{minipage}{\textwidth} \centering \caption{caption} \label{tab:label} \begin{tabular}{lcccc} \toprule some & text & is\footnote{footnote 1} & written & here\\ \midrule XYZ\footnote{explain the acronym!} & 1 & 2 & 3 & 4 \\ ASDF\footnote{explain this, too!} & 5 & 6 & 7 & 8 \\ \bottomrule \end{tabular} \end{minipage} \end{table} \lipsum[1] \end{document} ==== threeparttables ==== \documentclass{article} \usepackage{threeparttable} \usepackage{booktabs} \usepackage{lipsum} \begin{document} \lipsum[1] \begin{table}[h] \centering \begin{threeparttable} \caption{caption} \label{tab:table} \begin{tabular}{ccccc} \toprule some & things & are & written & here \\ \midrule 1\tnote{a} & 2 & 3 & 4 & 5 \\ 6 & 7 & 8\tnote{b}& 9\tnote{c} & 10 \\ \bottomrule \end{tabular} \begin{tablenotes} \item[a]{note} \item[b]{second note} \item[c]{here is a very, very, very, very, very, very long note.} \end{tablenotes} \end{threeparttable} \end{table} \lipsum[1] \end{document} ===== TikZ ===== ==== full page pdfs ==== generate figures, so that they fill the whole pdf. comes in handy for talks, like seen in slide 21 of "Quality guided wide field x-raytomographic imaging " in [[publications#talks]]. (scrubbed from [[http://www.nabble.com/Extracting-standalone-PDF-using-TikZ-PGF,-XeLaTeX,-and-pdfcrop-td17515086.html|here]]). This version using \begin{preview} and \end{preview} is an all-purpose way of achieving the effect. The [[latex#scale_bars|scale bar example below]] shows how to do it using %%\PreviewEnvironment{tikzpicture}%%. \documentclass{article} \usepackage[pdftex,active,tightpage]{preview} %\setlength\PreviewBorder{2mm} % use to add a border around the image \usepackage{tikz} \begin{document} \begin{preview} \begin{tikzpicture} \shade (0,0) circle(2); % background \draw (0,0) circle(2); % rim \draw (.75,1) circle(.5); % right eye \fill (.66,.9) circle(.25); % right pupil \draw (-.75,1) circle(.5); % left eye \fill (-.66,.9) circle(.25);% left pupil \fill (.2,0) circle (.1); % right nostril \fill (-.2,0) circle (.1); % left nostril \draw (-135:1) arc (-135:-45:1) -- cycle; % mouth \end{tikzpicture} \end{preview} \end{document} ==== scale bars ==== TikZ can be used to overlay stuff on images, this is used for adding arbitrary scalebars (with correct text-size and length according to the needs...). The output of the code below can be seen in {{latex:scalebar.pdf|this pdf}} (175 kB). \documentclass{article} \usepackage{graphicx,tikz} \usepackage{siunitx} \usepackage[graphics,tightpage,active]{preview} \PreviewEnvironment{tikzpicture} \newcommand{\imsize}{\linewidth} \newlength\imagewidth \newlength\imagescale \begin{document} \pgfmathsetlength{\imagewidth}{\linewidth} % desired displayed width of image \pgfmathsetlength{\imagescale}{\imagewidth/670} % pixel width of imagefile used below \usetikzlibrary{shapes.arrows} %% adjust scale of tikzpicture (and direction of y) such that pixel %% coordinates can be used for drawing overlays: \begin{tikzpicture}[x=\imagescale,y=-\imagescale] % place image (integer coordinates refer to pixel centers): \node[anchor=north west,inner sep=0pt,outer sep=0pt] at (0,0) {\includegraphics[width=\imagewidth]{imagefile}}; %\draw (100,500) node ; \draw[|-|,thick] (25,500) -- (175,500) node[midway,above] {\SI{300}{\micro\meter}}; % coordinates where the scalebar should be drawn, scaled with the size of the image. \end{tikzpicture} \end{document} a complete guide to generating scale-bars with correct lengths and placement is explained [[latex:tikz:scalebar|here]], including a fancy matlab-file for easy calculation! ===== misc short notes ===== ==== figures ==== use \begin{figure}[p] % [tb] for small, [p] for big pictures for figures, since [htbp] does sound good, but can lead to weird float-placement if the figure is big. ==== hidden sections and labels ==== \usepackage{hyperref} \phantomsection \label{blablabla} and then cite the phantom-section with \ref{blablabla} or \pageref{blablabla} somewhere in the text. [via [[http://www.borniert.com/|this]]] ==== watermarking a document ==== \documentclass{scrartcl} \usepackage[]{draftwatermark} % try firstpage as option \usepackage{lipsum} \title{Lorem ipsum} \author{David Haberth\"ur} % Use the following to make modification %\SetWatermarkAngle{12} \SetWatermarkLightness{0.618} \SetWatermarkScale{2.2} \SetWatermarkText{confidentidal, do not redistribute!} \begin{document} \maketitle \lipsum \end{document} [via [[http://jeanmartina.blogspot.com/2008/07/latex-goodie-how-to-watermark-things-in.html|Jean Martina]]] ==== sizes ==== \documentclass{scrartcl} \usepackage[pdftex,active,tightpage]{preview} \begin{document} \begin{preview} \centering \tiny \verb+\tiny+\\ \scriptsize \verb+\scriptsize+\\ \footnotesize \verb+\footnotesize+\\ \small \verb+\small+\\ \normalsize \verb+\normalsize+\\ \large \verb+\large+\\ \Large \verb+\Large+\\ \LARGE \verb+\LARGE+\\ \huge \verb+\huge+\\ \Huge \verb+\Huge+\\ \end{preview} \end{document} ==== cases or "programming" ==== \documentclass{article} \usepackage[ansinew]{inputenc} \begin{document} \newcommand{\case}[1]{% \ifcase#1% \or eis% \or zwöi% \or drü% \else ERROR!% \fi% }% \centering \case{1} - \case{2} - \case{3} - \case{4} - \case{18} \end{document} ==== coloring table rows ==== \documentclass{article} \usepackage[table]{xcolor} \begin{document} \verb+\usepackage[table]{xcolor}+ and \verb+\rowcolor{color}+ in tables \begin{table}[htbp] \centering \begin{tabular}{c} \rowcolor{red} red\\ \rowcolor{green} green\\ \rowcolor{blue} blue\\ \rowcolor{cyan} cyan\\ \rowcolor{magenta} magenta\\ \rowcolor{yellow} yellow\\ \rowcolor{white} white\\ \rowcolor{lightgray} lightgray\\ \rowcolor{gray} gray\\ \rowcolor{darkgray} darkgray\\ \rowcolor{black} \textcolor{white}{black} \end{tabular} \end{table} \end{document} ===== Chapterbib ===== Each chapter can have its own bibliography, this can come in handy for huge documents, like PhD-Theses. To do this, you need to add the chapterbib-package to your preamble and add the sectionbib-option to natbib. \usepackage[square,numbers,sectionbib]{natbib} \usepackage{chapterbib} Iclude chapter-files with \include{Subdir\Chapter01} and add the bibliography to the end of each chapter with \bibliographystyle{plainnat} \bibliography{../Bibliography} you can have multiple Bibliography-files, but have to keep in mind to add the correct path. After running pdflatex on your file, you should have a Chapter01.aux-file in the Subdir-Directory. Running bibtex Chapter01 and afterwards running pdflatex twice should give you a nice document with Bibliographies at the end of each chapter. This [[https://github.com/habi/latex/tree/master/chapterbib|small example]] on my LaTeX-GitHub-repository should be fully self-contained and explain it from start to finish. ===== Record and correct Errata in documents ===== \documentclass{article} \usepackage[record,show]{errata} \usepackage{lipsum} \title{Full of Errors} \begin{document} \maketitle \section{short} Here we have \erratumAdd{forgotten word}{three} errata in one \erratumDelete{superfluous phrase}{darned} long \erratumReplace{translated}{Zeile}{line}. \lipsum[1] \section{long} \begin{erratum}[date=2006-07-19,reported-by=Michael Kohlhase,type=Replacement]{Text was replaced, added and deleted} This is a test of a long erratum: We can replace\eReplace{old text}{new text} and \eAdd{add new text} and finally delete old text\eDelete{alltogether}\ldots \end{erratum} \lipsum[1] \newpage \section{List of all \erratumReplace{replaced}{Erros}{Errors}} \PrintErrata % if you want to print errata from another document, use "\printerrata{path/to/otherdocument}" and use the option [record] for the errata-package in said document... \end{document} ===== Make a CD-Cover with \LaTeX===== \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{papercdcase} \usepackage[a4paper, margin=0pt]{geometry} \usepackage{mdwlist} \pagestyle{empty} \setlength{\parindent}{0pt} \begin{document} \setcdlatchmatter{\textsf{\textbf{\LARGE Artist\\Album}\\CD 1/2}} \setcdbackmatter{\textbf{\LARGE Artist\\[0.25\baselineskip] Album}\\ CD 1/2 \begin{enumerate} \item Track 1 \item Track 2 \item Track 3 \item Track 4 \item Track 5 \item Track 6 \item Track 7 \item Track 8 \item Track 9 \item Track 10 \end{enumerate}} \setcdspinematter{\textbf{\Large Spine Text}} \centering\papercdcase* \end{document} print and fold according to [[http://kahuna.merrimack.edu/~thull/CDcase/cd.pdf|this pdf]] ===== Formulas ===== And because I always forget: \documentclass[paper=a4,DIV=calc]{scrartcl} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{siunitx} \begin{document} \begin{eqnarray} E&=&h\nu\\ c&=&\lambda\nu\rightarrow\frac{c}{\lambda}=\nu\\ E&=&\frac{hc}{\lambda}\rightarrow\lambda=\frac{hc}{E}\\ \lambda&=&\frac{\SI{4.136e-15}{\electronvolt\second} \SI{2.997e8}{\metre\per\second}}{\SI{12.6}{\kilo\electronvolt}}\\ \lambda&=&\frac{\SI{1.24e-6}{\electronvolt\metre}}{\SI{12.6}{\kilo\electronvolt}}=\SI{9.838e-11}{\metre}\\ \lambda&\simeq&\SI{1}{\angstrom} \end{eqnarray} \end{document} ===== Add a small (text) overlay to a collection of PDFs ===== \usepackage{pdfpages} is quite a nifty way to collect several pdfs into one document((Especially if you have to do something a bit complicated, for example, submit a [[http://www.thoracic.org/global-health/itta/index.php|Travel Award Application]])) If your collated document should have correct numbering and references in the footer of the collected pages, \AddToShipoutPicture comes in handy. If you add \usepackage{pdfpages} \usepackage{lastpage} to your preamble you can add (e.g.) a discreet Footer like that: \includepdf[% pages=-,% pagecommand={\AddToShipoutPicture*{\put(10,10){Page \thepage/\pageref{LastPage}: Text}}}% ]{% PDF_to_be_added.pdf% } * "pages=-" adds all pages from "PDF_to_be_added.pdf" * "pagecommand=" tells pdfpages to add this command to the included pdf * \AddToShipoutPicture* actually adds to the page. Use the starred variant to add and replace the existing add, the unstarred just adds, leading to gibberish :) * "\put(10,10)" shifts a bit into the page * "{Page \thepage/\pageref{LastPage}: Text}" adds "Page X/Y: Text". A "\pagestyle{empty}" in the surrounding document comes in handy to get rid of the original pagenumbers. Doesn't look pretty, but does the trick with the collation of several documents