How to place a wide figure with subfigures in Latex? - latex

I am trying to write a report and stuck with a wide figure. My document type is PRL using revtex4.1 with two columns. I have a wide figure which consists of 8 subfigures. I am trying to place it bottom of a page but it insists to go next page. Here is code for my wide figure:
\begin{figure*}
\centering
\subfloat[s1]{\label{fig:s1}\includegraphics[width=0.20\textwidth]{s1.png}}\qquad
\subfloat[s2]{\label{fig:s2}\includegraphics[width=0.20\textwidth]{s2.png}}\qquad
\subfloat[s3]{\label{fig:s3}\includegraphics[width=0.20\textwidth]{s3.png}}\qquad
\subfloat[s4]{\label{fig:s4}\includegraphics[width=0.20\textwidth]{s4.png}}\\
\subfloat[s5]{\label{fig:s5}\includegraphics[width=0.20\textwidth]{s5.png}}\qquad
\subfloat[s6]{\label{fig:s6}\includegraphics[width=0.20\textwidth]{s6.png}}\qquad
\subfloat[s7]{\label{fig:s7}\includegraphics[width=0.20\textwidth]{s7.png}}\qquad
\subfloat[s8]{\label{fig:s8}\includegraphics[width=0.20\textwidth]{s8.png}}
\caption{\label{fig:s}Caption}
\end{figure*}

Try also
\begin{figure*}[!hb]
If your figure is too wide, this might help: Centering wide tables or figures.

I don't know whether it will work, but have you tried using placements, ie:
\begin{figure*}[b]
where b stands for bottom?
You could also try using the float package (put this in the preamble, before \begin{document}:
\usepackage{float}
and then using
\begin{figure*}[H]
to specify exactly where you want your figure to be, i.e. put the figure exactly in the position in relation to your text where you want the figure to be placed.
It may be that your figure is just too big and it won't fit there, so you may have to reduce the size of the figures or fiddle with the margins (not recommended, but possible).
Lastly, in 6 days the LaTeX question and answer website will be open to everyone, and you might find it useful.

Related

Adding caption in LaTex without floats (tables)?

I have a few tables which are not long enough to warrant the use of \longtable, but they always start on the next page which breaks the whole flow and trying to force it with a [!h] in the table did not help. So I stopped using \tables and just have \tabular tag now which seems to have fixed the layout as there are no floats.
But the problem now is I can't get automatic captions for the Tables - any ideas how I can do this and also get auto numbering so when I use \addcontentsline it can show up in the TOC?
To use a caption outside a float environment, one needs to use \captionof which is part of package caption.
Example
\documentclass{article}
\usepackage{caption}
\begin{document}
\begin{center}
\begin{tabular}{rl}
right & left \\
right & left \\
\end{tabular}
\captionof{table}{Your caption here}
\end{center}
\end{document}
There is also a capt-of package if you are just interested in using the command \captionof.
Short answer; you need a \table for the caption. Only using \tabular + captioning is not gonna work.
bit longer
There may be a nasty work-around as people tend to create work-arounds for everything, but my base rule for most of those work-arounds is: "if latex does not provide it by itself, do not try to do it". Most of time those "fixes" will give even more text-flow problems anyway.
Now if you really want it right below the text just do a \clearpage before the table and place the table. Than the rest of the text. This will probably solve it, although it will give an empty space on the rest of your 'previous' page of course.

dealing with large figures in Latex

I have a large figure that appears at the end of my document rather than in the section that I want to be in. Even \begin{figure}[h] doesn't help. Without scaling it down, how can I put it at the end of the section I want it in?
Using the afterpage package can be a good solution. However, using the option here you are trying to tell LaTeX where you want to put the image. Instead, you need to tell LaTeX where the image is good to be put:
use \begin{figure}[tb] for figures that fit well in a page with text (say, half of the text height for the figure and the other half for the text)
use \begin{figure}[p] for floats large enough to require a dedicated page.
Setting a proper option increase your chances to have the image almost where you want, having at the same time a good page layout.
If the figure is still too far from the page where it should be placed, you can set some "barriers" for floats positioning with the packages placeins or afterpage (already mentioned).
Here is a small tutorial for float placement. The thing you want to do is put an \afterpage{\clearpage} command at the end of the section. This will create an additional page after the current one and place the floats that are left in the queque there. If the float still doesn't get placed, you have to resize it. If you really don't want to resize it and it should fit on the page, then you could try changing the margins and text area temporarily (i.e. just for that one page) and see if that lets the float get placed.
i forget if it's the float or array package that provides this, but,
\begin{figure}[H]
...
\end{figure}
The upper case H will put the figure exactly where it is in your code.

Inserting images in LaTeX

I have a question on inserting images into a LaTeX document. I try to insert images using the keyboard short cut: Ctrl-Alt-G and I'm able to insert images. But the compiled pdf document shows all the images at the end, whereas I want to interleave images with text. Something like the following:
Text1
Image1
Text2
Image2
Text3
Image3
I try to insert images at right positions i.e. in between text, but on compilation, they all appear at the end. I have tried different options provided on the image insertion UI but same result.
Any idea where I'm going wrong.
Related SO question.
You'll have to use graphicx package:
\usepackage{graphicx}
and then you just use \includegraphics
\includegraphics{myfig.pdf}
\includegraphics[width=60mm]{myfig.png}
\includegraphics[height=60mm]{myfig.jpg}
\includegraphics[scale=0.75]{myfig.pdf}
\includegraphics[angle=45,width=52mm]{myfig.jpg}
Try downsizing the images. Maybe they are too large and so they are moved to the end of the document..
Hope it helps.
What code did you use for the \figure environment? In most cases the "h" option should at least help a little bit there.
This is a FAQ: "Moving tables and figures in LaTeX". Note especially the third dot point, which relaxes some of the restrictions LaTeX uses to position floats.
That's the best answer I can give without seeing an example of how large your floats are and how you're inserting them into the document. Provided that they're reasonably-sized, you should have no problem with
\begin{figure}[htbp]
\includegraphics{myfig}
\caption{...}
\label{fig:myfig}
\end{figure}
And note that if the float is too large to fit then it will move to a subsequent page -- this is the whole idea behind getting LaTeX to help you with the formatting. You certainly don't want to end a page prematurely just because there's a figure coming up next that otherwise doesn't fit.
Maybe this can help you in general...I just hate the LaTeX way of making everything too advanced (flexible) at all times.
Beside, the source looks really awful.
It will not solve you initial problem, but since it will be easier to change size of each image you can at least try...
% Easy image insert
% use as \img{imagename}{caption}{label}
% will insert image with with 70% of textwidth
% change below for other width
\newcommand{\img}[3]{
\begin{figure}[!ht]
\centering
\includegraphics[width=0.7\textwidth]{#1}
\caption{#2}
\label{fig:#3}
\end{figure}
}
\img{myimage}{has this caption}{and_this_label}
the label is automatically prefixed with fig:.
Good luck!
/C
Using [!t] and [!h] in the figure environment, rather than [t], [h] etc seems to help, though I've yet to find a surefire way to get large images in sensible places. Sometimes it works half way through a document, othertimes it doesn't.
Sometimes just changing the width or height using an option to the includegraphics statement (square brackets before the filename a.k.a \includegraphics[width=foo]{}) will do the trick.
\begin{figure}[H!]
\includegraphics{myfig}
\caption{...}
\label{fig:myfig}
\end{figure}
Use H! to denote that you want your picture right there.
\documentclass{article}
\usepackage{graphicx}
\begin{document}
text
\begin{figure}[tbh]
\centering
\includegraphics[width=0.4 \textheight]{ & directory path of jpg. width defines the width of the page and one one can put in its place height which is text page height }
\caption{name of the jpg}
\end{figure}
% it worked for me.
\end{document}

Is there a way to get LaTeX to place figures in the same page as a reference to that figure?

I am using LaTeX and the figure environment.
I am well familiar with the parameters to that environment: [htbp], and I am also generally familiar with the strategies that LaTeX takes, by default, to decide where to put each figure. For example, by placing figures at the top or bottom of the page.
What I am wondering is whether there is a package, macro, or some commands that I can give so that if I have a single-column document and I mostly have a single in-text reference to a figure, that the figure would be more likely to be placed in the same page of the reference?
For example, imagine that I have a long paragraph which in the middle has a \ref{FIG:X}. When rendered, some of the paragraph appears before the page break, and some appears after the page break. I can also place the figure command somewhere before and after the whole paragraph. Is there a way to get it to actually be placed in the same page as the actual reference?
I don't want to sound too negative, but there are occasions when what you want is almost impossible without a lot of "artificial" tuning of page breaks.
If the callout falls naturally near the bottom of a page, and the figure falls on the following page, moving the figure back one page will probably displace the callout forward.
I would recommend (as far as possible, and depending on the exact size of the figures):
Place the figures with [t] (or [h] if you must)
Place the figures as near as possible to the "right" place (differs for [t] and [h])
Include the figures from separate files with \input, which will make them much easier to move around when you're doing the final tuning
In my experience, this is a big eater-up of non-available time (:-)
In reply to Jon's comment, I think this is an inherently difficult problem, because the LaTeX guys are no slouches. You may like to read Frank Mittelbach's paper.
Yes, include float package into the top of your document and H (capital H) as a figure specifier:
\usepackage{float}
\begin{figure}[H]
.
.
.
\end{figure}
You can always add the "!" into your float-options. This way, latex tries really hard to place the figure where you want it (I mostly use [h!tb]), stretching the normal rules of type-setting.
I have found another solution:
Use the float-package. This way you can place the figures where you want them to be.
I solve this problem by always using the [h] option on floats (such as figures) so that they (mostly) go where I place them. Then when I look at the final draft, I adjust the location of the float by moving it in the LaTeX source. Usually that means moving it around the paragraph where it is referenced. Sometimes I need to add a page break at an appropriate spot.
I've found that the default placement of floats is reasonable in LaTeX, but manual adjustments are almost always needed to get things like this just right. (And sometimes it isn't possible for everything to be perfect when there are lots of floats and footnotes.)
The manual for the memoir class has some good information about how LaTeX places floats and some advice for manipulating the algorithm.
If you want force this behaviour on all of your figures try
...
\usepackage{float}
\floatplacement{figure}{H}
...
Maybe this will help you?
\begin{center}
\includegraphics[scale=0.5]{picture_name}
\end{center}
I think is better to use the graphics command when your figures run away.
I have some useful comments. Because I had similar problem with location of figures.
I used package "wrapfig" that allows to make figures wrapped by text.
Something like
...
\usepackage{wrapfig}
\usepackage{graphicx}
...
\begin{wrapfigure}{r}{53pt}
\includegraphics[width=53pt]{cone.pdf}
\end{wrapfigure}
In options {r} means to put figure from right side. {l} can be use for left side.
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{4}
\renewcommand{\topfraction}{0.85}
\renewcommand{\bottomfraction}{0.85}
\renewcommand{\textfraction}{0.15}
\renewcommand{\floatpagefraction}{0.7}
http://robjhyndman.com/researchtips/latex-floats/
One way I found that helps with this is to use \include{file_with_tex_figure_commands}
(not input)

How do I prevent LaTeX from padding spaces between paragraphs so that next section begins at top of next page?

I have a two-column paper where space restrictions are very tight.
I just looked at my last version of the manuscript and saw that the upper half contains a figure (as expected), but in the lower half there is a lot of vertical space between paragraphs (enough to squeeze 10 more lines), and that LaTeX probably added it so that in the beginning of the next page a new numbered section will begin at the top of the page.
I know there's a way to adjust this so LaTeX doesn't try so hard, but I'm not sure how. any help? Thanks!
The parameter that controls inter-paragraph spacing is called \parskip(See Paragraph Spacing ). You set it (with "rubber" values) using something like:
\setlength{\parskip}{1cm plus4mm minus3mm}
The defualt value of \parskip is class dependent. The "plus" and "minus" parts tell TeX how much it can adjust the value to improve the layout (that is they make the spacing elastic, thus the "rubber" designation). Reducing (or eliminating) the "plus" part of the rubber might help.
Watch out though, you can cause other layout artifacts if you constrain TeX too much.
Other things to think about:
The widow and club penalties probably apply section headings, and may be affecting TeX's layout choices (see https://stackoverflow.com/questions/512967/how-can-one-keep-a-section-from-being-at-the-end-of-a-page-in-latex for a discussion).
You may also want to consider messing with \baselineskip which controls the allowed spacing between lines of text and can also have rubber values.
This is a common problem, and there are probably some fairly sophisticated treatments already prepared on CTAN.
\vfill before the new section worked perfectly for me.

Resources