Tikzpicture on every page - latex

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.

Related

Tall skinny figure along side of page in LaTeX document?

Looking for the best way to fit a figure tightly that spans the full height of a page. I'm writing a document about the ionosphere and want to include this image along the side: https://en.wikipedia.org/wiki/Thermosphere#/media/File:EarthAtmosphereBig.jpg
Seems like a job for minipage but I can't quite figure out a good solution. Any tips?
You can achieve this by placing two minipages, one with a larger width than the other, side-by-side.
\documentclass[12pt]{article}
\usepackage[demo]{graphicx} %demo option should be omitted in real document
\usepackage{lipsum} %for random text, should be omitted in real document
%--------%Shows page layout, also should be omitted in real document.
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%--------%Idea from Zarko of TEX.SE
\begin{document}
\begin{minipage}{0.8\textwidth}
\lipsum[1-3]
\end{minipage}
\begin{minipage}[r]{0.2\textwidth}
\centering
\includegraphics[width=0.2\textwidth, height=\textheight]{demo.png}
\end{minipage}
\end{document}

Koma scrbook seems not to include BCOR

The proof copies of a book laid out with KOMA scrbook show that the inner margins are too narrow. I had BCOR set to 10mm and want to increase them, but my experiments with BCOR set to 20mm show that the layout is the same independent what BCOR value I set. Here my MWE:
\documentclass{scrbook}
\KOMAoptions{paper=
128.5mm:198.4mm, %(5,06" x 7,91") %ziel
BCOR=20mm,
twoside,
headinclude=false, footinclude=false,
headings=normal,
titlepage=true,
% draft=true,
DIV=9, %ziel kleines buch
fontsize=12pt,
}
\usepackage[german]{babel}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage[a4,axes,cross,pdftex,center]{crop}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\part{ Philosophie}
some text
\lipsum
\lipsum
\end{document}
What is wrong?
My real question is: how can I just move the text area on both pages to the outside (i.e. making the gutter wider) without changing the text area size (and thus preserve line breaks)?
I found a hint in some other questions answered before and the problem was caused by the interaction between the KOMA script and the geometry package. Using the geometry package recalculates the page layout and overwrites the one calculated by scrbook including the BCOR value. This can be avoided when adding the option pass to geometry as in
`\usepackage[pass]{geometry}`.
In general the interaction between the layout calculated by KOMAscript and other package can lead to surprises. The discussion in https://tex.stackexchange.com/questions/182821/div-and-bcor-setting-in-koma-best-practices/183839 is very useful.

How to center LaTeX xtable (And Figure) output in full text width

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}.

Latex - Change margins of only a few pages

I have a Latex document where I need to change the margins of only a few pages (the pages where I'm adding a lot of graphics).
In particular, I'd like to change the top margins (\voffset). I've tried doing:
\addtolength{\voffset}{-4cm}
% Insert images here
\addtolength{\voffset}{4cm}
but it didn't work. I've seen references to the geometry package, but I haven't found how to use it for a bunch of pages, and not for the whole document.
Any hints?
Use the "geometry" package and write \newgeometry{left=3cm,bottom=0.1cm} where you want to change your margins. When you want to reset your margins, you write \restoregeometry.
I've used this in beamer, but not for general documents, but it looks like that's what the original hint suggests
\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}
Then to use it
\begin{changemargin}{-1cm}{-1cm}
don't forget to
\end{changemargin}
at the end of the page
I got this from Changing margins “on the fly” in the TeX FAQ.
I was struggling a lot with different solutions including \vspace{-Xmm} on the top and bottom of the page and dealing with warnings and errors. Finally I found this answer:
You can change the margins of just one or more pages and then restore it to its default:
\usepackage{geometry}
...
...
...
\newgeometry{top=5mm, bottom=10mm} % use whatever margins you want for left, right, top and bottom.
...
... %<The contents of enlarged page(s)>
...
\restoregeometry %so it does not affect the rest of the pages.
...
...
...
PS:
1- This can also fix the following warning:
LaTeX Warning: Float too large for page by ...pt on input line ...
2- For more detailed answer look at this.
3- I just found that this is more elaboration on Kevin Chen's answer.
\par\vfill\break % Break Last Page
\advance\vsize by 8cm % Advance page height
\advance\voffset by -4cm % Shift top margin
% Start big page
Some pictures
% End big page
\par\vfill\break % Break the page with different margins
\advance\vsize by -8cm % Return old margings and page height
\advance\voffset by 4cm % Return old margings and page height
For figures you can use the method described here :
http://texblog.net/latex-archive/layout/centering-figure-table/
namely, do something like this:
\begin{figure}[h]
\makebox[\textwidth]{%
\includegraphics[width=1.5\linewidth]{bla.png}
}
\end{figure}
Notice that if you have subfigures in the figure, you'll probably want to enter into paragraph mode inside the box, like so:
\begin{figure}[h]
\makebox[\textwidth]{\parbox{1.5\textwidth}{ %
\centering
\subfigure[]{\includegraphics[width=0.7\textwidth]{a.png}}
\subfigure[]{\includegraphics[width=0.7\textwidth]{b.png}}
\end{figure}
For allowing the figure to be centered in the page, protruding into both margins rather than only the right margin.
This usually does the trick for images. Notice that with this method, the caption of the image will still be in the delimited by the normal margins of the page (which is a good thing).
A slight modification of this to change the \voffset works for me:
\newenvironment{changemargin}[1]{
\begin{list}{}{
\setlength{\voffset}{#1}
}
\item[]}{\end{list}}
And then put your figures in a \begin{changemargin}{-1cm}...\end{changemargin} environment.
Look up \enlargethispage in some LaTeX reference.
I could not find a easy way to set the margin for a single page.
My solution was to use vspace with the number of centimeters of empty space I wanted:
\vspace*{5cm}
I put this command at the beginning of the pages that I wanted to have +5cm of margin.
This worked for me:
\newpage % larger page1
\enlargethispage{1.5cm} % more room for text or floats
\advance\voffset by -0.5cm % reduce top margin
\advance\footskip by 1cm % lower page number
Some content
\newpage % larger page2
\enlargethispage{1.5cm}
Some content
...
\newpage % return to normal page
\advance\voffset by 0.5cm
\advance\footskip by -1cm
I had the same problem in a beamer presentation. For me worked using the columns environment:
\begin{frame}
\begin{columns}
\column{1.2\textwidth}
\begin{figure}
\subfigure{\includegraphics[width=.49\textwidth]{1.png}}
\subfigure{\includegraphics[width=.49\textwidth]{2.png}}
\end{figure}
\end{columns}
\end{frame}

Ignoring page numbers in backup slides

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}

Resources