Samstag, 10. September 2011

Dienstag, 26. Juli 2011

Extension of "each nth point" for pgfplots

The option "each nth point={integer}" in pgfplots gives you the opportunity to plot only each nth point. This is necessary for instance for y error bars. However, the standard option does not allow you to specify an offset. In the following, two extensions are presented:

\makeatletter
\def\pgfplotsutil@decstringcounter#1{%
\begingroup
\c@pgf@counta=#1\relax
\advance\c@pgf@counta by -1
\edef#1{\the\c@pgf@counta}%
\pgfmath@smuggleone#1%
\endgroup
}%

\pgfplotsset{
/pgfplots/each nth point**/.style 2 args={%
/pgfplots/x filter/.append code={%
\ifnum\coordindex=0
\def\c@pgfplots@eachnthpoint@xfilter{#2}%
\def\c@pgfplots@eachnthpoint@xfilter@zero{0}%
\fi
\ifx\c@pgfplots@eachnthpoint@xfilter@zero\c@pgfplots@eachnthpoint@xfilter
\def\c@pgfplots@eachnthpoint@xfilter{#1}%
\else
\let\pgfmathresult\pgfutil@empty
\fi
\pgfplotsutil@decstringcounter\c@pgfplots@eachnthpoint@xfilter
}%
},
}

\pgfplotsset{
/pgfplots/each nth point*/.style 2 args={%
/pgfplots/x filter/.append code={%
\ifnum\coordindex=0
\def\c@pgfplots@eachnthpoint@xfilter{0}%
\edef\c@pgfplots@eachnthpoint@xfilter@cmp{#1}%
\else
\ifnum\coordindex>#2\relax
\pgfplotsutil@advancestringcounter\c@pgfplots@eachnthpoint@xfilter
\ifx\c@pgfplots@eachnthpoint@xfilter@cmp\c@pgfplots@eachnthpoint@xfilter
\def\c@pgfplots@eachnthpoint@xfilter{0}%
\else
\let\pgfmathresult\pgfutil@empty
\fi
\fi
\fi
}%
},
}
\makeatother



With each nth point**={integer}{integer} you can specify the offset by the second number. With each nth point*={integer}{integer} you can specify by the second number how many sampes in the beginning are plotted (without being skipped).

When using filters with pgfplots, it is useful to turn off the filter messages:

\pgfplotsset{filter discard warning=false} %Turn off filter messages

Montag, 30. Mai 2011

Space after a macro for text (xspace package)

Example from the xspace package:
After \newcommand{\gb}{Great Britain\xspace}
\gb is a very nice place to live.
Great Britain is a very nice place to live.
\gb, a small island off the coast of France.
Great Britain, a small island off the coast of France.

Freitag, 25. März 2011

Invisible Hyperrefs

Are you tired of blue/underlined/etc. hyperrefs in your LaTeX document? The following command results in "invisible" hyperrefs, i.e., they do not change the appearance of your document:


\usepackage[colorlinks=true, linkcolor=black, citecolor=black,
filecolor=black, urlcolor=black, bookmarks=true,
bookmarksopen=true, bookmarksopenlevel=3, plainpages=false,
pdfpagelabels=true, hypertexnames=false]{hyperref}


Of course, exchange black with the color of your text (...I assume that it is black.).

Widows and Orphans

Widows and orphans are typically considered bad style. While you may not want to completely forbid them in shorter documents like papers, avoiding them in a thesis etc. is mandatory.

An automatic layout that tends to completely avoid widows and orphans can be achieved by adding:

\clubpenalty = 10000
\widowpenalty = 10000
\displaywidowpenalty = 10000


A milder form that is more suitable for space constraint documents such as short papers is:

\clubpenalty = 150
\widowpenalty = 150
\displaywidowpenalty = 150


Some more information for particular document styles can also be found here.

Donnerstag, 24. März 2011

Dense Page Layout (Figure Placement)

Sometimes it happens that figures are on a page or column by themselves, i.e., there is space for text but no text actually put there. This prevents a dense layout. To achieve a more dense layout, add the following after the includes:
\renewcommand{\topfraction}{0.85}
\renewcommand{\textfraction}{0.1}
\renewcommand{\floatpagefraction}{0.75}

Found here

Acronym Hyphenation

The acronym package is quite useful. However, the hyphenation is prevented which might lead to overfull boxes. To enable the hyphenation for the acronym package, add the following somewhere after \include{acronym}.
\makeatletter
\renewcommand*\AC@get[3]{%
\ifx#1\relax
\PackageWarning{acronym}{Acronym `#3' is not defined}%
\textbf{#3!}%
\else
\expandafter#2#1%
\fi}
\makeatother

Found here