How to align a picture correctly in Overleaf - latex

I want to insert an image on my text but the image always aligns on top of the text and not below as I wanted to. Does anyone know how to accomplish this?
This is the image I want to display on the bottom
\subsection{DistribuciĆ³n Normal}
all that text in spanish
\begin{figure}
\centering
\centerline{\includegraphics[width=8cm,height=8cm]{fdd.eps}}
\end{figure}

If you want to specify where the figure has to be, you have to use some options of the figure environment: for example
all that text in spanish
\begin{figure}[h]
\centering
\includegraphics[width=8cm,height=8cm]{fdd.eps}
\end{figure}
means that LaTeX will try to put the figure where you inserted the figure environment ([h]ere). Other options include
t: top
b: bottom
p: on a special page only for floating environments
You can use several options, for example
all that text in spanish
\begin{figure}[htb]
\centering
\includegraphics[width=8cm,height=8cm]{fdd.eps}
\end{figure}
LaTeX will try to put the figure following the order of the options provided: first it will try to put it [h]ere, then on the [t]op and finally, if the other two possibilities are not available, it will put the figure on the [b]ottom of the page. This strategy lets LaTeX decide the best position for the figure.
For references, see this Overleaf document.

Related

Overleaf: Picture Formatting

I want to fit my image in the Overleaf but the output result is not as expected.
The overleaf code i used is as:
\begin{figure}[htb]
\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{Fig2.png}
\label{Fig1}
\end{figure}
\begin{figure}[htb]
\includegraphics[scale=0.5]{Fig_3.png}
\label{Fig2}
\end{figure}
However my image is coming on top of the text of the other sections, any solutions are appreciated.
Note: The Image needs the whole page width to be accommodated
Try \pagebreak before and/or after images.
The next option is to replace [htb] with [!h].

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

How do I change the caption for a figure in Latex?

I would like to change the caption from being:
Figure 1: ...
to
From left to right: ...
If I try and renewcommand the figurename, they still get numbered. This is unecessary as there is only a single image in the document.
Any suggestions?
You could also use the caption package to remove the "Figure 1:" from the \caption{} command.
\usepackage{caption}
...
\begin{figure}
\caption*{A figure}
. . .
\end{figure}
If you want to use \caption{...} to specify the caption, you can use this hack in your document:
\makeatletter
\def\#makecaption#1#2{%
\vskip\abovecaptionskip
\hb#xt#\hsize{\hfil#2\hfil}%
\vskip\belowcaptionskip}
\makeatother
With this instruction, your figures will display only what you have specified as \caption{...} and won't add any "Figure 1: " etc.
Instead of using \caption you may consider putting your own content beneath the figure's content:
\includegraphics{...}
\small
From left to right: ...
Geoff's answer is basically correct. Within a figure or table environment, you can drop the caption if you don't want numbering, and just write plain text. From the book A Guide to LaTeX, 3rd edition (p.184):
The \caption command may be omitted if numbering is unwanted, since any text included in the float environment will accompany the contents. The advantages of \caption over simple text are the automatic numbering and entries in the lists of figures and tables.

latex template or example for personal statement

I am writing a personal statement in latex. I don't want the big margin at the top of the page not big title taking a lot of space. I just like to make the layout compact but still clearly spaced with title, name and other necessary information, since there may be restriction on the number of pages. One example would be http://www.hsc.unt.edu/education/CIM/Documents/PS-Sample2_000.pdf. I wonder where to find some good latex templates or examples?
Thanks and regards!
I would use the geometry package to establish the desired margins. To get the margins in your sample document, try:
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}
Your next requirement was to fix the title block. LaTeX uses the internal command \#maketitle to format the title block. You can redefine this as you like. To achieve the same title block style as in the sample document, use:
\usepackage[svgnames]{xcolor}% provides colors for text
\makeatletter% since there's an at-sign (#) in the command name
\renewcommand{\#maketitle}{%
\begin{center}
\parskip\baselineskip% skip a line between paragraphs in the title block
\parindent=0pt% don't indent paragraphs in the title block
\textcolor{red}{\bf\#title}\par
\textbf{\#author}\par
%\#date% remove the percent sign at the beginning of this line if you want the date printed
\end{center}
}
\makeatother% resets the meaning of the at-sign (#)
The \#title, \#author, and \#date commands will print the title, author, and date. You can use whatever formatting commands you like to set the text in bold, different colors, etc.
Put all of the above commands in the preamble of the document. The preamble is the space between \documentclass and \begin{document}.
\documentclass{article}
% this is the preamble
% put all of the above code in here
\title{Personal Statement}
\author{Tim}
\begin{document}
\maketitle% prints the title block
Emergency medicine has always been a passion of mine\ldots
\end{document}
Attempt #1: I've used the following style file, which I call cramp2e, for similar purposes. It is probably not right for you, but have a look:
\oddsidemargin -1cm
\evensidemargin -2cm
\topmargin 1cm
\textheight 24cm
\textwidth 19cm
\headheight 0cm
\headsep .7cm
\footskip .7cm
\parskip .2cm
\paperheight 25cm
\setlength\voffset{-.33in}
\setlength\hoffset{-.25in}
Any good?
Postscript This is for A4 size paper.
A slightly less LaTeX-ey solution would be to not use the \maketitle command. A couple of times I've simply used this as my title(marginsize helps too).
Set up smaller margins:
\documentclass{article}
\usepackage{anysize}
\marginsize{1cm}{1cm}{1cm}{1cm}
(EDIT: 1cm might be even better..)
Minimal title:
\begin{document}
\begin{center}
\section*{My Document Title}
\today
\end{center}
% content goes here
\end{document}
The result looks something like:

How do I correctly insert an image/figure and have the text "flow around" the image/figure in latex?

I've been struggling with this. I wanted to insert an image and have it 'near' the text that discusses it, but have the text on that page wrap/flow around the image.
The image I've converted into eps format. I initially tried to use the figure environment (\begin{figure}...), but that merely placed the image at the top or bottom of the page without any text beside it, leaving a large portion of the page empty.
I did some digging on the web and identified the 'wrapfig' package, it seemed a likely solution, but I get a series of errors, and the image appears at the end of the document.
The errors:
Package wrapfig Warning: wrapfigure used inside a conflicting environment on input line 297.
Package wrapfig Warning: Stationary wrapfigure forced to float on input line 303.
Package wrapfig Warning: Stationary wrapfigure forced to float on input line 306.
Which continues for several lines.
What's odd is that one occasion, after compiling, the image appeared exactly where I wanted it, and then on the next it didn't.
[Added a minute or so later]
The latex code I have currently:
\begin{wrapfigure}{r}{0.2\textwidth}[h]
\begin{center}
\includegraphics[width=0.18\textwidth]{vec-perp.eps}
\end{center}
\caption{A}
\end{wrapfigure}
wrapfigure does not need the [h] specifier.
you need to include the wrapfigure package in your preamble:
\usepackage{wrapfig}
then, put the wrapfigure call above the text you want to wrap into, like this:
\begin{wrapfigure}{r or l}{width/height} \centering \includegraphics[width/height]{graphic.filename} \caption{foo} \end{wrapfigure}
a real world example:
\begin{wrapfigure}{r}{1.5in}
\centering
\includegraphics[width=1.5in]{smile.jpg}
\end{wrapfigure}
I just went through my document, commenting it out in sections, hoping to find the environment it was complaining about...in the process, I unintentionally introduced a blank line that I didn't have before. Apparently, the environment it was complaining about was the environment before the figure. I didn't have a blank line between the previous part, which was an itemize environment.
So...this, for example, is 'broken':
Ingredients for the Banana-Grape Bread Recipe
\begin{itemize}
\item Bananas
\item Grapes
\item Eggs
\end{itemize}
\begin{wrapfigure}{r}{0.2\textwidth}
\centering
\includegraphics[width=0.18\textwidth]{banana-grape.eps}
\caption{BananaGrape Bread}
\end{wrapfigure}
And inserting a empty line:
\end{itemize}
\begin{wrapfigure}{r}{0.2\textwidth}
Clears up my problems. Along the way I learned all sorts of things, yay! On the other hand, I'm pretty sure I don't have a clear understanding of environments yet. Time to spend some time reading, I reckon.

Resources