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}
Related
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 want to create a table with (at least) 6 columns. Right now, I automatically get a line break after 4 columns and i don't know how to avoid it.
I thought I'd already have my solution with /resizebox, but obviously it doesn't change anything.
\begin{table}[htb]
\caption{Evaluationstabelle}
\resizebox{\textwidth}{!}{%
\begin{tabular}{cccc}\toprule
\textbf{Anzahl Features} &\textbf{Entfernte Features} &\textbf{Filter} &\textbf{Precision} &\textbf{Recall} &\textbf{F-Score} \\
\midrule
08.05. & Ausarbeitung & Formuliere & Bsp & ok & shit \\[20pt]
\bottomrule
\end{tabular}
}
\end{table}
This is how it looks right now:
But I'd want all Columns in one line. If it doesn't fit, maybe by reducing the font size or something.
Whatever you do, don't use \resizebox for elements that contain text, see https://tex.stackexchange.com/questions/425453/why-not-scale-elements-that-contain-text for more details.
One possibility would be to use a tabularx and let latex decide on the best columns widths and linebreaks. In case this is not enough to fit your table in your available textwidth, this can be combined with a smaller font (commented in the code below)
\documentclass{article}
\usepackage{caption}
\usepackage{geometry}
\usepackage{array}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{makecell}
\renewcommand\theadfont{\normalfont\bfseries}
\renewcommand\theadalign{YY}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}[htbp]
\caption{Evaluationstabelle}
%\small
\begin{tabularx}{\linewidth}{#{}YYYYYY#{}}
\toprule
\thead{Anzahl Features} & \thead{Entfernte Features} &\thead{Filter} &\thead{Precision} & \thead{Recall} & \thead{F-Score}\\
\midrule
08.05. & Ausarbeitung & Formuliere & Bsp & ok & test\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
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}
I just started to learn latex and now I'm trying to create a table. This is my code:
\begin{table}
\caption{Top Scorers}
\begin{tabular}{ l l }
\hline
\bf Goals & \bf Players\\
\hline
4 & First Last, First Last, First Last, First Last\\
3 & First Last\\
2 & First Last\\
1 & First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last\\
\hline
\end{tabular}
\end{table}
The problem is that the table is wider than the page. I was hoping that it would automatically fit to the page like normal text does, but it didn't. How do I tell latex to make the table fit to the page?
Use p{width} column specifier: e.g. \begin{tabular}{ l p{10cm} } will put column's content into 10cm-wide parbox, and the text will be properly broken to several lines, like in normal paragraph.
You can also use tabular* environment to specify width for the entire table.
You have to take whole columns under resizebox. This code worked for me
\begin{table}[htbp]
\caption{Sample Table.}\label{tab1}
\resizebox{\columnwidth}{!}{\begin{tabular}{|l|l|l|l|l|}
\hline
URL & First Time Visit & Last Time Visit & URL Counts & Value\\
\hline
https://web.facebook.com/ & 1521241972 & 1522351859 & 177 & 56640\\
http://localhost/phpmyadmin/ & 1518413861 & 1522075694 & 24 & 39312\\
https://mail.google.com/mail/u/ & 1516596003 & 1522352010 & 36 & 33264\\
https://github.com/shawon100& 1517215489 & 1522352266 & 37 & 27528\\
https://www.youtube.com/ & 1517229227 & 1521978502 & 24 & 14792\\
\hline
\end{tabular}}
\end{table}
You can use these options as well, either use \footnotesize or \tiny. This would really help in fitting big tables.
\begin{table}[htbp]
\footnotesize
\caption{Information on making the table size small}
\label{table:table1}
\begin{tabular}{ll}
\toprule
S.No & HMD \\
\midrule
1 & HTC Vive \\
2 & HTC Vive Pro \\
\bottomrule
\end{tabular}
\end{table}
I have two very short and consecutive sections (for a CV), each containing a small table:
\section{Work Experience}
\begin{tabular}{r|p{11cm}}
Current & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\multicolumn{2}{c}{}\
\end{tabular}
\section{Education}
\begin{tabular}{r|p{11cm}}
Slightly wider first column & University, Town \\
Jan 2009 & Thesis subject \\
& A description of what you did\\
\multicolumn{2}{c}{}\
\end{tabular}
So each table has two columns: The first containing the period, aligned to the right. The second: some more info with a certain width, top (and left) aligned.
The problem is that the width of the left column in the two tables is different, and doesn't look nice since the sections (therefore tables) are consecutive and in one page. I cannot give r a width like p:
\begin{tabular}{r{11cm}|p{11cm}}
Does not work. How can I get the widths of the first columns of the two tables the same length while also having them right aligned?
EDIT Thanks for the answers, they all work for me so I upvoted all of them, and accepted the one that appealed to me the most (and most upvoted), since you don't have to specify the \hfill in each row. However if you don't want to use the array package for any reason then the other solutions are also great.
If you use the array package, you can put the \hfill in the header as follows, so you don't have to remember to put it (or a \parbox) in each row.
\documentclass{article}
\usepackage{multicol}
\usepackage{array}
\begin{document}
\section{Work Experience}
\begin{tabular}{>{\hfill}p{5cm}|p{11cm}}
Current & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\multicolumn{2}{c}{}
\end{tabular}
\section{Education}
\begin{tabular}{>{\hfill}p{5cm}|p{11cm}}
Slightly wider first column & University, Town \\
Jan 2009 & Thesis subject \\
& A description of what you did\\
\multicolumn{2}{c}{}
\end{tabular}
\end{document}
to give:
alt text http://www.freeimagehosting.net/uploads/5e29f675e3.jpg
Here's a variant of #RTBarnard's answer using the tabularx package:
\documentclass[a4paper,twoside,draft,12pt]{article}
\usepackage{tabularx}
\begin{document}
\section{Work Experience}
\begin{tabularx}{\textwidth}{>{\raggedleft}X|p{8cm}}
Current & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\end{tabularx}
\section{Education}
\begin{tabularx}{\textwidth}{>{\raggedleft}X|p{8cm}}
Somewhat wider than first column,
overflowing into additional lines & University, Town \\
Jan 2009 & Thesis subject \\
& A description of what you did\\
\end{tabularx}
\end{document}
Notes:
Why tabularx? Because it's often
easier to know the width you have
available for the whole table, and
to let TeX calculate the unknown
column widths.
The first parameter is the overall table width. Here, I've specified \textwidth to fill the width of typeblock, but you can change that to whatever measure you need.
I've used \raggedright rather than \hfill: if the item flows onto a second line, \hfill will only right-align the first line of the paragraph.
Was the \multicol significant? I've removed it to keep the answer as simple as possible.
Run with XeTeX under TeXLive.
Here's one solution of many possibilities:
\begin{tabular}{r|p{11cm}}
\parbox{11cm}{\hfill Current} & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\multicolumn{2}{c}{}\
\end{tabular}
Basically, create a \parbox with the desired width and put an \hfill at the left.
You can give both p{width} options, and start each cell in the left with an \hfill.
You can use array package to specify a fill command for each row in your first column:
\begin{tabular}{>{\hfill}p{11cm}|p{11cm}|}
For example:
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{>{\hfill}p{5cm}|p{11cm}|}
This is a test & test
\end{tabular}
\begin{tabular}{>{\hfill}p{5cm}|p{11cm}|}
Test & this is a test
\end{tabular}
\end{document}