1

I have a document in overleaf with some text before a figure, however when it is compiled, the figure appears above the text, including the header. Why is this happening and how can I fix it? I have the following packages active:

\usepackage{helvet} 
\renewcommand{\familydefault}{\sfdefault}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc} 
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[citestyle=authoryear, style=apa]{biblatex}
\addbibresource{References.bib}
\usepackage[margin=2cm]{geometry}
\usepackage{caption, stackengine}
\usepackage{wrapfig}
\usepackage{subfigure}
\usepackage[table,xcdraw]{xcolor} 
\usepackage{subfiles}
\usepackage{gensymb}
\usepackage{siunitx}
\sisetup{group-minimum-digits = 4, detect-display-math = true, detect-weight, detect-mode = true, math-rm, group-separator = {,} }
\usepackage[version=4]{mhchem}
\usepackage{hyperref}
\usepackage{chngcntr} % IMPORTANT FOR THE NUMBERING OF SECTIONS AND EQUATIONS 
\usepackage{tikz} % SKETCHING PACKAGE
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{etoolbox} 
\usepackage{adjustbox}
\usepackage[parfill]{parskip}
\usepackage[none]{hyphenat}
\sloppy
\usepackage{lipsum}
\usepackage{svg} 
\usepackage[super]{nth}
\usepackage{booktabs} 
\usepackage{multirow} 
\usepackage{xcolor}
\usepackage{lscape} 
\usepackage{nomencl} 

\fancypagestyle{style1}{
\fancyhead{}
\fancyfoot{} 
\fancyfoot[R]{Page \thepage \hspace{1pt} of \pageref{LastPage}}}

relevant document:

\documentclass[../main.tex]{subfiles}

\begin{document}
\section*{Introduction}
Xylenes are a class of highly useful chemical raw materials. Their chemical formulae are shown in Figure \ref{fig:xylene_strucutres}.

\begin{figure}
    \centering
    \includesvg[scale=0.43]{Introduction/Xylene_structures}
    \caption{Chemical formulae of p-xylene, o-xylene, and m-xylene}
    \label{fig:xylene_strucutres}
\end{figure}

P-xylene enjoys the largest market among the three isomers.




\end{document}
David Carlisle
  • 757,742
weasel
  • 257
  • 1
    Welcome to tex.sx. Unfortunately, the code you show isn't sufficient to answer your question. The reason that a figure appears somewhere else than where it is input depends on how it is input. We need to know what document class is used, whether you are using the figure environment (by definition a "float"), and whether you have specified any options. (Most of the packages you show are probably irrelevant.) Reformulate your example, starting with \documentclass and ending with \end{document}, so that it produces the problem you describe, so that helpers can compile it. – barbara beeton Mar 09 '20 at 01:28
  • I have added the relevant part please – weasel Mar 09 '20 at 02:29
  • 1
    You haven't specified any positioning options for your figure. The default assumption is that a float will appear at the top of a page, so that's what has most likely happened here. Add the option \begin{figure}[ht} and if there is room "here", that's where it will be placed; if there's not room, it will move to the top of the next page. There's lots of useful information about figure positioning in this question: How to influence the position of float environments like figure and table in LaTeX? – barbara beeton Mar 09 '20 at 02:34
  • 1
    note that the only reason to use figure is to take its content out of the main document flow and mark it as a float that may be re-inserted elsewhere to help with page breaking. So what you describe is the expected behaviour – David Carlisle Mar 09 '20 at 07:54

1 Answers1

0

You haven't specified any positioning options for your figure. The default assumption is that a float will appear at the top of a page, so that's what has most likely happened here.

Add the option \begin{figure}[ht} and if there is room "here", that's where it will be placed; if there's not room, it will move to the top of the next page.

There's lots of useful information about figure positioning in this question: How to influence the position of float environments like figure and table in LaTeX?

As commented by David Carlisle, "the only reason to use figure is to take its content out of the main document flow and mark it as a float that may be re-inserted elsewhere to help with page breaking. So what you describe is the expected behaviour."