Graphics, Figures & TablesHow to force table to be on the same page with text?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
rain
Posts: 12
Joined: Thu Jan 28, 2016 9:00 pm

How to force table to be on the same page with text?

Post by rain »

Hello.

How do I force table to be on the same page with text?

Code: Select all

\section{Differences between CVE and OWASP}
In this chapter we will give overview of differences between CVE and OWASP. For better redability, we will do this in the form of table.
\begin{table}[h] \label{cmp}
\begin{center}
\caption {Differences between CVE and OWASP}
\begin{tabularx}{\textwidth}{|X|X|X|}
\hline \textbf{Criteria} & \textbf{CVE} & \textbf{OWASP} \\
\hline \textbf{Purpose}  & To give overview of software and it's version specific vulnerabilities  &  To general information about vulnerabilities by class and give developers example codes that contain given type of vulnerability and explain how to fix that type of vulnerability. \\ 
\hline \textbf{Naming} & Systematic naming of CVEs. CVE name itself does not say anything about vulnerability. Example: CVE-2008-3224. &  Lists vulnerability by name of it's type. Example: Integer overflow. \\
\hline \textbf{Multiplicity} & CVE Name is in role of primary key that uniquely identifies software and it's version that can be exploited trough this vulnerability, publish date, score (severity), etc.  & For one type of vulnerability there are many programs that are affected by it. \\
\hline \textbf{Sample code} & No & Yes \\
\hline \textbf{Offers solution} & No & Yes \\
\hline \textbf{Offers guidelines} & No & Yes \\
\hline \textbf{Statistics} & Histogram & Document of top ten vulnerabilities.\\
\hline \textbf{Descriptiveness} & Vulnerability is described in few sentences. Description does not explicitly teach how to exploit that vulnerability. & Vulnerability description gives detailed overview of given vulnerability and how it works. \\
\hline \textbf{Descriptiveness of vulnerability} & Vulnerability is described in few sentences. Description does not explicitly teach how to exploit that vulnerability. & Vulnerability description gives detailed overview of given vulnerability and how it works. \\
\hline
\end{tabularx}
\end{center}
\end{table}
\FloatBarrier
Gives me ugly result, but when you look at image it can be seen that table has plenty of room on page previous page.
Attachments
rainTableMod.jpg
rainTableMod.jpg (45.58 KiB) Viewed 27764 times

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

mas
Posts: 226
Joined: Thu Dec 04, 2008 4:39 am

How to force table to be on the same page with text?

Post by mas »

When you post the code also include the preamble so that others have an idea of packages you are using. Since it is missing, one can only guess at the page dimensions you are using.

By changing the dimensions/geometry of the page, you can get the table on the same page. I used

Code: Select all

\usepackage[body={15cm,23cm},headheight=15.2pt,centering]{geometry}
x.png
x.png (19.07 KiB) Viewed 27774 times

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim
rain
Posts: 12
Joined: Thu Jan 28, 2016 9:00 pm

How to force table to be on the same page with text?

Post by rain »

I use template that was given by school for essay.

Code: Select all

\documentclass[runningheads,a4paper]{llncs}

\usepackage{amssymb}
\setcounter{tocdepth}{3}
\usepackage{graphicx}
\usepackage{color}
\usepackage{xcolor}

\usepackage{url}
\urldef{\mailsa}\path|{alfred.hofmann, ursula.barth, ingrid.haas, frank.holzwarth,|
\urldef{\mailsb}\path|anna.kramer, leonie.kunz, christine.reiss, nicole.sator,|
\urldef{\mailsc}\path|erika.siebert-cole, peter.strasser, lncs}@springer.com|    
\newcommand{\keywords}[1]{\par\addvspace\baselineskip
\noindent\keywordname\enspace\ignorespaces#1}
\usepackage{tabularx}
\usepackage{placeins}
\usepackage{pbox}
\begin{document}
    \section{Differences between CVE and OWASP}
    In this chapter we will give overview of differences between CVE and OWASP. For better redability, we will do this in the form of table.
    \begin{table}[h] \label{cmp}
    \begin{center}
    \caption {Differences between CVE and OWASP}
    \begin{tabularx}{\textwidth}{|X|X|X|}
    \hline \textbf{Criteria} & \textbf{CVE} & \textbf{OWASP} \\
    \hline \textbf{Purpose}  & To give overview of software and it's version specific vulnerabilities  &  To general information about vulnerabilities by class and give developers example codes that contain given type of vulnerability and explain how to fix that type of vulnerability. \\
    \hline \textbf{Naming} & Systematic naming of CVEs. CVE name itself does not say anything about vulnerability. Example: CVE-2008-3224. &  Lists vulnerability by name of it's type. Example: Integer overflow. \\
    \hline \textbf{Multiplicity} & CVE Name is in role of primary key that uniquely identifies software and it's version that can be exploited trough this vulnerability, publish date, score (severity), etc.  & For one type of vulnerability there are many programs that are affected by it. \\
    \hline \textbf{Sample code} & No & Yes \\
    \hline \textbf{Offers solution} & No & Yes \\
    \hline \textbf{Offers guidelines} & No & Yes \\
    \hline \textbf{Statistics} & Histogram & Document of top ten vulnerabilities.\\
    \hline \textbf{Descriptiveness} & Vulnerability is described in few sentences. Description does not explicitly teach how to exploit that vulnerability. & Vulnerability description gives detailed overview of given vulnerability and how it works. \\
    \hline \textbf{Descriptiveness of vulnerability} & Vulnerability is described in few sentences. Description does not explicitly teach how to exploit that vulnerability. & Vulnerability description gives detailed overview of given vulnerability and how it works. \\
    \hline
    \end{tabularx}
    \end{center}
    \end{table}
    \FloatBarrier
\end{document}
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to force table to be on the same page with text?

Post by Johannes_B »

I am always said when i hear that schools are distributing templates that aren't even suited for the job. llncs is for special submissions to Springer.

Nevermind, you are using a center environment within a table environment. That is even listed in ltaboo. Don't.

Code: Select all

\documentclass[runningheads,a4paper]{llncs}

\usepackage{amssymb}
\setcounter{tocdepth}{3}
\usepackage{graphicx}
\usepackage{xcolor}
%\usepackage{showframe}
\usepackage{booktabs}
\usepackage{ragged2e}

\usepackage{url}
\urldef{\mailsa}\path|{alfred.hofmann, ursula.barth, ingrid.haas, frank.holzwarth,|
	\urldef{\mailsb}\path|anna.kramer, leonie.kunz, christine.reiss, nicole.sator,|
	\urldef{\mailsc}\path|erika.siebert-cole, peter.strasser, lncs}@springer.com|    
	\newcommand{\keywords}[1]{\par\addvspace\baselineskip
	\noindent\keywordname\enspace\ignorespaces#1}
	\usepackage{tabularx}
	\usepackage{placeins}
	\usepackage{pbox}
	\newcommand{\tabhl}[1]{\textbf{#1}}
	\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
	\begin{document}
	\section{Differences between CVE and OWASP}
	In this chapter%An article does not have any chapters!
	we will give overview of differences between CVE and OWASP. For better redability, we will do this in the form of table.
	\begin{table}%[h]
%		\label{cmp}% that label doesn't work
%		\begin{center}% a center environment is useless when the table is set to use the full width of the page
		% Also, it adds vertical space above and below. Remove it and tada. 
			\caption {Differences between CVE and OWASP}
			\begin{tabularx}{\textwidth}{|X|X|X|}
				\hline \textbf{Criteria} & \textbf{CVE} & \textbf{OWASP} \\
				\hline \textbf{Purpose}  & To give overview of software and it's version specific vulnerabilities  &  To general information about vulnerabilities by class and give developers example codes that contain given type of vulnerability and explain how to fix that type of vulnerability. \\
				\hline \textbf{Naming} & Systematic naming of CVEs. CVE name itself does not say anything about vulnerability. Example: CVE-2008-3224. &  Lists vulnerability by name of it's type. Example: Integer overflow. \\
				\hline \textbf{Multiplicity} & CVE Name is in role of primary key that uniquely identifies software and it's version that can be exploited trough this vulnerability, publish date, score (severity), etc.  & For one type of vulnerability there are many programs that are affected by it. \\
				\hline \textbf{Sample code} & No & Yes \\
				\hline \textbf{Offers solution} & No & Yes \\
				\hline \textbf{Offers guidelines} & No & Yes \\
				\hline \textbf{Statistics} & Histogram & Document of top ten vulnerabilities.\\
				\hline \textbf{Descriptiveness} & Vulnerability is described in few sentences. Description does not explicitly teach how to exploit that vulnerability. & Vulnerability description gives detailed overview of given vulnerability and how it works. \\
				\hline \textbf{Descriptiveness of vulnerability} & Vulnerability is described in few sentences. Description does not explicitly teach how to exploit that vulnerability. & Vulnerability description gives detailed overview of given vulnerability and how it works. \\
				\hline
			\end{tabularx}
%		\end{center}
	\end{table}

	\clearpage% alternative 
	\begin{table}
		\renewcommand{\tabhl}[1]{#1}% comment out if you insist in making the table more destructive.
			\caption {Differences between CVE and OWASP}
		\label{cmp}% that label does work
		\renewcommand{\arraystretch}{1.5}
		\begin{tabularx}{\textwidth}{>{\RaggedRight}p{.25\linewidth}L@{\quad}L}
			\toprule
				 \tabhl{Criteria} & \tabhl{CVE} & \tabhl{OWASP} \\
				 \midrule
				 \tabhl{Purpose}  & To give overview of software and it's version specific vulnerabilities  &  To general information about vulnerabilities by class and give developers example codes that contain given type of vulnerability and explain how to fix that type of vulnerability. \\
				 \tabhl{Naming} & Systematic naming of CVEs. CVE name itself does not say anything about vulnerability. Example: CVE-2008-3224. &  Lists vulnerability by name of it's type. Example: Integer overflow. \\
				 \tabhl{Multiplicity} & CVE Name is in role of primary key that uniquely identifies software and it's version that can be exploited trough this vulnerability, publish date, score (severity), etc.  & For one type of vulnerability there are many programs that are affected by it. \\
				 \tabhl{Sample code} & No & Yes \\
				 \tabhl{Offers solution} & No & Yes \\
				 \tabhl{Offers guidelines} & No & Yes \\
				 \tabhl{Statistics} & Histogram & Document of top ten vulnerabilities.\\
				 \tabhl{Descriptiveness} & Vulnerability is described in few sentences. Description does not explicitly teach how to exploit that vulnerability. & Vulnerability description gives detailed overview of given vulnerability and how it works. \\
				 \tabhl{Descriptiveness of vulnerability} & Vulnerability is described in few sentences. Description does not explicitly teach how to exploit that vulnerability. & Vulnerability description gives detailed overview of given vulnerability and how it works. \\
				 \bottomrule
			\end{tabularx}
	\end{table}
	\end{document}
The example above contains a second approach to tables. The layout is much more light-weight and open.
Attachments
rainTabular.png
rainTabular.png (63.4 KiB) Viewed 27758 times
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
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

How to force table to be on the same page with text?

Post by Stefan Kottwitz »

Perhaps the school wants people to learn how to work with a publisher's template for submitting scientific articles, and just chose Springer.

Rain, templates in general are just known to be often not perfect, sometimes even misleading, and specifically a publisher's template is made for matching their own style perfectly, not to be good in its own or to be modern and flexible.

As I like screenshots :-) here's one of the Johannes' improved table, so readers can compare with the "classical" table above:
table.png
table.png (55.31 KiB) Viewed 27758 times
Stefan
LaTeX.org admin
rain
Posts: 12
Joined: Thu Jan 28, 2016 9:00 pm

How to force table to be on the same page with text?

Post by rain »

Thank you!

Solution:

Code: Select all

%\begin{center}%a center environment is useless 
when the table is set to use the full width of the page. 
Also, it adds vertical space above and below. 
Remove it and tada.
Post Reply