How to position nested Tbox in top right? - latex

How to position the smaller nested box, so it appeared in the top right corner (see image below)?
Here is my current, wrong implementation:
\newcommand\TBox[3][]{%
\tikz\node[draw,ultra thick,text width=#2,align=left,#1] {#3};}
\TBox{14cm}{%
\TBox{10cm}{xxx \vspace{9cm}} \TBox{3cm} \\
}

It would be better to place all your boxes in a single tikzpicture, because right now you are nesting them which is in general not a good idea.
To come back to your original question, you can use baseline=(current bounding box.north) to top align the boxes:
\documentclass{article}
\usepackage{tikz}
\newcommand\TBox[3][]{%
\tikz\node[draw,ultra thick,text width=#2,align=left,#1,baseline=(current bounding box.north)] {#3};}
\begin{document}
\TBox{14cm}{%
\TBox{10cm}{xxx \vspace{9cm}} \TBox{3cm} \\
}
\end{document}

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}

Add logo in very bottom right corner

I have been trying to insert a (transparent) logo in the bottom right corner in the background of my title page without affecting the text in Overleaf. Unfortunately, I haven't found a similar use case and have tried many different options for quite some time, but it doesn't work the way I need it to. Can someone please help me in this regard?
I would like it to look like this. As you can see, there is a logo inserted in the lower right corner.
You can add an image to the page background via the shipout/background hook. To make positioning easier, I'm using tikz in the following example:
\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\AddToHookNext{shipout/background}{
\begin{tikzpicture}[remember picture, overlay,inner sep=0pt,outer sep=0pt,opacity=0.5]
\node[anchor=south east] at ([xshift=3cm,yshift=-3cm]current page.south east) {
\includegraphics[width=16cm]{example-image-duck}
};
\end{tikzpicture}
}
\begin{document}
\lipsum
\end{document}

Improving outputs in tikz package

$F_1(g)=\left\{
\begin{tikzpicture}
\node[shape=circle,draw=black] (A) {$b^1_0$};
\end{tikzpicture} \right\}$
Doing this code, I have an output like this Output
And I'd like something more centered into the brackets, like if I'm still writing instead of drawing.
You have to change the baseline of the picture to be at its center, then align that baseline to the vertical center of the text. This can be done with the option [baseline={([yshift=-.8ex]current bounding box.center)}]. I added it to the example code you gave, and also changed the inner sep of the circle to 0pt. Let me know if that works for you.
$F_1(g)=\left\{
\begin{tikzpicture}[baseline={([yshift=-.8ex]current bounding box.center)}]
\node[shape=circle,draw=black, inner sep=0pt] (A) {$b^1_0$};
\end{tikzpicture} \right\}$
\end{document}

Add an image in background and a text zone

Well I'm a newbie in latex and I want to make a latex Curriculum Vitae.
I want to create a page with two parts
First part: an image from TOP to Bottom, and from left to the middle of the page
Second part: a text zone from from TOP to Bottom, and from middle of the page to the right
I have tried to create two columns but every time one of the columnes are put on the next pages :(
Do you have any advice or tips or answer to give me?
Thank you very much for your help.
For a single-page split-view display, you can set the content in a tabularx structure. The left-hand side contains an image with no height/depth. This allows you put anything in the right-hand side.
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx,tabularx}
\usepackage{lipsum}
\setlength{\parindent}{0pt}
\pagestyle{empty}
\begin{document}
\begin{tabularx}{\textwidth}{#{} X X #{}}
\raisebox{\dimexpr-\height+.7\normalbaselineskip}[0pt][0pt]{%
\includegraphics[width=\linewidth,height=\textheight]{example-image}} &
\lipsum[1-3]
\end{tabularx}
\end{document}
There are multiple ways of doing this. It all depends on whether you're stuck with a single page, or want to move to a bigger canvas.

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

Resources