I'm new to LaTex and I'm trying to create a table with items, but I'm having issues with closing the table borders. When I add "|" to the {tabularx}, I get a new column that I don't want. I tried to follow different LaTex examples, but I'm stuck on how to close my table:
My code is
\documentclass{article}
\usepackage{tabularx}
\usepackage{paralist}
\makeatother
\begin{document}
\begin{table}[!b]
\centering
\caption{ Comparison between ST-Kriging, Bayesian inference, and ANNs.}
\label{tab:2}
\renewcommand{\arraystretch}{1.5}
\scriptsize
\begin{tabularx}{\textwidth} {|p{2.3cm}|p{3.5cm}|p{3.5cm}|p{3.5cm}}
\hline
\textbf{} & \textbf{Bayesian Inferences} & \textbf{ST-Kriging} & \textbf{ANNs} \\ \hline
\textbf{Computational Complexity} & NP-hard \cite{ref-satria2020spatial} & $O(N^2)$ & $O(i\times o\times n + n\times o)$ or $O(n \times o \times (i+1))$ for training a single epoch. \cite{ref-taylor1995freeway} \\ \hline
\textbf{Performance Evaluation } & Provides a posterior probability distribution with confidence interval. &
Ensure linear unbiased predictors. & Epoch with the lowest sum of squared error.\\ \hline
\textbf{Weaknesses} & Very computationally intensive due to choosing the proper prior distribution.
&
\begin{compactitem}
\item Missing value causes error in unmatched dimensions.
\item Can not handle large datasets.
\item Require normal distribution.
\end{compactitem}
&
Require intensive data training, and this might lead to an overfitting problem. \\ \hline
\textbf{Strengths }
&
\begin{compactitem}
\item Handle large and small data.
\item Handle missing values.
\item Prior knowledge about uncertain input is not required.
\end{compactitem}
&
\begin{itemize}
\item Handle small data.
\item Computational efficiency.
\end{itemize}
&
\begin{compactitem}
\item Handle big data and small data.
\item Accommodate missing values without a separate estimation step [108]
\item Computational efficiency due to the parallelity feature.
\item Prior knowledge about uncertain input is not required.
\end{compactitem}
\\ \hline
\textbf{Overcoming the Limitation}
&
Use uninformative prior to reduce the computational time, however, it can affect the prediction accuracy negatively.
&
Remove observations that include missing values.
&
\begin{compactitem}
\item Decrease the number of layers of the network.
\item Use iterative methods to stop the training process such as gradient descent.
\end{compactitem}
\\ \hline
\end{tabularx}
\end{table}
\end{document}
The table will look like this:
I believe that the issue is with this line, but I can't find a way to fix it:
\begin{tabularx}{\textwidth} {|p{2.3cm}|p{3.5cm}|p{3.5cm}|p{3.5cm}}
If I add "|" it will create another column instead of closing the table. Any thoughts on what could be the issue? I used "tabular" here instead of "tabularx" and I had no issue, but because I wanted to reduce the space between the list indented text, therefore I had to switch to "tabularx".
The problem is that when one sums up all your manually defined columns widths, they are larger than the available \textwidth. As you are using a tabularx environment, you could instead use X columns and latex will automatically calculate a suitable width:
\documentclass{article}
\usepackage{tabularx}
\usepackage{paralist}
\makeatother
\begin{document}
\begin{table}[!b]
\centering
\caption{ Comparison between ST-Kriging, Bayesian inference, and ANNs.}
\label{tab:2}
\renewcommand{\arraystretch}{1.5}
\scriptsize
\begin{tabularx}{\textwidth}{|X|X|X|X|}
\hline
\textbf{} & \textbf{Bayesian Inferences} & \textbf{ST-Kriging} & \textbf{ANNs} \\ \hline
\textbf{Computational Complexity} & NP-hard \cite{ref-satria2020spatial} & $O(N^2)$ & $O(i\times o\times n + n\times o)$ or $O(n \times o \times (i+1))$ for training a single epoch. \cite{ref-taylor1995freeway} \\ \hline
\textbf{Performance Evaluation } & Provides a posterior probability distribution with confidence interval. &
Ensure linear unbiased predictors. & Epoch with the lowest sum of squared error.\\ \hline
\textbf{Weaknesses} & Very computationally intensive due to choosing the proper prior distribution.
&
\begin{compactitem}
\item Missing value causes error in unmatched dimensions.
\item Can not handle large datasets.
\item Require normal distribution.
\end{compactitem}
&
Require intensive data training, and this might lead to an overfitting problem. \\ \hline
\textbf{Strengths }
&
\begin{compactitem}
\item Handle large and small data.
\item Handle missing values.
\item Prior knowledge about uncertain input is not required.
\end{compactitem}
&
\begin{itemize}
\item Handle small data.
\item Computational efficiency.
\end{itemize}
&
\begin{compactitem}
\item Handle big data and small data.
\item Accommodate missing values without a separate estimation step [108]
\item Computational efficiency due to the parallelity feature.
\item Prior knowledge about uncertain input is not required.
\end{compactitem}
\\ \hline
\textbf{Overcoming the Limitation}
&
Use uninformative prior to reduce the computational time, however, it can affect the prediction accuracy negatively.
&
Remove observations that include missing values.
&
\begin{compactitem}
\item Decrease the number of layers of the network.
\item Use iterative methods to stop the training process such as gradient descent.
\end{compactitem}
\\ \hline
\end{tabularx}
\end{table}
\end{document}
If you use tabularx one of the column should be X which adapts its width to a remaining available width.
Your table is quite wordy and due to number of columns there doesn't seem to be enough space for long texts. You could consider rotating a table and use a pageheight as an available space for a width of the table.
While correcting your table, I have also made a few adjustments:
indentation removed in lists to increase horizontal space
the caption moved upwards to add a little space between title and the table
increased vertical spacing in the first row by inserting a strut
space between columns slightly decreased
added rules from booktabs
reduced margins on the page with the table.
\documentclass{article}
\usepackage{tabularx}
\usepackage{calc}
\usepackage{paralist}
%% Added packages
\usepackage{booktabs} % For improved rules
\usepackage{caption} % For extra space between table and caption
\usepackage{rotating} % For sidewaystable
\usepackage{ragged2e} % Improves typesetting in
\usepackage{microtype} % in narrow environments
\usepackage{geometry}
\captionsetup[table]{position=top,skip=3pt,font=normalsize}
%% END Added packages
\setdefaultleftmargin{0em}{}{}{}{}{}
\begin{document}
\newgeometry{top=1in,bottom=1in}
\begin{sidewaystable}
\RaggedLeft
\setlength\tabcolsep{4pt}
\newcommand\xstrut[1][1]{%
\rule[-0.35\normalbaselineskip*\real{#1}]{0pt}{#1\normalbaselineskip}}
\newcommand\xthead[1]{\normalsize\textbf{#1}}
\renewcommand{\arraystretch}{1.25}
\centering
\caption{Comparison between ST-Kriging, Bayesian inference, and ANNs.}
\label{tab:2}
\footnotesize
\begin{tabularx}{0.9\textwidth} {p{3cm}XXX}
\specialrule{\heavyrulewidth}{0pt}{0pt}
\xstrut[2.2]
& \xthead{Bayesian Inferences}
& \xthead{ST-Kriging}
& \xthead{ANNs} \\
\midrule[\heavyrulewidth]
\textbf{Computational Complexity}
& NP-hard \cite{ref-satria2020spatial}
& $O(N^2)$
& $O(i\times o\times n + n\times o)$ or $O(n \times o \times (i+1))$\newline for training a single epoch. \cite{ref-taylor1995freeway} \\
\midrule
\textbf{Performance Evaluation}
& Provides a posterior probability distribution with confidence interval.
& Ensure linear unbiased predictors.
& Epoch with the lowest sum of squared error. \\
\midrule
\textbf{Weaknesses}
& Very computationally intensive due to choosing the proper prior distribution.
& \begin{compactitem}
\item Missing value causes error in unmatched dimensions.
\item Can not handle large datasets.
\item Require normal distribution.
\end{compactitem}
& Require intensive data training, and this might lead to an overfitting problem. \\
\midrule
\textbf{Strengths }
&
\begin{compactitem}
\item Handle large and small data.
\item Handle missing values.
\item Prior knowledge about uncertain input is not required.
\end{compactitem}
&
\begin{itemize}
\item Handle small data.
\item Computational efficiency.
\end{itemize}
&
\begin{compactitem}
\item Handle big data and small data.
\item Accommodate missing values without a separate estimation step [108]
\item Computational efficiency due to the parallelity feature.
\item Prior knowledge about uncertain input is not required.
\end{compactitem} \\
\midrule
\textbf{Overcoming the Limitation}
&
Use uninformative prior to reduce the computational time, however, it can affect the prediction accuracy negatively.
&
Remove observations that include missing values.
&
\begin{compactitem}
\item Decrease the number of layers of the network.
\item Use iterative methods to stop the training process such as gradient descent.
\end{compactitem} \\
\bottomrule
\end{tabularx}
\end{sidewaystable}
\restoregeometry
\end{document}
Related
I am having problems in adjusting the format for a table in LaTex. The code is the following and the image depicts how the table comes out after compiling:
\begin{table}[H]
\centering
\renewcommand{\arraystretch}{1.2}
\resizebox{\columnwidth}{!}{
\begin{tabular}{|p{2cm}|c|c|c|}
\hline
{\textbf{Labels}} & {\textbf{Precision}} & {\textbf{Recall}} & {\textbf{F1-Score}}
\\
% \hline
\cline{2-9}
% \textbf{Inactive Modes} & \textbf{Description}\\
%\hhline{~--}
{Not Misogynous} & $37.49\%\pm1.91\%$ & $46.13\%$ & $36.15\%\pm2.61\%$ & \\ \hline
{Not Misogynous} & $37.49\%\pm1.91\%$ & $46.13\%$ & $36.15\%\pm2.61\%$ & \\ \hline
\end{tabular}
}
\caption{BERTweet binary task}
\label{table:bert_binary}
\end{table}
I don't understand how to add the necessary line to "close" the boxes around the table
You have a few issues in your code.
You specify 4 columns p{}ccc while a content of tabular body has 5 columns (with the extra ending &). This is why the lines are discontinued.
Numbers X and Y in the argument of \cline{X-Y} must not exceed the available number of columns. You define 4 and trying to draw horizontal rule between 2 and 9. You probably get the error: Extra alignment tab has been changed to \cr.
You should avoid inserting empty line in tables. Most of the times LaTeX do not accept \par in table environments, which is converted from empty lines. It may work in modern packages that use more recent advances in LaTeX.
I also wonder why you enclose cells inside {...}. The code works without them. Is there any particular reason? Perhaps in the main code you load siunitx and apply S-type column. Then, you do have to tell siunitx which cells are non-numeric by wrapping cells inside braces. Otherwise, siunitx issues error!
Here's my suggestion for the table:
I defined columns which accept math expressions without extra $...$
The main values and uncertainties are split in columns to improve formatting and spacing
booktabs provides improved rules that arguably improved presentation
Default gap between the table and its caption seems too large, so I slightly reduced it (requires caption package)
I keep captions of tables at the top and captions of figures at the bottom but this is again a personal preference.
One of the rules I usually follow is to avoid repeated information in tables. The % in your case is repeated everywhere. You could remove it and add annotation that values in all three columns are percentages.
Here's the table
and the code
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup[table]{position=bottom,skip=3pt}
\newcolumntype{R}{>{\(}r<{\)}}
\newcolumntype{L}{>{\(}r<{\)}}
\begin{document}
\begin{table}[tbh]
\centering
\renewcommand{\arraystretch}{1.2}
\caption{BERTweet binary task}
\label{table:bert_binary}
\begin{tabular}{p{2.5cm} R#{\;}L c R#{\;}L}
\toprule
\textbf{Labels}
& \multicolumn{2}{c}{\textbf{Precision}}
& \textbf{Recall}
& \multicolumn{2}{c}{\textbf{F1-Score}} \\
\midrule
Not Misogynous & 37.49 & \pm1.91 & 46.13 & 36.15 & \pm2.61 \\
Not Misogynous & 37.49 & \pm1.91 & 46.13 & 36.15 & \pm2.61 \\
\bottomrule
\multicolumn{6}{#{}l#{}}{\footnotesize All values in \%}
\end{tabular}
\end{table}
\end{document}
I think the previous answer to this question is very good and detailed, including many observations that is always useful to consider when doing tables in LaTeX. It also addresses you to avoid vertical lines in tables (consistently with the use of the package booktabs).
I add the following code and output just for the sake to remark the minimal edits necessary for your original code to reach a threshold look.
\documentclass{article}
\begin{document}
\renewcommand{\arraystretch}{1.2}
\begin{table}%[H]
\centering
\begin{tabular}{|p{3cm}|c|c|c|}
\hline
{\textbf{Labels}} & {\textbf{Precision}} & {\textbf{Recall}} & {\textbf{F1-Score}}\\
\hline
Not Misogynous & $37.49\%\pm1.91\%$ & $46.13\%$ & $36.15\%\pm2.61\%$\\
\hline
Not Misogynous & $37.49\%\pm1.91\%$ & $46.13\%$ & $36.15\%\pm2.61\%$\\
\hline
\end{tabular}
\caption{BERTweet binary task}
\label{table:bert_binary}
\end{table}
\end{document}
I am using Overleaf to take notes in my classes and I am running into trouble with a tabular column I am trying to create. My code is the following:
\begin{center}
\begin{tabular}{|c|c|}
\hline
Crystalline Solids & Non-Crsytalline Solids \\
\hline
i. Atoms and molecules are periodic in space & i. Atoms and molecules are not periodic in space \\
\hline
ii. Some crystalline solids are anisotopic \\
i.e the magnitudes of the physical properties like \\
refractive index, electrical conductivity are \\
different along difference directions \\ & ii. Physical properties are isotropic \\
\hline
iii. Have sharp melting points & iii. Do not have sharp boiling points - a range is present \\
\hline
iv. Breaks are observed in the cooling curve & iv. No breaks in cooling curve \\
\hline
v. Breaks along sharp edges i.e breaks \\
along specific "crystallographic planes" & v. Broken surfaces are irregular because there are no crystal planes \\
\hline
\end{tabular}
\end{center}
The problem is that now my table appears like so. https://imgur.com/ZrWFNSS
I have tried using the \begin{table} environment and the \begin{figure} environment but even after using qualifiers like [h] or [ht] the table's position in the text also changes, and the alignment is still off. How do I correct this to fit it into the page?
c, l and r columns don't wrap their contents. You'll have to use a fixed-width p{<len>} column for your tabular, or consider using tabularx.
Here's an option with a paragraph-style column specification:
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{center}
\begin{tabular}{ l p{.45\linewidth} p{.45\linewidth} }
\toprule
& \multicolumn{1}{c}{Crystalline Solids} &
\multicolumn{1}{c}{Non-Crystalline Solids} \\
\midrule
i. & Atoms and molecules are periodic in space &
Atoms and molecules are not periodic in space \\
ii. & Some crystalline solids are anisotopic \textit{i.e.}~the magnitudes of the physical properties
like refractive index, electrical conductivity are different along difference directions &
Physical properties are isotropic \\
iii. & Have sharp melting points &
Do not have sharp boiling points --- a range is present \\
iv. & Breaks are observed in the cooling curve &
No breaks in cooling curve \\
v. & Breaks along sharp edges i.e breaks along specific ``crystallographic planes'' &
Broken surfaces are irregular because there are no crystal planes \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
Here's a similar option using tabularx:
\documentclass{article}
\usepackage{tabularx,booktabs}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{ l X X }
\toprule
& \multicolumn{1}{c}{Crystalline Solids} &
\multicolumn{1}{c}{Non-Crystalline Solids} \\
\midrule
i. & Atoms and molecules are periodic in space &
Atoms and molecules are not periodic in space \\
ii. & Some crystalline solids are anisotopic \textit{i.e.}~the magnitudes of the physical properties
like refractive index, electrical conductivity are different along difference directions &
Physical properties are isotropic \\
iii. & Have sharp melting points &
Do not have sharp boiling points~--- a range is present \\
iv. & Breaks are observed in the cooling curve &
No breaks in cooling curve \\
v. & Breaks along sharp edges i.e breaks along specific ``crystallographic planes'' &
Broken surfaces are irregular because there are no crystal planes \\
\bottomrule
\end{tabularx}
\end{document}
This below latex code has warning saying Overfull \hbox (1.38991pt too wide) in paragraph at lines; pdf is getting generated without any issue, I am trying to find out where exactly I am making a mistake to see that warning.
Latex code1:
\begin{document}
\setbeamertemplate{caption}[numbered]
\begin{frame}
\titlepage
\end{frame}
Latex code2:
%\section{Literature Review}%
\begin{frame}{OBJECTIVE}
\begin{table}[h!]
\centering
\begin{tabular}{ p{3cm}|p{7cm}}
\hline
\vspace{1pt}
Title & “CompaRob:The shopping cart assistance robot" \textit{’ Int. J. Distrib. Sensor Netw., vol. 12,no. 2, Feb. 2016, Art. no. 4781280.} \\
\hline
\vspace{6mm}
Methodology &
\begin{itemize}
\item Radio and ultrasound signals
\item Provide freedom of movements for elderly people
\end{itemize}\\
\hline
\vspace{1pt}
Demerit &
\begin{itemize}
\item Not able to show how to find a product
\end{itemize}\\
\hline
\end{tabular}
\end{table}
\end{frame}
There is not enough space to fit 10 cm worth of columns and the default padding before and after the columns. Either remove the padding by using #{}p{2.9cm}|p{7cm}#{} or make the columns a bit smaller:
\documentclass{beamer}
\begin{document}
\setbeamertemplate{caption}[numbered]
\begin{frame}
\titlepage
\end{frame}
%\section{Literature Review}%
\begin{frame}{OBJECTIVE}
\begin{table}[h!]
\centering
\begin{tabular}{ p{2.9cm}|p{7cm}}
\hline
\vspace{1pt}
Title & “CompaRob:The shopping cart assistance robot" \textit{’ Int. J. Distrib. Sensor Netw., vol. 12,no. 2, Feb. 2016, Art. no. 4781280.} \\
\hline
\vspace{6mm}
Methodology &
\begin{itemize}
\item Radio and ultrasound signals
\item Provide freedom of movements for elderly people
\end{itemize}\\
\hline
\vspace{1pt}
Demerit &
\begin{itemize}
\item Not able to show how to find a product
\end{itemize}\\
\hline
\end{tabular}
\end{table}
\end{frame}
\end{document}
I am trying to format a table of numbers with units using the siunitx package to align the numbers on the decimal.
I am having trouble controlling the amount of white space that siunitx is allocating to the display of numbers.
Here is an example. I would like the numbers in the first column to be closer to the right, as they are in the third column, and I would like there to be less space on the left of numbers in the third column. (The vertical lines are ugly, I know, but they show the column widths.)
\documentclass[10pt,a4paper]{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{|S|r|S|r|}
\multicolumn{2}{c}{Range} & \multicolumn{2}{c}{Readout} \\
\hline
10 & mV & 0.000049 & mV \\
100 & V & 0.00007 & mV \\
\end{tabular}
\end{document}
EDIT
As a continuation of this question, I am trying to find a way to report numbers and units in the same column, with a single (or at least uniform) space between them. But again whitespace is hard to control. For example,
\begin{tabular}{
S|
S|
S[table-format=1.9]
}
{Range} & {Readout} & {Uncertainty} \\
\hline
10 {mV} & 0.000022~{mV} & 0.000069 {mV}\\
100 {mV} & -0.00001~{mV} & 0.00011 {mV}\\
1 {V} & -0.0000007~{V} & 0.00000029 V\\
10 {V} & -0.000007~{V} & 0.0000029 V\\
100 {V} & -0.000075~{V} & 0.000058 V\\
\end{tabular}
which produces this
Here, in the first column, space is inserted after the numbers depending on how big the mantissa is; in the second column there is too much white space on the left of the numbers; in the third column, the space between the number and unit allows for a certain number of digits.
Also, the use of ~ in the second column seems necessary. Without it, the text is joined directly to the number. I have played with table-align-text-post and -pre, as described in the siunitx docs, but they don't seem to work here. I thought they would.
You can specify how many digits are before and after the decimal marker. The syntax is table-format=<digits before marker>.<digits after the marker>
\documentclass[10pt,a4paper]{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{|S[table-format=3.0]|r|S[table-format=1.6]|r|}
\multicolumn{2}{c}{Range} & \multicolumn{2}{c}{Readout} \\
\hline
10 & mV & 0.000049 & mV \\
100 & V & 0.00007 & mV \\
\end{tabular}
\end{document}
I have this equation and it's quite big (basically a FDM one) but it aligns with the text and then continues out on the right side to the nothingness. I've tried stuff like \begin{center} and \hspace*{-2.5cm} but to no avail. I want it to use the whole line not just from the left-margin and out to the right.
How do I do it and do I need to install some special package for it?
I use the \[ instead of the displaymath like this
\[
Equation arrays here
\]
The code
\[
\left(
\begin{array}{cccccc}
-(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) & 0 & \cdots & 0 \\
-\kappa & -(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) & 0 & \cdots \\
0 & -\kappa & -(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) & 0 & \cdots \\
\vdots & 0 & \ddots & \vdots \\
\vdots & \vdots & \vdots & -\kappa & -(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) \\
0 & \vdots & \vdots & 0 & \kappa - \frac{2h\kappa_{v}}{\kappa}(\frac{hv\rho}{2} - \kappa) & -2\kappa \\
\end{array}
\right)
\left(
\begin{array}{c}
T_{1} \\
T_{2} \\
\vdots \\
T_{n} \\
\end{array}
\right)
=
\left(
\begin{array}{c}
Q(0) + \kappa T_{0} \\
Q(h) \\
Q(2h) \\
\vdots \\
Q((n-1)h) \\
2\frac{\kappa_{v}}{\kappa_{v}}T_{out} \\
\end{array}
\right)
\]
The \[ \] delimiters are intended for single-line equations. In basic LaTeX you can use the eqnarray environment to make a multi-line equations, or you can use the multline environment from the amsmath package. The eqnarray environment lets you use \\ for line breaks but if you want the equation to be numbered, you also need to use the \nonumber command on all lines but one to prevent the numbering of all lines. The multline environment is intended for a single equation so it always produces just one equation number too.
EDIT: This isn't what I would do habitually, but since your equation does seem to fit on a single line, here's the code I've used to get whole-line spanning things:
\newenvironment{widefig}[1][1in]{%
\begin{list}{}{\setlength{\itemindent}{-#1}%
\setlength{\leftmargin}{0pt}%
\setlength{\rightmargin}{0pt}}\item
}{%
\end{list}
}
Like the environment name suggests, I wrote it for figures that are too wide to fit inside the margins, so this allows controlling the left margin and permits a figure to be centered on the whole line.
How I modified your example was to wrap it inside a \begin{widefig}[1.5in]-\end{widefig} pair, added
\relpenalty=10000
\binoppenalty=10000
after the \begin{widefig} line to prohibit line breaking inside the formula, and changed the \[\] into \(\) because the widefig environment only works for inline, not display. You might also need to fiddle a bit with the amount of space given on the \begin line to make the equation properly centered.
I don't believe this is very good typesetting style, though, so you'll want to be very careful about using it, and preferably try to fit things inside the margins. For instance, in this case you could also get rid of a few columns in your first matrix; the usual standard is to have only the first, second, and last, but you probably also want the second-to-last row and column, since the changes in the values for the last row and column is a bit surprising. If you did that, it might fit (but I didn't check).
If you really don't want to break the equation over lines and you don't mind breaking the text width, you could try something like: (untested)
\centerline{$\displaystyle <long equation here>$}
could you add a line-break using \\ ?
Begin centre only aligns things like figures, it won't affect line equations.
You might like to look at the American Mathematical Society guide to their package s
ftp://ftp.ams.org/pub/tex/doc/amsmath/amsldoc.pdf
You could use the eqnarray environment to break equations into multiple lines.