How to have a fixed size number that depends on the slide in latex beamer / tikz? - latex

I have a tikz picture with a circle node which has a number inside.
I want this number to change with the slides but to be of fixed size. (-> not mess up the circle).
This one isn't working, the circle gets as big as if it has to hold all 3 numbers.
\tikz[baseline]
\node [fill=blue!20,draw,circle,anchor=base] (node1)
{
\only<1-3>{3} \only<4-6>{8} \only<7->{11.5}
};
Here the values are 3 on slides 1-3, 8 on slides 4-6 and else 7.

I observed the following:
The spaces between \only{} are always rendered (\only, when not active, is a "zero-width character"; TeX does not discard spaces between characters)
Set the width of the text explicitly using "text width=...". This implicitly puts the content into a minipage.
Note that the "baseline" property does not work anymore as expected.
"text centered" ensures the alignment for the case that the content is not exactly "text-width"
The "overprint" environment only automatically determines the height of the content, not the width.
To conclude, this works for me (I tried it):
\tikz[baseline]
\node [fill=blue!20,draw,circle,anchor=base,text width=4ex,text centered,inner sep=0] (node1)
{
\only<1-3>{3}\only<4-6>{8}\only<7->{11.5}
};
EDIT: This works with the correct baseline:
\tikz[baseline=(node1.base)]
\node [fill=blue!20,draw,circle] (node1)
{
\begin{minipage}{4ex}
\centering
\only<1-3>{3}\only<4-6>{8}\only<7->{11.5}
\end{minipage}
};

There are a couple of ways to do this:
You could use a 'overlay' environment which calculates the maximum size needed.
You could use \makebox[width]{ }.
Or simply use the 'minimum width' and 'minimum height' options on the node.
...

Related

Overlaying off-margin figure over another on Latex using Tikz

I was hoping anyone could help me with this. I am working with Latex and the Tikz package (I'm a new user on both) on a document cover using 2 figures so it looks like this:
That is, the background image leaves a thin margin on all sides, and the logo falls off-margin to the right and bottom. So, I enter the code overlaying the the logo over the background using Tikz, and as soon as I edit the coordinates to get the logo to go off-margin either on the right or bottom, the background image starts moving to the left and top until it sticks to the opposing borders of the page, like this:
My question is, is there a way to have the superimposing image to fall off the margins while keeping the background image properly centered?
Here is the code I'm using:
\usepackage{mwe,tikz}
\begin{figure}
\begin{tikzpicture}[
every node/.style={anchor=south west,inner sep=20pt},
x=1mm, y=1mm,
]
\node (fig1) at (0,0)
{\includegraphics[scale=0.2]{Images/Background.jpg}};
\node (fig2) at (124,-23)
{\includegraphics[scale=1.5]{Images/Logo.png}};
\end{tikzpicture}
\end{figure}
I first tried using the Overpic package instead, but I found it to be rather limited (or I couldn't figure it out well enough probably). I then tried using \centering and other horizontal and vertical centering techniques in combination with Tikz, but to no avail.
A figure environment is a floating objects, which allows latex to find a good location within the text flow. If you want an image at a very specific position, like a title page, you shouldn't use a figure environment
using the overlay option will make sure that the actual size of the tikzpicture does not influence the positioning and thus a cutoff logo won't influence the rest of the page
I also suggest the remember picture option which allows you to position your nodes with respect to the page. This way you can place the big picture in the centre of the page and the smaller picture at the lower right corner (shift it around with the xshift and yshift keys)
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.center) {\includegraphics[width=.9\paperwidth,height=.9\paperheight]{example-image-10x16}};
\node at ([xshift=-2cm,yshift=1cm]current page.south east) {\includegraphics[width=15cm]{example-image-duck}};
\end{tikzpicture}
\end{document}

Position text in margin relative to paper border

I'm trying to write a macro that positions text in the margin of a LaTeX document. The text should appear in the same line the macro is called. Horizontal text position should be relative to the absolute border of the paper rather than the left side of the text.
I tried with the tabto package using the \tabto* command and then jump back to the location in the text with \tabto*{\TabPrevPos}. This works well but since tabto positions relative to the border of the text the result is different if you are in a list environment or similar.
So the whole command looks similar to:
\newcommand{\sidenote}[1]{%
\tabto*{\sidenoteskip}%
\smash{%
\begin{minipage}[t][1ex][t]{\sidenotewidth}%
\textbf{#1}%
\end{minipage}%
}%
\tabto*{\TabPrevPos}%
}
Does anywone have an idea how I can position the minipage relative to left paper border and jump back to the location where the macro was called?

Center background image on page within margins using eso-pic

In my thesis I'm including already published papers. I've extracted pages as individual EPS files and I'm shrinking them so they fit on one page within the margins (\pageScale).
\hfill{}\includegraphics[scale=\pageScale]{Integrative-Theory-Associative/eps-pages/page-1}\hfill{}
While this works ok, the pages appear extremely small to fit in the margins. I'd like to increase the size of the graphics beyond the margins such that header and page number information would overlap with margins of the inserted pages.
eso-pic allows me to fill the whole page with my inserted pages, but the header and page number overlap with the text in the inserted pages:
\mbox{}
\AddToShipoutPictureBG*{
\includegraphics{Integrative-Theory-Associative/pdf-pages/page-1.pdf}
}
\newpage
I's like to scale down and centre the graphics on the page so they are as big as possible while text within the graphics is not behind the header and is within the margins.
I don't mind manually figuring out the right scale for graphics, but I can't figure how to place the centre of a smaller graphic in the centre of the margins. \AtPageCenter
does not do what I expected, centre the centre of the graphic, not centre the lower left of the graphic.
In the example below I've used some of adjustbox's prowess to adjust included content:
\documentclass{article}
\usepackage{fancyhdr,lipsum}% Just for this example
\fancyhf{}
\fancyhead[C]{This is some random header text}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{.4pt}
\renewcommand{\footrulewidth}{.4pt}
\pagestyle{fancy}
\usepackage[export]{adjustbox}
\usepackage{eso-pic}
\newcommand{\pictureincenteroftextblock}[2][]{%
\AddToShipoutPictureBG*{%
\AtTextLowerLeft{%
\raisebox{.5\textheight}{%
\hspace*{.5\textwidth}%
\makebox[0pt]{\includegraphics[max width=\textwidth,max height=\textheight,valign=c,#1]{#2}}%
}%
}%
}%
}
\begin{document}
\lipsum[1-5]
\clearpage
\mbox{}% Just put something on this page.
\pictureincenteroftextblock{example-image-a}
\clearpage
\mbox{}% Just put something on this page.
\pictureincenteroftextblock{example-image-10x16}
\clearpage
\mbox{}% Just put something on this page.
\pictureincenteroftextblock{example-image-1x1}
\clearpage
\mbox{}% Just put something on this page.
\pictureincenteroftextblock{example-image-a4}
\end{document}
With the [export] option, adjustbox adds its key-values to graphicx's \includegraphics options. Those I've used are max width and max height which will shrink the included image (or page from a PDF) if the width or height exceeds these maxima while still maintaining the included image/page aspect ratio. Additionally, valign=c will align the content in a vertically centred fashion.
eso-pic is used to place the image in the background, starting at the lower-left part of the text block. Then, through standard spacing commands, it's raised into position (\raisebox) and shoved over (\hspace) to the centre of the text block. Finally the image is horizontally centred (\makebox[0pt]).

How do i center a quote, vertically and horizontally in latex?

I have a quote on a blank page in latex. I have managed to center it horizontally, however, when i try to center it vertically it gives me some problems. I have tried
\vspace{}
\begin{quote}
\centering
quote
\end{quote}
However it doesnt work.
Try this:
\vspace*{\fill}
\begin{quote}
\centering
quote
\end{quote}
\vspace*{\fill}
You can also use increments of \paperheight. For instance if you wish to have the quote 1/3 down the page you can do
\vspace*{0.15\pageheight}
\begin{quote}
\centering
quote
\end{quote}
\newpage
Note:
The multiplication factor is based on having twice the pageheight, therefore 1/3 = 0.3 . 0.3/2 = 0.15 -> 0.15\pageheight
Rather than adding a fraction of vertical space underneath it is easier to tell continuing content to start at the top of the next page with \newpage.

get height on a block of latex output

I am trying to determine how to get the height on a block of latex output (not the whole document, and not the code..but rather a block of output). As an example of what I am trying to accomplish: i were to have the latex code
$\sum_{i=0}^\infty \frac{1}{n}>\infty$ \newline hello world \newline hello universe
The height of the above block of text is dependent on a number of things-font, margin size, and of course what the text is, as changing any of these parameters changes how many inches that output would be, but with default formatting its output would be something like 2 inches high.
I am hoping there is a package that does this!
Usually, the trick is to put whatever you want to measure into a box and then simply not typeset the box, but measure it:
\newdimen\height
\setbox0=\hbox{\Huge Hello, World!}
\height=\ht0 \advance\height by \dp0
The height is: \the\height
I think this will work:
\newlength{\somenamehere}
\settoheight{\somenamehere}{\hbox{...}}
Where ... is your content you like to measure. And you can then use \somenamehere as the height of that content.
Example:
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}
\begin{document}
\newlength{\heightofhw}
\settoheight{\heightofhw}{\hbox{Hello World!}}
Value = \the\heightofhw
\end{document}
Will output:
Value = 6.8872pt
Note:
Values of lengths are stored as points, and 1 inch ≈ 72.27 pt
This does not require any additional packages.
Update:
Use \hbox to correctly calculate the height of a different sized environment, but it won't work with newlines :-(

Resources