I am new to latex, and I am trying to create a table, but the content in the table cell is quite long, so I decided to create a new line for the cells.
But I am not sure how to do that, could someone help me on that? Here is my code:
\begin{table}[h!]
\caption{Multirow table}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
Observation(Species name) & Likelihood (Limnodynastes peronii Distribution Model) &Likelihood (Rhinella marina Distribution Model)\\
\hline
Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
\hline
Observation 2 (Rhinella marina) &0.30 &0.013 \\
\hline
\end{tabular}
\end{center}
\end{table}
Here is a fix I made up. The command wraps information in a parbox with a little extra spacing above and below the text to make it look nice. This allows you to limit the width of a cell as well as enter manual line breaks.
\begin{table}[h!]
\caption{Multirow table}
\newcommand{\wrap}[1]{\parbox{.33\linewidth}{\vspace{1.5mm}#1\vspace{1mm}}}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
\wrap{Observation\\ (Species name)} &\wrap{Likelihood\\ (Limnodynastes peronii Distribution Model)} &\wrap{Likelihood\\ (Rhinella marina\\ Distribution Model)}\\
\hline
\wrap{Observation 1\\ (Limnodynastes peronii)} &0.0712 &0.2699\\
\hline
\wrap{Observation 2\\ (Rhinella marina)}&0.30 &0.013 \\
\hline
\end{tabular}
\end{center}
\end{table}
Hope this helps- this is my first answer on stackoverflow!
Related
Can anyone give an idea on how to make this table?
Use \begin{table} [...] \end{table}
Here is a minimal working example:
\begin{table}
\centering
\begin{tabular}{l r}
& 119 Responses\\
Field & Percentage \\
\hline
Very convenient & 63\% \\
Sowewhat convenient & 28\% \\
Neutral & 5\% \\
Somewhat inconvenient & 2\% \\
Very inconvenient & 3\% \\
\end{tabular}
\end{table}
\end{document}
It looks like this:
I have a table need to write in latex, then I need to use the following code to make a table.
\begin{table}[]
\begin{tabular}{|l|r|}
\hline
\textbf{Item} & \textbf{Amount} \\ \hline
User Account & 15,763 \\ \hline
Original Post & 56,797 \\ \hline
Post Reply & 1,515,618 \\ \hline
Post (Original+Reply) & 1,572,415 \\ \hline
Adopted Post & 88,240 \\ \hline
\end{tabular}
\end{table}
However, it cannot set a specific width. When I want to write \begin{tabular}{|l{3.8}|r{3.8}|}, it does not work.
If I use p{3.8cm}, it does work. However, it does not keep right but left.
I want to make a specific width from the table and set it to keep right instead of the left.
Can anyone help me? Thanks!!
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{table}[]
\begin{tabular}{|l|>{\raggedleft\arraybackslash}p{3.8cm}|}
\hline
\textbf{Item} & \textbf{Amount} \\ \hline
User Account & 15,763 \\ \hline
Original Post & 56,797 \\ \hline
Post Reply & 1,515,618 \\ \hline
Post (Original+Reply) & 1,572,415 \\ \hline
Adopted Post & 88,240 \\ \hline
\end{tabular}
\end{table}
\end{document}
I'm trying to make a latex table, and I want to insert a string of the form word/anotherword/athirdword/afourthword/andsoon. This doesn't work though, as it will overflow instead of wrapping to the next line. If I just remove all the "/" characters, it works well. Below are some examples:
Correctly working word wrap without "/":
\begin{center}
\begin{tabular}{ |p{10em}|p{10em}|p{10em}| }
\hline
a wordanotherwordathirdwordafourthwordandsoon &
Next column &
Third column \\
\hline
\end{tabular}
\end{center}
Overflowing with "/":
\begin{center}
\begin{tabular}{ |p{10em}|p{10em}|p{10em}| }
\hline
a word/anotherword/athirdword/afourthword/andsoon &
Next column &
Third column \\
\hline
\end{tabular}
\end{center}
Another oddity, if I remove the first word "a" from the cell, the word overflows no matter what.
I tried to search SO for help, but the closest I was this SO post, which doesn't really address my problem.
EDIT: Here is the minimal reprex I mention in the comment:
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{Title}
\author{}
\date{}
\begin{document}
\maketitle
\begin{center}
\begin{tabular}{ |p{10em}|p{10em}|p{10em}| }
\hline
a wordanotherwordathirdwordafourthwordandsoon &
Next column &
Third column \\
\hline
\end{tabular}
\end{center}
\begin{center}
\begin{tabular}{ |p{10em}|p{10em}|p{10em}| }
\hline
a word/anotherword/athirdword/afourthword/andsoon &
Next column &
Third column \\
\hline
\end{tabular}
\end{center}
\end{document}
Hi all if anyone can help me. I am new to latex. I am trying to add table in my latex. I know the format but i don't know what I am doing wrong because my table is not in the form I want moreover it is giving me the error when I add caption.
I need some thing like this in the image
but I am getting this when I compile my latex code
Here is my code:
\begin{center}
\begin{tabular}[!ht]{||c c ||}
\caption{Dataset Specifications}
\centering \label{data}
\hline
Dataset & Samples \\ [0.5ex]
\hline\hline
Vovid & 349 \\
\hline
noncovid & 397 \\ [1ex]
\hline
\end{tabular}
\end{center}
My minimal code:
\documentclass{article}
\setlength{\tabcolsep}{1em}
\renewcommand{\arraystretch}{1.5}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{|c|c|}
\hline
Dataset & Samples \\
\hline
Covid & 349 \\
Non Covid & 397 \\
\hline
\end{tabular}
\caption{Dataset Specifications}
\label{tab:data}
\end{table}
\end{document}
and its output:
Please comment below here if any feature is missing or something is not clear to you :)
How about that:
\begin{table}[!ht]
\centering
\begin{tabular}{|c |c|}
\hline
Dataset & Samples \\ [0.5ex]
\hline
Vovid & 349 \\
noncovid & 397 \\ [1ex]
\hline
\end{tabular}
\caption{Dataset Specifications}
\label{tab:data}
\end{table}
So, the trick is 1) to pack the tabular in a table environment, 2) play with \hline and | to modify the lines around the table cells. More ways to polish tables in https://en.wikibooks.org/wiki/LaTeX/Tables
Ok so i wrote this simple code (shown below) to create an alternate colour table using \rowcolors, yet instead of just colouring the rows of the table it colours the whole row (even more than textwidth). Any help how to fix this?
begin{table}[ht]
\scriptsize
\begin{center}
\rowcolors{1}{lightgray}{white}
\caption{...}
\begin{tabular}{p{0.45\textwidth} | p{0.55\textwidth}}
Filename & Contents \\
\hline
\hline
A & B \\
C & F \\
\end{tabular}
\end{center}
\end{table}
While 0.45\textwidth + 0.55\textwidth would seem to fit within \textwidth, each of your p-columns have an extra column separation... on both sides. To that end, you should remove them in order to make it fit within the text block boundary:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{lipsum}
\begin{document}
\begin{table}[ht]
\scriptsize\centering
\rowcolors{1}{lightgray}{white}
\caption{This is a table.}
\begin{tabular}{
p{\dimexpr0.45\textwidth-2\tabcolsep} |
p{\dimexpr0.55\textwidth-2\tabcolsep}}
Filename & Contents \\
\hline
\hline
A & B \\
C & F
\end{tabular}
\end{table}
\lipsum[1]
\end{document}
Also, don't use the center environment; use \centering instead.