2

I am attempting to type after creating a figure. I have tried doing clearpage but it will just create a new page for the new section and move the figure back a page as well. I just want text, figures, then text. Any help would be appreciated, thanks!

\section{exponents}
sklfjsadlkfjskldfjsldkfjaslkfj;klsaj;sjf;lkasj
\begin{figure}
    \vspace{2cm}
    \centering
\begin{tikzpicture}
\begin{axis}[name=plot,
xmin=0, xmax=10,
ymin=0,ymax=1000,width=.5\textwidth,
legend pos=north west,]
\addplot [domain=0:10, color=blue, thick]   {5*x};
\addlegendentry{5x}
\addplot [domain=0:10, samples=100, color=red, thick]   {x^2};
 \addlegendentry{$x^2$}
\addplot [domain=0:10, samples=100, color=black, thick]   {2^x};
 \addlegendentry{$2^x$}
\end{axis}
\end{tikzpicture}
\caption{\label{fig:plot1}}

\vspace{3cm}

\begin{tabular}{ |c|c|c|c| } 

\hline
n & 5x & $x^2$ & $2^n$  \\ 
\hline
3 & 15 & 9 & 8  \\ 
5 & 25 & 25 & 32  \\ 
7 & 35 & 49 & 128  \\ 
9 & 45 & 81 & 512  \\ 
11 & 55 & 121 & 2048  \\ 
13 & 65 & 169 & 8192  \\ 
15 & 75 & 225 & 32768  \\ 



\hline
\end{tabular}
\caption{\label{fig:plot2}}

\end{figure} \section{polynomials}

  • 5
    How to influence the position of float environments like figure and table in LaTeX? might be useful here. Probably \begin{figure}[htbp] instead of \begin{figure} already results in the expected placement. Apart from that, you might want to consider removing all the \vspace commands and probably place plot and table side by side to save even more space. – leandriis May 09 '21 at 08:17
  • Your situation is not reproducible with the fragment of code what you show, but I suspect that some text before plus picture+table + 5cm of vertical space all in one unbreakable float is simply too much to allow also start a section after it (note that sections headers also have their own rules: they don't like to be in the last and penultimate rows.) – Fran May 09 '21 at 09:47

1 Answers1

2

As @leandriis has already pointed out in a comment, removing the \vspace directives, providing the [htb] placement specifier for the figure environment, and placing the tabular environment next to instead of below the tikzpicture environment are all worth doing. In addition, you may also want to assign a table-caption rather than a figure-caption to the tabular material.

enter image description here

\documentclass{article}
\usepackage{pgfplots,caption}
\begin{document}

\section{exponents} bla bla bla

\begin{figure}[htb!] \begin{minipage}{0.5\textwidth} \begin{tikzpicture} \begin{axis}[name=plot, xmin=0, xmax=10, ymin=0,ymax=1000,width=0.9\textwidth, legend pos=north west,] \addplot [domain=0:10, color=blue, thick] {5*x}; \addlegendentry{5x} \addplot [domain=0:10, samples=100, color=red, thick] {x^2}; \addlegendentry{$x^2$} \addplot [domain=0:10, samples=100, color=black, thick] {2^x}; \addlegendentry{$2^x$} \end{axis} \end{tikzpicture} \caption{aaaa \label{fig:plot1}} \end{minipage}% \begin{minipage}{0.5\textwidth} \centering \begin{tabular}{ |c|c|c|c| } \hline n & 5x & $x^2$ & $2^n$ \ \hline 3 & 15 & 9 & 8 \ 5 & 25 & 25 & 32 \ 7 & 35 & 49 & 128 \ 9 & 45 & 81 & 512 \ 11 & 55 & 121 & 2048 \ 13 & 65 & 169 & 8192 \ 15 & 75 & 225 & 32768 \ \hline \end{tabular} \captionof{table}{bbbb \label{fig:plot2}} \end{minipage} \end{figure}

\section{polynomials}

more bla bla bla

\end{document}

Mico
  • 506,678
  • Thank you for the code! I figured out that the problem was one of the formatting things I was using to try to get latex to do apa format, I think I am just going to write everything up and then figure out how to APA it later. – Zerender May 09 '21 at 18:02