Graphics, Figures & TablesFigure in subsection

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
LatexBeginnerrrr
Posts: 8
Joined: Sun Apr 28, 2019 2:15 am

Figure in subsection

Post by LatexBeginnerrrr »

Hello everyone

I'm new to the LaTeX world (read: I've been trying to use it for 3 hours) and I have come across two problems:

1. Everytime I try to post an image, the caption is like 10 centimeters below it. I have tried a lot of different codes, but nothing seems to work.

2. I'm currently trying to add an image and a table in a subsection, but they always end up above my section. I can't figure out why. This is what i've entered to add the table:
\section{Soorten modellen}
\subsection{Title}
Random text
\\
More random text
\\
\subsection{Title}
Text
\\
Text
\\
\begin{table}[]
\begin{tabular}{|l|l|l|}
\hline
\textbf{Word} & \textbf{Word} & \textbf{Word} \\ \hline
Word & Word & Word \\ \hline
Word & Word & Word \\ \hline
Word & Word & Word \\ \hline
Word & Word & Word \\ \hline
\end{tabular}
\end{table}

The table and image always end up before "Soorten modellen" and I really don't know why.

I hope some of you will be able to help this newbie out. :?

Thank you

Recommended reading 2024:

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

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

User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Figure in subsection

Post by Johannes_B »

Welcome to the forum.

Your use of \\ is wrong. Don't use it in normal text or between paragraphs.

A table (similar to a figure) can float. Meaning that LaTeX (the software) can put it to a suitable place. That place might be on top of a page (and in another section).
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
user22741
Posts: 35
Joined: Fri Nov 09, 2018 12:03 pm

Figure in subsection

Post by user22741 »

Your code is missing instructions where the table can be placed. I suggest to use `\begin{table}[htbp]`, this will allow the table to be placed [h]ere, or if there is not enough space to place it here, on [t]op of a page, at the ottom or on a separate [p]age if none of the other solutions worked.

Code: Select all

\documentclass{article}

\begin{document}
\section{Soorten modellen}
\subsection{Title}
Random text

More random text

\subsection{Title}
Text

Text

\begin{table}[htbp]
\begin{tabular}{|l|l|l|}
\hline
\textbf{Word} & \textbf{Word} & \textbf{Word} \\ \hline
Word & Word & Word \\ \hline
Word & Word & Word \\ \hline
Word & Word & Word \\ \hline
Word & Word & Word \\ \hline
\end{tabular}
\end{table}

\end{document}
LatexBeginnerrrr
Posts: 8
Joined: Sun Apr 28, 2019 2:15 am

Figure in subsection

Post by LatexBeginnerrrr »

Thank you very much! The problems are fixed!
LatexBeginnerrrr
Posts: 8
Joined: Sun Apr 28, 2019 2:15 am

Figure in subsection

Post by LatexBeginnerrrr »

Code: Select all

100\% heeft de afwijking niet.
\newline \newline
\begin{table}[tbph]
\centering
\begin{tabular}{l|l|l}
  & a  & a  \\ \hline
A & Aa & Aa \\ \hline
A & Aa & Aa
\end{tabular}
\end{table} 
\newline \newline \noindent
100\% heeft de afwijking niet.
\newline \newline
Er moet dus ten minste 1 ouder homozygoot zijn voor het dominante allel opdat de kans 0 zou zijn om een kind te krijgen met afwijking. Als beide ouders de afwijking hebben, is de kans 100\% dat het kind deze afwijking ook heeft.
This is the only table that seems to appear on the next page and I have no idea why.
What should I change?
user22741
Posts: 35
Joined: Fri Nov 09, 2018 12:03 pm

Figure in subsection

Post by user22741 »

Try `[htbp]` instead.
LatexBeginnerrrr
Posts: 8
Joined: Sun Apr 28, 2019 2:15 am

Figure in subsection

Post by LatexBeginnerrrr »

It still didn't work & still appeared on the next page, while the text below the table appeared on the right page.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Figure in subsection

Post by Johannes_B »

\newline inside normal text is wrong. What are you trying to achieve?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Figure in subsection

Post by Johannes_B »

By the way,l have you considered replacing the table environment with just center environment?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply