2

Question:

Actually i am working with an example in which figures dragged above the question text i cant understand, what is the problem. Any help..

MWE:

\documentclass[12pt, a4paper]{article}
\usepackage[
top=0.6in,bottom=0.5in,left=0.7in,right=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{subcaption}
\usepackage[parfill]{parskip}
%line spacing
\renewcommand{\baselinestretch}{1.0}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{intersections}
\makeatother
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{lastpage}
\lhead{}
\rhead{}
\chead{}
\rfoot{Page \thepage \hspace{1pt} of \pageref{LastPage}}
\lfoot{}
\cfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\headsep=10pt
\begin{document}
    \textbf{Example~1}

    This is the body text of my example 1...........
    \begin{figure}
        \centering
        \begin{subfigure}{6cm}
            \centering
            \begin{tikzpicture}
            \tkzDefPoint(-5,0){B}
            \tkzDefPoint(0,0){C}
            \tkzDefPoint(-1,5){A}
            \tkzDrawSegments(A,B B,C C,A)
            \tkzLabelPoints[left,xshift=00pt](B)
            \tkzLabelPoints[right,xshift=00pt](C)
            \tkzLabelPoints[above](A)

            \tkzDefShiftPoint[A](-3,-2){A1}
            \tkzDefShiftPoint[A](2,-2){A2}
            \tkzDrawVector[thick,<->](A1,A2)

            \tkzDefPoint(-2.5,3.1){D}
            \tkzLabelPoints[left,yshift=2mm](D)

            \tkzDefPoint(-0.65,3.1){E}
            \tkzLabelPoints[right,yshift=2mm](E)
            \end{tikzpicture}
            \caption*{(i)}
        \end{subfigure}
        \hspace{1cm}
        \begin{subfigure}{6cm}
            \centering
            \begin{tikzpicture}
            \tkzDefPoint(2,2){B}
            \tkzDefPoint(8,0){C}
            \tkzDefPoint(7,5){A}
            \tkzDrawSegments(A,B B,C C,A)
            \tkzLabelPoints[left,xshift=00pt](B)
            \tkzLabelPoints[right,xshift=00pt](C)
            \tkzLabelPoints[above](A)

            \tkzDefShiftPoint[A](-3,-0.8){A1}
            \tkzDefShiftPoint[A](2,-2.5){A2}
            \tkzDrawVector[thick,<->](A1,A2)

            \tkzDefPoint(5.1,3.85){D}
            \tkzLabelPoints[above,yshift=0mm](D)

            \tkzDefPoint(7.3,3.3){E}
            \tkzLabelPoints[right,yshift=0mm](E)

            \end{tikzpicture}
            \caption*{(ii)}
        \end{subfigure}
        \end{figure}
\end{document} 
2

Add a floating option to your figure environment

\documentclass[12pt, a4paper]{article}
\usepackage[
top=0.6in,bottom=0.5in,left=0.7in,right=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{subcaption}
\usepackage[parfill]{parskip}
%line spacing
\renewcommand{\baselinestretch}{1.0}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{intersections}
\makeatother
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{lastpage}
\lhead{}
\rhead{}
\chead{}
\rfoot{Page \thepage \hspace{1pt} of \pageref{LastPage}}
\lfoot{}
\cfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\headsep=10pt
\begin{document}
    \textbf{Example~1}

    This is the body text of my example 1...........
    \begin{figure}[h]
        \centering
        \begin{subfigure}{6cm}
            \centering
            \begin{tikzpicture}
            \tkzDefPoint(-5,0){B}
            \tkzDefPoint(0,0){C}
            \tkzDefPoint(-1,5){A}
            \tkzDrawSegments(A,B B,C C,A)
            \tkzLabelPoints[left,xshift=00pt](B)
            \tkzLabelPoints[right,xshift=00pt](C)
            \tkzLabelPoints[above](A)

            \tkzDefShiftPoint[A](-3,-2){A1}
            \tkzDefShiftPoint[A](2,-2){A2}
            \tkzDrawVector[thick,<->](A1,A2)

            \tkzDefPoint(-2.5,3.1){D}
            \tkzLabelPoints[left,yshift=2mm](D)

            \tkzDefPoint(-0.65,3.1){E}
            \tkzLabelPoints[right,yshift=2mm](E)
            \end{tikzpicture}
            \caption*{(i)}
        \end{subfigure}
        \hspace{1cm}
        \begin{subfigure}{6cm}
            \centering
            \begin{tikzpicture}
            \tkzDefPoint(2,2){B}
            \tkzDefPoint(8,0){C}
            \tkzDefPoint(7,5){A}
            \tkzDrawSegments(A,B B,C C,A)
            \tkzLabelPoints[left,xshift=00pt](B)
            \tkzLabelPoints[right,xshift=00pt](C)
            \tkzLabelPoints[above](A)

            \tkzDefShiftPoint[A](-3,-0.8){A1}
            \tkzDefShiftPoint[A](2,-2.5){A2}
            \tkzDrawVector[thick,<->](A1,A2)

            \tkzDefPoint(5.1,3.85){D}
            \tkzLabelPoints[above,yshift=0mm](D)

            \tkzDefPoint(7.3,3.3){E}
            \tkzLabelPoints[right,yshift=0mm](E)

            \end{tikzpicture}
            \caption*{(ii)}
        \end{subfigure}
        \end{figure}
\end{document} 

enter image description here

  • will it work for every similar problem? – Maths4Sandy Apr 26 at 5:17
  • @Sandy Yes. Read more in the linked question – JouleV Apr 26 at 5:18
  • @Sandy, it will not work in every cases. use only h option doesn't enable to flow figure to available space. better is to use htb, which enable, that float is moved to top of the next page (if at point of insertion is not enough space for it) or to bottom of the same page. otherwise it can happen that float be pushed to the end of document. – Zarko Apr 26 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.