Table in Latex Overlapping with Second Column of the Page - latex

I got a problem with tables in LaTeX. I am using a pre-defined format from a conference, which makes a page consists of two columns. My table is too wide to be contained in one column, so it goes to the second column of the page and overlaps with text!
Why is LaTeX allowing this?
Is it possible in the current format, to make the table a block, so that it uses two columns, and the text in the other column dragged down a bit?
Any other suggestion?
This is my code:
\begin{table}
\centering
\begin{tabular}{|c|c|c|c|c|c|}
\hline
Rule & Factor & Best Value & Delta_t & Delta_{do} & Comments \\
\hline
\multirow{3}{c}{Diagonal Dominance} & Line Angle & 45 & 15 & 30 & The angle between the prominent line of the object and
the diagonal lines \\ % TODO: What object? Make sure it is clear.
& Line Distance & 0 & 0.25 & 1 & The distance, in screen coordinates, from the
prominent line of the object to the diagonal lines. \\ % TODO: Need to define screen coordinates
& Corner Distances & 0 & 0.1 & 0.7 & The distance, in screen coordinates, from the
end of the prominent line of the object to the corners of the screen. \\
\hline
\end{tabular}
\caption{The factors of each rule and their parameters.}
\label{table:factors}
\end{table}
Thank you in advance for your help.
Regards,
Rafid

Generally, the starred version of floating environments are used to tell LaTeX to span two columns. So, something like:
\begin{table*}
% Table contents
\end{table*}
The same can be done with figures.

In place of tabular, use tabularx, for example:
\begin{tabularx}{\textwidth}{|c|c|c|c|c|X|}
Sorry, #Rafid, I normally use memoir, which includes it, so I forgot this bit:
\usepackage{tabularx}

Related

Problems in formatting table and closing tables "boxes" in latex

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}

LaTex table corner cell line not showing

I'm using Overleaf to write a report. I can't seem to get the format just right for the top right corner cell.
I would also like to center "Correlation coefficient"
\begin{table}[h]
\caption{Correlation coefficient between force plate data and kinematic model data}
\label{IMUvsVB}
\begin{center}
\begin{tabular}{|c||c||c|}
\hline
\textbf{Ground reaction} & \multicolumn{2}{l}{\textbf{Correlation coefficient}} \\
\cline{2-3}
& \textbf{IMU based kinematics} & \textbf{Vision based kinematics}\\
\hline
Anteroposterior & 0.91 & 0.96\\
Mediolateral & 0.80 & 0.79\\
Vertical & 0.97 & 0.99\\
Frontal & 0.64 & 0.66\\
Sagittal & 0.91 & 0.94\\
Transverse & 0.82 & 0.84\\
\hline
\end{tabular}
\end{center}
\end{table}
Substitute
\textbf{Ground reaction} & \multicolumn{2}{l}{\textbf{Correlation coefficient}} \\
with
\textbf{Ground reaction} & \multicolumn{2}{c|}{\textbf{Correlation coefficient}} \\
The \multicolumn command needs 3 inputs:
The 1st one is the number of columns to be spanned.
The 2nd is the formatting of the cell (l for left, c for center and r for right). Here you can add also | for a single vertical line or even || for a double vertical line.
The 3rd one is the content of the cell.
Have a look at the documentation here if you need more insights on the usage of \multicolumn.

White space in siunitx columns

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}

How to underline columns with gaps in the line?

I am looking for a way to put this into a table with the underlining going correctly. What I want is the following: both columns are underlined, but it is not one connected line. I would like to have a small gap in between the two. How can I obtain this?
I know I can underline columns with \cline{1} and \cline{2} but this makes them connected, which is what I do not want.
\begin{table}
\begin{tabular}{cc}
3 & 3 \\
\end{tabular}
\end{table}
Hopefully someone can help me out.
Simply use an empty column and hhline (or cline)
%...
\usepackage{hhline}
%...
\begin{tabular}{c#{\ }c#{\ }c}
3 & & 3 \\
\hhline{-~-}
\end{tabular}

Latex: Problem with Multirow

I am creating a table with mulitrow but I am getting a problem. As far as I understand, this is the form of the multirow:
\multirow{count}{alignment}{content}
where count is the number of rows to merge, alignment is either l, c, r, or *, and content is the content of the row. I tried the following:
\multirow{3}{*}{Framing}
but I am getting a problem. Rather than seeing the word "Framing" in the cell, I see "3*Framing" which gives the indication that the \multirow element isn't working. Any idea?
Also, how is it possible to align a text in a cell vertically?
UPDATE:
I thought the \usepackage{multirow} would solve it, but I still see problems:
First, I can't make vertical alignments.
Second, I get some strange thing with the "Framing" cell. Instead of getting "Framing" aligned to the left, I get one virtual row containing the letter "l" and then after two virtual rows I get the word "Framing"!! It is something like this:
______________
| l |
| |
| Framing |
| |
| |
| |
| |
______________
This is my table for those who asked about it:
\begin{table*}\tiny
\centering
\begin{tabular}{|c|c|c|c|c|p{2in}|}
\hline
Rule & Factor & Best Value & \Delta_t & \Delta_{do} & Comments \\
\hline
% Diagonal Dominance Rule
\multirow{3}{*}{Diagonal Dominance} & Line Angle & 45 & 15 & 30 & The angle between the prominent line of the object and
the diagonal lines \\ % TODO: What object? Make sure it is clear.
& Line Distance & 0 & 0.25 & 1 & The distance, in screen coordinates, from the
prominent line of the object to the diagonal lines. \\ % TODO: Need to define screen coordinates
& Corner Distances & 0 & 0.1 & 0.7 & The distance, in screen coordinates, from the
end of the prominent line of the object to the corners of the screen. \\
\hline
% Framing Rule
\multirow{4}{l}{Framing} & Left Distance & 0 & ${Frame Width}*5\%$ & ${Frame Width}*25\%$ & The distance between the
left side of the frame covering the object and the left or the right side of the intended frame, whichever closer. \\
& Right Distance & 0 & ${Frame Width}*5\%$ & ${Frame Width}*25\%$ & The distance between the
right side of the frame covering the object and the left or the right side of the intended frame, whichever closer. \\
& Top Distance & 0 & ${Frame Height}*5\%$ & ${Frame Height}*25\%$ & The distance between the
top side of the frame covering the object and the upper or the lower side of the intended frame, whichever closer. \\
& Bottom Distance & 0 & ${Frame Height}*5\%$ & ${Frame Height}*25\%$ & The distance between the
bottom side of the frame covering the object and the upper or the lower side of the intended frame, whichever closer. \\
\hline
\end{tabular}
\caption{The factors of each rule and their parameters.}
\label{table:factors}
\end{table*}
Regards,
Rafid
Did you put \usepackage{multirow} at the beginning of your document?
There are probably good examples out there to follow. I've never used this package but in a short time (seconds) was able to find this PAGE via google. Does following along with that example help you?
Update: after seeing your actual table, I hate to say it but think your spacing glitch is due to the spill over in the "comments" column into multiple lines. I truncated your comments and got this (column 1 is now vertically centered as desired):
\begin{table*}\tiny
\centering
\begin{tabular}{|c|c|c|c|c|p{3cm}|}
\hline
Rule & Factor & Best Value & \Delta_t & \Delta_{do} & Comments \\
\hline
% Diagonal Dominance Rule
\multirow{3}{*}{Diagonal Dominance} & Line Angle & 45 & 15 & 30 & The angle between... \\
& Line Distance & 0 & 0.25 & 1 & The distance, in... \\
& Corner Distances & 0 & 0.1 & 0.7 & The distance, in... \\
\hline
% Framing Rule
\multirow{4}{*}{Framing} & Left Distance & 0 & ${Frame Width}*5\%$ & ${Frame Width}*25\%$ & The distance... \\
& Right Distance & 0 & ${Frame Width}*5\%$ & ${Frame Width}*25\%$ & The distance... \\
& Top Distance & 0 & ${Frame Height}*5\%$ & ${Frame Height}*25\%$ & The distance... \\
& Bottom Distance & 0 & ${Frame Height}*5\%$ & ${Frame Height}*25\%$ & The distance... \\
\hline
\end{tabular}
\caption{The factors of each rule and their parameters.}
\label{table:factors}
\end{table*}
Regarding the {l} argument, I think the link I posted originally is perhaps wrong. LaTeX spits out some errors for me when I try replacing * with l for the \multirow argument. I get this on a test table:
! Missing number, treated as zero.
<to be read again>
l
l.12 \multirow{4}{l}{Batch}
& MM & Min-Min \\
! Illegal unit of measure (pt inserted).
<to be read again>
l
l.12 \multirow{4}{l}{Batch}
& MM & Min-Min \\
After finding THIS, I think the second argument in \multirow is not for an alignment but for a width. The LyX wiki linked says the format is like so:
\multirow{number of rows}{cell width}{cell entry}
We've been assuming that {cell width} was actuall {alignment} and I think the link from earlier makes that confusing. See the note at the LyX wiki about spacing; you can use the following where needed to make it do your bidding:
\renewcommand{\multirowsetup}{\centering}
And replace \centering with \raggedleft or \raggedright where needed. I still think you're going to run into trouble with the multiple lines. I've at least shown that ditching them makes the spacing work as desired... how to force them to be centered with your default example is beyond me, I'm afraid. But perhaps now you know where the problem lies?
I guess if you really, really, really wanted to you could split your sentence up, figure out how many rows it takes, and adjust your \multirow argument accordingly for the increase in rows. Though you'd also probably need a nested multirow structure:
| | item 1, 2 rows | comment 1 line 1 |
| multirow, 4 rows | | comment 1 line 2 (spill over) |
| | item 2, 2 rows | comment 2 line 1 |
| | | comment 2 line 2 (spill over) |
Does that make sense? Column 1 would span all rows for its section, subsequent rows would span the number of rows required by the split up comments, and each line needed by the comments (some take up 3 or 4) would be on their own separate lines and just appear to be continuous. Not sure if the sentence spacing would look weird, though.
Nuff rambling. There's your food for thought.
One Last Update: One last hope way to go about this might be with TikZ tables. Essentially, your nodes are like "cells." Then just put them together and make it look like a table. Perhaps a horrible proposal, but I assure you that you'll have all the flexibility you need with cell spacing and such. Some ideas:
Fancy Tables 1
Fancy Tables 2
Periodic table in TikZ which might give you some insight about how to do this a bit better than the first two?
Wild guess: You're getting undefined control sequence: multirow because you're lacking a \usepackage{multirow} in the preamble?
Yes, you need the multirow package.
\usepackage{multirow}
\begin{document}
\begin{table}
\centering
\begin{tabular}{l||c|r}
Header 1 & Header 2 & Header 3 \\
\multirow{2}{*}{Hello} & stuff & stuff \\
& Body 2 & Body 3
\end{tabular}
\end{table}
\end{document}
EDIT after edits to question: I got two errors:
\multirow{4}{l}{Framing}. I changed to \multirow{4}{*}{Framing}
Delta_t changed to $Delta_t$.
Otherwise, everything seems fine. You may want to ask tex.stackexchange.com, too.

Resources