How to use TikZ externalize with PGFgantt

I recently switched on tikzexternalize on a document with several figures created by TikZ in it. Activating this Tikz library has the advantage of compiling the figures only once (if unchanged), speeding up the creation of the completed document. As a nice side benefit, one gets the images as separate PDF files, which in my case was the main motivation. One simple call to ImageMagick later, one has all images in a format of choice. However, I could not get it to work at first due to my using the PGFgantt package to create a gantt time chart. Here is the (not compiling) start point: Continue reading “How to use TikZ externalize with PGFgantt”

Finally the definitive full-frame graphic commands for beamer in LaTeX

After my two (!) previous posts on the same topic, it’s time to give my final entry for the competition of the definitive full-frame graphics command for use with beamer in LaTeX. To seal the deal, I do not propose 1, but 4 commands, depending on your use case: Continue reading “Finally the definitive full-frame graphic commands for beamer in LaTeX”

How to only color external links in LaTeX

Package hyperref is quite handy for making a compiled LaTeX document more accessible, by allowing to quickly jump to references (back to the text with package backref), section headings (from the table of contents) and weblinks.

By default, links are marked by a coloured rectangles, which only appear on screen, not in print. If one wants to get rid of the rectangles, there are options. However, there is also the colorlinks that marks hyperlinks by changing their text colour. However, these makes all link types become coloured. There is a way to reset certain link types to the default text colour, just by setting their colour to an empty value like this:

\hypersetup{colorlinks=true,linkcolor=,urlcolor=blue}

The trick is the empty value for linkcolor. It applies to internal links (e.g. entries in the table of contents listing), which are thus not touched. This trick can be extended to the other fields citecolor, anchorcolor if needed, to either not change or change their colour.

The definitive full-frame graphic command for beamer in LaTeX

2018-06-02: This content has been superseded by this newer post: Finally the definitive full-frame graphic commands for beamer in LaTeX. Look there for an updated version.

After my previous post on the same topic, I have improved upon the command considerably. This time, it is based on Matthew Leingang’s answer on the question Image on full slide in beamer package.

Usage:

\fullframegraphic[optional credits]{path/to/image}

To use, copy this definition in your preamble. Requires package tikz.

\newcommand{\fullframegraphic}[2][]{%
\begin{frame}%
\begin{tikzpicture}[remember picture,overlay]%
\node[at=(current page.center)] {%
\includegraphics[height=\paperheight,width=\paperwidth,keepaspectratio]{#2}%
};%
% optional argument: credits on lower-right corner
\ifx\relax#1\relax\else%
\node[at=(current page.south east), anchor=south east,font=\tiny,text=white,fill=black,fill opacity=.5,text opacity=1,inner sep=2pt,text height=1ex,text depth=.25ex] {#1};%
\fi%
\end{tikzpicture}%
\end{frame}}

Visual example (for the credits overlay):

fullframegraphic-DA_Cambridge_c1937

Source: File:DA_Cambridge_c1937.jpg on Wikimedia Commons

How to horizontally align beamer columns with surrounding text

If you (like me) assumed that placing two columns width 50% of textwidth next to each other would align with preceding or following text on a beamer slide, then you are mistaken (like me).

Fortunately, a discussion on Bug #262: Provide more usable columns environment showed a viable solution in form of the optional argument onlytextwidth.

However, in order to use it successfully, one must then take care of spacing oneself. Here is my result of some experimentation:

beamer-columns-to-textwidth

Here is the corresponding document source code:

\documentclass{beamer}
\usepackage{mathtools}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}

\usepackage{hyperref}

\begin{document}
\begin{frame}{Testing columns spacing}{How to achieve 
correctly spaced columns with beamer}
\emph{The documentation doesn't tell you anything about 
the alignment of the columns or the space in between them.
In particular, the side effect of totalwidth (which 
changes the columns to be left aligned within the 
textarea of the slide rather than center aligned on the 
page).}
\vspace{.5cm}
\begin{columns}[t,onlytextwidth]
\begin{column}{.5\textwidth-.25cm}
This slide shows the successfull result to align the 
margins of these two columns with the surrounding text to 
exactly \lstinline{\\textwidth}.
\end{column}
\begin{column}{.5\textwidth-.25cm}
What to do?

Do your own math and specify column widths with spacing. 
These columns have equal width of 
\lstinline{.5\\textwidth-.25cm}.
\end{column}
\end{columns}
\vspace{.5cm}
From: 
\href{https://bitbucket.org/rivanvx/beamer/
issue/262/provide-more-usable-columns-environment}
{Issue \#262}: Provide more usable columns environment}
\end{frame}
\end{document}

Full-frame graphics on a LaTeX beamer presentation

2018-06-02: This content has been superseded by this newer post: Finally the definitive full-frame graphic commands for beamer in LaTeX. Look there for an updated version.

This snippet defines the custom command \fullframegraphic. Paste it into the document preamble (header) of your presentation:

\newcommand{\fullframegraphic}[1]{
\begin{frame}
\includegraphics[height=\textheight,width=\textwidth,keepaspectratio]{#1}
\end{frame}
}

Then, you can create a full-frame graphic slide anywhere (outside a frame) using

\fullframegraphic{image}

Further reading

How to use TikZ for inline polygons

The trick is to define inner sep=0pt when beginning the tikzpicture environment, as I learned from pgf bug report #172 minimum size in regular polygon fails for small length from last year. Here is a minimum working example, adapted to my use case of inline polygon symbols with roughly text height, i.e. 2ex in my case:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\newcommand{\poly}[2]{\tikz[inner sep=0pt] {%
\node[regular polygon,%
regular polygon sides=#1,%
regular polygon rotate=#2,%
minimum size=2ex, fill] (0,0) {};}}

\begin{document}
Triangle upwards \poly{3}{0}, 
triangle downward \poly{3}{180} 
and diamond \poly{4}{45}.
\end{document}

This snippet yields the following result:

tikz-poly

How to use custom colours in LaTeX

I will post short minimum working examples (MWEs) of minimal LaTeX documents, showing a certain feature in action. Though the well-maintained LaTeX Wikibook is a much more extensive resource than a collection of such examples could ever be, they show directly compilable examples compared to isolated snippets.

I start simple: custom text colours, using different colour models. Shown here are RGB (0-255) and HTML (00-FF) style definitions. The text shows two different ways to access them. Bonus: these colours can be used in TikZ as well.

latex-xcolors

\documentclass{article}
\usepackage{xcolor}
\definecolor{cool}{RGB}{0, 110, 220}
\definecolor{heat}{RGB}{240, 120, 40}
\definecolor{pink}{HTML}{FF00FF}
\begin{document}
I am some \textcolor{heat}{really hot}, 
though \textcolor{cool}{also cold} text.
{\color{pink}Bright colors} are discouraged.
\end{document}