0

I have problems with tables in latex. I want to have text before a table and I cannot do that. I don't know why the text wrote by me is written after the table. Any help?

enter image description here

Here is the code for making table which I used in my project:

\begin{table}
\small
\begin{tabular}{p{3.5cm}p{3.5cm}p{3.5cm}p{3.5cm}}
\hline
I(mA) &1mA &5mA &7mA\\
\hline
R(k$\ohm$)  &0.415k$\ohm$ &0.415k$\ohm$ &0.415k$\ohm$\\
\hline
U(V)   &0.175V &0.077V &0.107V
\end{tabular}
\end{table}
4
  • I hope you don't use the image as a background of the table... now the real 'problem' is that your table 'floats' away. If you don't need a caption (there is none there), you can omit the \begin{table}...\end{table} pair. Replace them with {...} only (such that the \small font declaration does not leak into the rest of the document.
    – user31729
    Oct 10, 2015 at 5:21
  • Try \begin{table}[htb]
    – user11232
    Oct 10, 2015 at 5:31
  • Lots of people are confused by this behaviour. What happens is that the table (and figure) environment are floating environments, which means that LaTeX can move them around to avoid bad page breaks. For example if you have a big table that doesn't fit in what's left of the page, then LaTeX can move text from after the table before it, so you don't get a half-empty page. Then instead of saying "the following table", you add a \caption and \label, and use \ref to add a cross-reference to the table. This isn't always what you want though, and then you can do something like (ctd.) Oct 10, 2015 at 13:16
  • 1
    what @ChristianHupfer did in his answer, and remove the table environment altogether. It is not required to surround a tabular with this environment. Similarly, one doesn't need a figure environment around an \includegraphics. Oct 10, 2015 at 13:17

1 Answer 1

2

Here a two strategies (and a third one, with floating table as the O.P. has already, which does not produce the requested result)

  1. Omit the \begin{table}...\end{table} pair and use {\small\centering ...} instead to prevent font declaration leaking into the rest of the document. The table will be centered then. For a caption you need \captionof{table}{Your caption text}.
  2. Try \begin{table}[htb]

In both cases the table stays at the desired position, keeping the text above as desired.

In addition, I've changed the look and dimensions of the table a little bit, using siunitx and tabularx packages.


\documentclass{article}

\usepackage{siunitx}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{blindtext}

\begin{document}

\blindtext
\begin{table}
\small
\begin{tabularx}{\linewidth}{*{4}{X}}
\multicolumn{4}{c}{The floating table} \tabularnewline
\hline
I(\si{\mA}) &1 &5 &7\tabularnewline
\hline
R(\si{\kohm})  &0.415 &0.415 &0.415\tabularnewline
\hline
U(\si{V})   &0.175 &0.077 &0.107
\end{tabularx}
\end{table}


\clearpage

\blindtext

\begin{table}[htb]
\small
\begin{tabularx}{\linewidth}{*{4}{X}}
\multicolumn{4}{c}{The non - floating table with \texttt{[htb]}} \tabularnewline
\hline
I(\si{\mA}) &1 &5 &7\tabularnewline
\hline
R(\si{\kohm})  &0.415 &0.415 &0.415\tabularnewline
\hline
U(\si{V})   &0.175 &0.077 &0.107
\end{tabularx}
\end{table}


\clearpage


\blindtext

{%
\centering
\small
\begin{tabularx}{\linewidth}{*{4}{X}}
\multicolumn{4}{c}{The non-floating floating table} \tabularnewline
\hline
I(\si{\mA}) &1 &5 &7\tabularnewline
\hline
R(\si{\kohm})  &0.415 &0.415 &0.415\tabularnewline
\hline
U(\si{V})   &0.175 &0.077 &0.107
\end{tabularx}
\captionof{table}{My still improvable table}
}

\clearpage
\end{document}

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.