Graphics, Figures & TablesInsert Figure Between Text

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
mdk31
Posts: 20
Joined: Wed Mar 11, 2009 4:38 am

Insert Figure Between Text

Post by mdk31 »

I'm trying to embed a figure (a table in this case) in between text and I'm having quite a problem with this. What ends up happening is that part of the text will run together above the picture while some will then go below it, not at the break where I actually put the image. I have these commands in the preamble

\documentclass{article}
\usepackage{epsfig}
\renewcommand{\topfraction}{0.9}
\renewcommand{\bottomfraction}{0.8}
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{2}
\renewcommand{\textfraction}{0.07}
\renewcommand{\floatpagefraction}{0.7}

Then, I have

Text, text, and more text
\centering
\begin{tabular}{ | l | l | l | p{5cm} |}
\hline
Day & Min Temp & Max Temp & Summary \\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
across most of Scotland and Northern Ireland,
but rain reaching the far northwest. \\ \hline
Wednesday & 10C & 21C & Rain will still linger for the morning.
Conditions will improve by early afternoon and continue
throughout the evening. \\
\hline
\end{tabular}
\caption{Weather Table}
\end{figure
Text, text, and still more text

I just took the table from some website so I could test all this out.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Insert Figure Between Text

Post by localghost »

You should have posted a minimal working example (MWE) to clarify the problem. Keep that in mind for the next time. I'm not sure if I understand you right, but if you want a paragraph not be interrupted by a figure, separate this figure by blank lines from the text.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs}
\usepackage{textcomp}
\usepackage{lmodern}
\usepackage{blindtext}

%%% Do you know what this lines do? %%%
\renewcommand{\topfraction}{0.9}
\renewcommand{\bottomfraction}{0.8}
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{2}
\renewcommand{\textfraction}{0.07}
\renewcommand{\floatpagefraction}{0.7}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
  \blindtext

  \begin{table}[!ht]
    \centering
    \caption{Weather Table}\label{tab:weather}
    \begin{tabular}{lllp{5cm}}\toprule
      Day & Min Temp & Max Temp & Summary \\ \midrule[0.8pt]
      Monday & 11\textcelsius & 22\textcelsius & A clear day with lots of sunshine. \\
      \multicolumn{4}{l}{However, the strong breeze will bring down the temperatures.} \\ \midrule
      Tuesday & 9\textcelsius & 19\textcelsius & Cloudy with rain, across many northern regions. Clear spells across most of Scotland and Northern Ireland, but rain reaching the far northwest. \\ \midrule
      Wednesday & 10\textcelsius & 21\textcelsius & Rain will still linger for the morning. Conditions will improve by early afternoon and continue throughout the evening. \\ \bottomrule
    \end{tabular}
  \end{table}

  \blindtext
\end{document}
Use only code from which you really know what it does (see remarks in the code).


Best regards and welcome to the board
Thorsten¹
mdk31
Posts: 20
Joined: Wed Mar 11, 2009 4:38 am

Re: Insert Figure Between Text

Post by mdk31 »

I'm sorry about my first post; reading it again I can see now that it was not clear.

What I'm trying to do is to make my text flow with my figures. I want to have text, followed by a figure, then more text. The problem is that the text is not breaking for the figure in the correct spot; my figure is not going where I tell it to go.

My first problem was trying to keep LaTeX from putting my tables at the end of the paper. Now I can't get the figure to go in the right spot in between the text. I want say something like "as shown in Figure 2 below," then have the figure, and then continue with the rest of my text.

I'm new to LaTeX and I'm not sure entirely what those commands do. I got them from this website here.

http://mintaka.sdsu.edu/GF/bibliog/latex/floats.html
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Insert Figure Between Text

Post by localghost »

For the present I suggest to omit the lines I marked in the code and use some optional parameters for the float environments as I demonstrated in the code above. Refer to some introductions to LaTeX [1]. In this topic you will find some useful guides and manuals.

[1] View topic: LaTeX Resources for Beginners
Olf
Posts: 2
Joined: Wed Mar 11, 2009 6:28 pm

Re: Insert Figure Between Text

Post by Olf »

You can force latex to put the figure at a precise position with the placement specifier "H" (you need to include the "float" package)

\usepackage{float}

\begin{figure}{H}
...
\end{figure}

More detailes on:
http://en.wikibooks.org/wiki/LaTeX/Floa ... d_Captions

Regards,
Olf
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Insert Figure Between Text

Post by localghost »

Using the float package with this parameter should be the very last alternative. If a picture should strictly appear where it is declared in the source, it is recommendable to use the \captionof command instead of the usual \caption provided by the caption (or the capt-of) package.
Christos
Posts: 25
Joined: Sun Nov 30, 2008 10:06 pm

Insert Figure Between Text

Post by Christos »

What I generally find very useful for placing floats right where we want them to be is an old package (1991) by David Carlisle. The package is called here.sty and it avoids tempering with
the default floating commands of LaTeX. You can find it http://www.ipipan.waw.pl/MGV/here.sty.

Best,
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Insert Figure Between Text

Post by localghost »

Of course an entry for the here package also can be found on CTAN. But as the caption already says it is considered obsolete. Modern versions of placing a figure absolutely have already been mentioned in this topic.
Christos
Posts: 25
Joined: Sun Nov 30, 2008 10:06 pm

Re: Insert Figure Between Text

Post by Christos »

Oops...didn't know. Thanks.
Post Reply