1

I have read this article carefully: however, I still have problems with the placement of figures and tables inside a document. Here is an example

\documentclass{article}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{mathptmx}
\usepackage{makecell}
\setcellgapes{5pt}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage{lipsum}
\pgfplotsset{compat=1.16}
\newcommand\ProvideMathOperator[2]{\ifdefined#1\else\DeclareMathOperator{#1}{#2}\fi}
\ProvideMathOperator{\w}{w}
\ProvideMathOperator{\x}{x}
\begin{document}
\textcolor{red}{\lipsum[1][1]}
\begin{figure}[htbp!]
\centering
\begin{tikzpicture}
  \begin{axis}[
  grid, grid style=dashed,
  ymin=0,ymax=80,
  ytick={0,10,20,30,40,50,60,70},
  xtick={0,0.05,0.10,0.15,0.20,0.25,0.30}, 
  extra y ticks={0},            % <---
  xmax=0.35,xmin=0,
  extra x ticks={0},            % <---
  minor tick num=1,
  axis lines = middle,
  set layers,                   % <---
  axis on top,                  % <---
  xlabel=$\x_1$,ylabel=$\theta\lbrack\si{\celsius}\rbrack$,
  x label style={at={(1,0)},right},
  y label style={at={(0,1)},above},
  x tick label style={/pgf/number format/.cd,
                      fixed relative,
                     },
               ]
  \addplot+[color=red,mark=*,mark options={draw=red,fill=green},smooth]
    coordinates {
    (0.05,32.05)(0.10,30.00)(0.15,32.4)(0.20,35.65)(0.25,42.50)(0.31,63.45)
    };
  \end{axis}
\end{tikzpicture}
\end{figure}
\textcolor{yellow}{\lipsum[1][1]}
\begin{figure}[htbp!]    
\centering
    \begin{tikzpicture}
  \begin{axis}[
  grid, grid style=dashed,
  ymin=0,ymax=80,
  ytick={0,10,20,30,40,50,60,70},
  xtick={0,10,20,30,40,50,60,70}, 
  extra y ticks={0},            % <---
  xmax=80,xmin=0,
  extra x ticks={0},            % <---
  minor tick num=1,
  axis lines = middle,
  set layers,                   % <---
  axis on top,                  % <---
  xlabel=$\w_1$,ylabel=$\theta\lbrack\si{\celsius}\rbrack$,
  x label style={at={(1,0)},right},
  y label style={at={(0,1)},above},
  x tick label style={/pgf/number format/.cd,
                      fixed relative,
                     },
               ]
  \addplot+[color=blue,mark=*,mark options={draw=blue,fill=orange},smooth]
    coordinates {
    (25.97,32.05)(42.55,30.00)(53.99,32.4)(62.50,35.65)(68.96,42.50)(74.85,63.45)
    };
  \end{axis}
\end{tikzpicture}
\end{figure}
\textcolor{blue}{\lipsum[1][1]}
\end{document}

Red text should be above the first graph whole

Yellow text should be between the graphs whole

Blue text should be below the second graph whole

enter image description here

Can you help me?

Thank you in advance

3
  • please provide in your question mwe (minimal working example), a code for the complete small document beginning with \documentclass{...} and ending with \end{document}, which reproduce your problem. given link can be after while death and no one will be able to see what is your problem. for text use some dummy text (from lipsum or blindtext ...). explain your problem relation to tikz. your question is not clear.
    – Zarko
    Apr 11, 2019 at 11:28
  • @Zarko question edited Apr 11, 2019 at 12:00
  • 1
    Simply, leave space after each \end{figure}.
    – user31034
    Apr 11, 2019 at 12:08

1 Answer 1

1

In TeX a (not commented out) linebreak is equivalent to a space. An empty line denotes the end of a paragraph.

Because you have no empty lines in your code TeX puts it all in one paragraph.

If you insert empty lines in between TeX will split the text up into several paragraphs and place the figures between those paragraphs.

Also, a few empty lines in your preamble might improve readability.

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\usepackage{siunitx}

\usepackage{amsmath}
\newcommand\ProvideMathOperator[2]{\ifdefined#1\else\DeclareMathOperator{#1}{#2}\fi}
\ProvideMathOperator{\w}{w}
\ProvideMathOperator{\x}{x}

\usepackage{lipsum}

\begin{document}

\textcolor{red}{\lipsum[1][1]}

\begin{figure}[htbp]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            grid, grid style=dashed,
            ymin=0,ymax=80,
            ytick={0,10,20,30,40,50,60,70},
            xtick={0,0.05,0.10,0.15,0.20,0.25,0.30}, 
            extra y ticks={0},            % <---
            xmax=0.35,xmin=0,
            extra x ticks={0},            % <---
            minor tick num=1,
            axis lines = middle,
            set layers,                   % <---
            axis on top,                  % <---
            xlabel=$\x_1$,ylabel=$\theta\lbrack\si{\celsius}\rbrack$,
            x label style={at={(1,0)},right},
            y label style={at={(0,1)},above},
            x tick label style={/pgf/number format/fixed relative},
        ]
            \addplot+[color=red,mark=*,mark options={draw=red,fill=green},smooth] coordinates {
                (0.05,32.05)(0.10,30.00)(0.15,32.4)(0.20,35.65)(0.25,42.50)(0.31,63.45)
            };
        \end{axis}
    \end{tikzpicture}
\end{figure}

\textcolor{yellow}{\lipsum[1][1]}

\begin{figure}[htbp]    
    \centering
        \begin{tikzpicture}
        \begin{axis}[
            grid, grid style=dashed,
            ymin=0, ymax=80,
            ytick={0,10,20,30,40,50,60,70},
            xtick={0,10,20,30,40,50,60,70}, 
            extra y ticks={0},            % <---
            xmax=80,xmin=0,
            extra x ticks={0},            % <---
            minor tick num=1,
            axis lines = middle,
            set layers,                   % <---
            axis on top,                  % <---
            xlabel=$\w_1$,ylabel=$\theta\lbrack\si{\celsius}\rbrack$,
            x label style={at={(1,0)},right},
            y label style={at={(0,1)},above},
            x tick label style={/pgf/number format/fixed relative},
        ]
            \addplot+[color=blue,mark=*,mark options={draw=blue,fill=orange},smooth] coordinates {
                (25.97,32.05)(42.55,30.00)(53.99,32.4)(62.50,35.65)(68.96,42.50)(74.85,63.45)
            };
        \end{axis}
    \end{tikzpicture}
\end{figure}

\textcolor{blue}{\lipsum[1][1]}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .