I followed the recipe at https://tex.stackexchange.com/questions/36109/making-tikz-nodes-hyperlinkable to create nodes that are clickable links to other places in the document. The node links work when built with lualatex, but don't seem to work when built with with xelatex at all -- though they do render to the screen as expected (the green overlay on the node is to demonstrate that hyperlink node is being invoked, it'll go away when I'm not debugging).
My MWE:
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[colorlinks,linkcolor=green!50!black]{hyperref}
\tikzset{
hyperlink node/.style={
alias=sourcenode,
append after command={
let \p1 = (sourcenode.north west),
\p2=(sourcenode.south east),
\n1={\x2-\x1},
\n2={\y1-\y2} in
node [draw=green!50!black,rounded corners,opacity=0.5,fill=green,inner sep=0pt,outer sep=0pt,anchor=north west,at=(\p1)] {\hyperlink{#1}{\phantom{\rule{\n1}{\n2}}}}
}
},
mynode/.style={rectangle, rounded corners, fill=white,draw=black},
edge/.style={>=Stealth},
}
\begin{document}
\begin{tikzpicture}
\node [mynode] (a) {Not a link};
\node [mynode,hyperlink node=LinkHere] (b) [right=30mm] {This is a link};
\path (a) -> (b);
\end{tikzpicture}
In text, though:
Not a link.
\hyperlink{LinkHere}{This is a link} also
\clearpage
This page deliberately left blank.
\clearpage
\hypertarget{LinkHere}{}
Link lands here.
\end{document}
Built with xelatex, clicking the green node doesn't take me to the third page, but clicking the text link (green text below, "This is a link") does. Both hyperlinks work when I build the PDF with lualatex.
Why does this work in lualatex but not xelatex, and what can I do about it? I otherwise like the output I get from xelatex (the layout and font rendering are a little different), but the links are important. What do I do to make the hyperlink node work correctly when building with xelatex?
Using
XeTeX 3.1415926-2.5-0.9999.3-2013060708 (TeX Live 2013)
LuaTeX, Version beta-0.76.0-2013061708 (TeX Live 2013) (rev 4627)
Simple invocation:
$ xelatex mwe.tex; mv mwe.pdf mwe-xelatex.pdf
$ lualatex mwe.tex; mv mwe.pdf mwe-lualatex.pdf
I have just determined that using the navigator.sty package instead of hyperref.sty exhibits the same difference in behavior when using \jumplink and \anchor instead of \hyperlink and \hypertarget.
Ah ha.
TL;DR: replace \hyperlink{#1}{\phantom{\rule{\n1}{\n2}}}} with
\hyperlink{#1}{\XeTeXLinkBox{\phantom{\rule{\n1}{\n2}}}}}
I added below the working (text) link:
\hyperlink{LinkHere}{\rule{1in}{1in}}
which is pretty much what I had in the hyperlink node. The rule was rendered in green because it was a \hyperlink, but clicking it did nothing when the PDF was compiled using xelatex. The problem isn't really with xelatex and TikZ, but with xelatex and hyperref.sty. Per https://tex.stackexchange.com/questions/56802/hyperlinking-a-drawing xelatex only links if it finds text.
\XeTeXLinkBox was added to hyperref.sty specifically to deal with this problem. You do still need to use the \phantom{} to hide the rule.
Slightly more than MWE that does do what I want, and demonstrates the difference of using \XeTeXLinkBox and not using it.
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[colorlinks,linkcolor=green!50!black]{hyperref}
\setlength{\XeTeXLinkMargin}{0pt}
\tikzset{
hyperlink node/.style={
alias=sourcenode,
append after command={
let \p1 = (sourcenode.north west),
\p2=(sourcenode.south east),
\n1={\x2-\x1},
\n2={\y1-\y2} in
node [draw=green!50!black,rounded corners,opacity=0.5,fill=green,inner sep=0pt,outer sep=0pt,anchor=north west,at=(\p1)] {\hyperlink{#1}{\XeTeXLinkBox{\phantom{\rule{\n1}{\n2}}}}}
}
},
mynode/.style={rectangle, rounded corners, fill=white,draw=black},
edge/.style={>=Stealth},
}
\begin{document}
\begin{tikzpicture}
\node [mynode] (a) {Not a link};
\node [mynode,hyperlink node=LinkHere] (b) [right=30mm] {This is a link};
\path (a) -> (b);
\end{tikzpicture}
In text, though:
Not a link.
\hyperlink{LinkHere}{This is a link} also
---
\hyperlink{LinkHere}{test\ldots \rule{1in}{1in}\ldots big green box doesn't work, text does}
---
\hyperlink{LinkHere}{test\ldots \XeTeXLinkBox{\rule{1in}{1in}}\ldots big green box now \emph{does} work, and so does text}
---
\clearpage
This page deliberately left blank.
\clearpage
\hypertarget{LinkHere}{}
Link lands here.
\end{document}
Related
I've created an example environment for my maths notes. It takes the title of the example as the input and draws some lines with tikz. However, to do so, it requires the length of the title.
This is relatively easy to do when the environment is only called once by using \newlength{\lengthname} followed by \settowidth{\lengthname}{[length]}. However, as soon as it is called more than once, a different length must be defined. My (admittedly poor) work-around has been to pass the name of a different length, #2, every time I use my example environment.
How can I create a unique \newlength{\unique} each time I use my environment, or, is there some better way of achieving my goal?
\newenvironment{example}[2] % Example Environment
{\refstepcounter{example}
\newlength{#2}
\settowidth{#2}{\small \textbf{Example \thesection.\theexample} --- #1}
\bigskip\begin{tikzpicture}
\draw (-0.5\columnwidth,-0.2)--(-0.5\columnwidth,0)--(0.5\columnwidth,0)--(0.5\columnwidth,-0.2);
\fill[white] (-0.5#2-5pt,-1pt) rectangle (0.5#2+5pt,1pt);
\tikzlabel{0}{-0.4}{\text{\small \textbf{Example \thesection.\theexample} --- #1}}
\end{tikzpicture}}
%
{\begin{tikzpicture}
\draw (-0.5\columnwidth,0.2) -- (-0.5\columnwidth,0) -- (0.5\columnwidth,0) -- (0.5\columnwidth,0.2);
\end{tikzpicture}}
Many thanks.
My suggestion would be to use tcolorbox instead of drawing the frame yourself, but if you must use tikz, simply use a white background for your title.
Please note that your code would produce a lot of overfull box warnings. You have to consider the indention and drawing a frame of column won't fit because you need an additional two times the half the width of the tikz lines. I simply reduced the width to .49\columnwidth, but you could also take into account the width of the line in your calculation.
Also pay attention to the spacing around the ---. If you don't prevent the macro before from swallowing the space, it won't be centred.
\documentclass{article}
\usepackage{tikz}
\newcounter{example}
\newenvironment{example}[1]{%
\refstepcounter{example}%
\bigskip
\noindent%
\begin{tikzpicture}
\draw (-0.49\columnwidth,-0.2)--(-0.49\columnwidth,0)--(0.49\columnwidth,0)--(0.49\columnwidth,-0.2);
\node[fill=white,font=\small\bfseries] at (0,-1pt) {Example \thesection.\theexample{} --- #1};
\end{tikzpicture}%
\par%
}{%
\par%
\noindent%
\begin{tikzpicture}
\draw (-0.49\columnwidth,0.2) -- (-0.49\columnwidth,0) -- (0.49\columnwidth,0) -- (0.49\columnwidth,0.2);
\end{tikzpicture}%
\par%
}
\begin{document}
\begin{example}{test}
content...
\end{example}
\end{document}
I have been searching for some automated way of numbering the references on the same slide in beamer Madrid with biblatex. This works fine with \pause and \footcite{}. But when I have multiple bullets on the same slide (e.g. 5), and I want to cite for the last point, the problem is that the reference appears from the very first slide. I want that the reference appears only when the relevant slide appears (i.e. 5th one in this case)
\documentclass{beamer}
\mode<presentation>{\usetheme{Madrid}}
\usepackage[style=verbose]{biblatex}
\only<2->{...} etc. is one solution but I think it is a lot of manual work to update all numbers on the slide when, for instance, I need to remove (or add) one point with a reference.
Thanks.
You don't need to update any numbers if you use relative overlays instead of absolute numbers:
\documentclass{beamer}
\mode<presentation>{\usetheme{Madrid}}
\usepackage[style=verbose]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\begin{frame}
\begin{itemize}[<+->]
\item ABC \only<.->{\footcite{knuth:ct:a}}
\item XYZ \only<.->{\footcite{knuth:ct:b}}
\end{itemize}
\end{frame}
\end{document}
This is a follow-up to a question I posted earlier (How to center LaTeX xtable output in full text width).
I realize that my MWE from this previous post was incomplete. In an effort to make it as minimal of an example as possible, I did leave out something that ended up conflicting. Hence, here, I am posting the issue more fully.
I am using tufte-handout (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) to create a small report in latex. I have a file code.Rnw that I knit into code.tex. Below is my code.Rnw:
\documentclass[12pt,english,nohyper]{tufte-handout}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage[space]{grffile}
\usepackage{geometry}
\usepackage{pgffor}
\usepackage{calc}
\usepackage{enumitem}
\usepackage{microtype}
\usepackage{tabularx}
%\usepackage{floatrow}
\begin{document}
<<include=FALSE>>=
library(ggplot2)
library(xtable)
#
\begin{fullwidth}
\makeatletter\setlength\hsize{\#tufte#fullwidth}\makeatother
<<echo=FALSE,results='asis'>>=
x.big <- xtable(mtcars[1:10,1:4], label ='tab:mtcars',caption ='This is the mtcar dataset head.',align = c("rr|lr|r"))
print(x.big, tabular.environment ='longtable', floating = FALSE, include.rownames=FALSE)
#
\end{fullwidth}
<<echo=FALSE,results='asis'>>=
fnameO <<- "plot.pdf"
pdf(paste0("./",fnameO),width=6,height=7)
print(qplot(hp, mpg, data=mtcars, main="Scatterplots of MPG vs. Horsepower", xlab="Horsepower", ylab="Miles per Gallon"))
{dev.off();invisible()}
#
\begin{fullwidth}
\makeatletter\setlength\hsize{\#tufte#fullwidth}\makeatother
\begin{figure}[!ht]
\includegraphics[width=\linewidth]{\Sexpr{fnameO}}
\caption{This is a plot of the mtcars dataset from R. It compares the horsepower with the miles per gallon. It uses the qplot function from ggplot2.}
\label{fig:LearningObj_summary}
\end{figure}
\end{fullwidth}
\end{document}
This is the output:
I am desiring to have both the table and the figure centered (across the whole page). As shown above, I am successfully able to get the table centered (thanks to advice from a user in my previous post).
However, I am unable to get the figure centered across the whole page with the caption below it. Instead, likely due to the document class I am using (tufte-handout), the figure itself is in the non-margin area, and its caption is in the margin area.
For starters, I uncommented the \usepackage{floatrow} in the code, in an attempt to force the figure caption to be below the figure instead of to the right of it. This lead to an output as such (where both the table and figure are undesirably on the left side instead of centered, but the figure caption is indeed below the figure):
My question is: How can I center both the table and figure (with the caption below it), so that the output would look more like this?:
Thank you.
As a crude hack, you could simply modify the figure environment of your MWE to use the original \caption command:
\begin{fullwidth}
\begin{figure}[!ht]
\makeatletter\setlength\hsize{\#tufte#fullwidth}\setlength\linewidth{\#tufte#fullwidth}\let\caption\#tufte#orig#caption\makeatother
\includegraphics[width=\linewidth]{\Sexpr{fnameO}}
\caption{This is a plot of the mtcars dataset from R. It compares the horsepower with the miles per gallon. It uses the qplot function from ggplot2.}
\label{fig:LearningObj_summary}
\end{figure}
\end{fullwidth}
...or, for a bit smaller figure that is centered on the page:
\begin{fullwidth}
\begin{figure}[!ht]
\makeatletter\setlength\hsize{\#tufte#fullwidth}\setlength\linewidth{\#tufte#fullwidth}\let\caption\#tufte#orig#caption\makeatother
\centering
\includegraphics[width=.4\linewidth]{\Sexpr{fnameO}}
\caption{This is a plot of the mtcars dataset from R.}
\label{fig:LearningObj_summary}
\end{figure}
\end{fullwidth}
If you find the original \caption command lacking and if none(!) of the floats in your document need to use tufte captions you can overwrite the \caption command using something like \usepackage[labelfont=bf,compatibility=false]{caption}.
How can I include a tikzpicture on every page?
I would like to create a complicated document template (page should be framed, and have a table to hold document information both in the header and footer).
I was thinking of using something like:
\begin{tikzpicture}[remember picture,overlay]
% complicated layout should be here, simple example is given below:
% \node [xshift=1cm,yshift=1cm] at (current page.south west)
% {This is an absolutely positioned text in the page};
\end{tikzpicture}
Do you have any other suggestions on how to create such a template?
Add information to header/footer either using fancyhdr Or KOMA Script
For adding a something on every page I used this:
\usepackage{eso-pic}
\makeatletter
\AddToShipoutPicture{%
\setlength{\#tempdimb}{.1\paperwidth}%
\setlength{\#tempdimc}{.04\paperheight}%
\setlength{\unitlength}{1pt}%
\put(\strip#pt\#tempdimb,\strip#pt\#tempdimc){%
\makebox(0,0){ \textcolor{gray}{Rev: \svnrev{} (\svnfilerev)} }%
}%
}
\makeatother
Here, I add the SVN revision number on the bottom right of every page. I don't remember why I did not use a tikzpicture[overlay,remember picture] in \AddToShipoutPicture, maybe because it can't remember the picture position in the state of shipping out the page.
Hope that helps.
I am using the beamer document class in latex to make a presentation. I will have a number of back up slides which are there for offline viewing, reference etc. Beamer has a feature that shows the progress through the presentation as {page#}/{total pages} on each slide. I would really like it if {total pages} was equivalent to my total number of pages w/out counting the back up slides (I don't want to discourage my audience on the first page!). Does anyone know how this can be done?
This can now be achieved with the following option on all "backup" slides:
\begin{frame}[noframenumbering]{My Title}
\end{frame}
Source
This will cause the final number (e.g. 25/25) to be displayed on such pages.
As always, a matter of taste.
This can be done with the appendixnumberbeamer package. Just add \usepackage{appendixnumberbeamer} to the preamble and use \appendix before the first backup slide.
I have defined two commands to do this:
\newcommand{\beginbackup}{
\newcounter{framenumbervorappendix}
\setcounter{framenumbervorappendix}{\value{framenumber}}
}
\newcommand{\backupend}{
\addtocounter{framenumbervorappendix}{-\value{framenumber}}
\addtocounter{framenumber}{\value{framenumbervorappendix}}
}
You can then use \beginbackup and \backupend before and after your backup slide to adjust the number of slides.
For my beamer template I also like to add
\setbeamertemplate{footline}{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
\usebeamerfont{author in head/foot}\insertshortauthor~~(\insertshortinstitute)
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
\usebeamerfont{title in head/foot}\insertshorttitle
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
\insertframenumber{} \hspace*{2ex} % hier hat's sich geändert
\end{beamercolorbox}}%
\vskip0pt%
}
in the definition of the \beginbackup command to hide to total page number in the backup slides, otherwise you'll get something like "24/18".
Using all this, your slides will be numbered like "x/Y" for all slides before the backup, where Y is the total number of slides before the first backup slide, and the backup slides will continue the numbering of the previous slides.
To manually fix the total frame count to a certain number, say 25, you could add the following command
\renewcommand{\inserttotalframenumber}{25}
right after the \begin{document} command.
You can also add the \appendix command right before the beginning of your backup slides, so that the corresponding sections/subsections do not appear in the table of contents/navigation structure.
It should be possible to tweak the renewcommand above so that it automatically uses the last frame number before the appendix, but I don't know how to do it.
Just insert
\renewcommand{\inserttotalframenumber}{\pageref{lastslide}}
after \begin{document}, and place the marker
\label{lastslide}
on your last slide.
You can put all of your backup slides in appendix and use the appendixnumberbeamer package.
\documentclass[12pt]{beamer}
\usepackage{appendixnumberbeamer}
\begin{document}
\begin{frame}{Frames that counts}
\end{frame}
\appendix
\begin{frame}{Backup slides}
\end{frame}
\end{document}
Fanfan, thanks for your answer, your answer steered me to this sty file that one can include in a beamer document class that will automatically count only the number of frames before the appendix, and then restart the a separate count for the appendix slides, pretty neat.
http://www.ensta.fr/~lelong/Latex/appendixnumberbeamer.sty
Thanks also to Jérôme LELONG for having this available online.
The great command \insertpresentationendpage will take care of your problem. Just place \appendix at the begin of your backup slides.
\documentclass[t]{beamer}
\usepackage[absolute,overlay]{textpos}
\setbeamertemplate{navigation symbols}{}
\def\insertpresentationendframe{\inserttotalframenumber}
\makeatletter
\g#addto#macro{\appendix}{\immediate\write\#auxout{\string\#writefile{nav}{\noexpand\headcommand{\noexpand\def\noexpand\insertpresentationendframe{\the\c#framenumber}}}}}
\makeatother
\setbeamertemplate{footline}{%
\begin{picture}(54,12.5)(0,0)
\put(0.9,0.52){%
\begin{minipage}[b][12.5mm][c]{112.5mm}
\raggedleft
\insertframenumber/\insertpresentationendframe
\end{minipage}
}
\end{picture}
}
\begin{document}
\begin{frame}
slide in the main part
\only<2>{blub}
\end{frame}
\appendix
\section*{Backup}
\begin{frame}
\frametitle{backup}
not counting in the total frame number
\end{frame}
\end{document}
Another possibility - which was recently added to beamer - is to use the appendixframenumber template:
\documentclass[t]{beamer}
\setbeamertemplate{footline}{
\hfill%
\usebeamercolor[fg]{page number in head/foot}%
\usebeamerfont{page number in head/foot}%
\setbeamertemplate{page number in head/foot}[appendixframenumber]%
\usebeamertemplate*{page number in head/foot}\kern1em\vskip2pt%
}
\begin{document}
\begin{frame}
slide in the main part
\only<2>{blub}
\end{frame}
\appendix
\section*{Backup}
\begin{frame}
\frametitle{backup}
not counting in the total frame number
\end{frame}
\end{document}