rowcolors fill whole row and not just the table row - latex

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.

Related

making latex table

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:

Wrapping multiple words concatenated with / symbols in latex tables

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}

How to center my text vertically in a table environment?

I have a table with 3 columns where the first 2 columns are pictures and the 3rd is my comment on those pictures, but the comment "drowns", it is down at the bottom of the cell.
I have tried with m{2cm} instead of c:
\begin{tabularx}{\textwidth}{c c m{2cm}}
but no change.
\begin{table}
\caption{Caption if needed}
\label{tab:lastcheck}
\begin{tabularx}{\textwidth}{c c c}
\textbf{O-Na} & \textbf{Na-Y} & \textbf{Comments} \\
\includegraphics[width=0.3\linewidth]{pic1.png} &
\includegraphics[width=0.3\linewidth]{pic2.png} &
My comments. \\
\end{tabularx}
\end{table}
My text is at the bottom of the cell.
The graphbox provides the handy align=c option to vertically centre images:
\documentclass{article}
\usepackage{tabularx}
\usepackage{array}
\usepackage{graphicx}
\usepackage{graphbox}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\begin{document}
\begin{table}
\caption{Caption if needed}
\label{tab:lastcheck}
\begin{tabularx}{\textwidth}{XXX}
\thead{O-Na} & \thead{Na-Y} & \thead{Comments} \\
\includegraphics[width=\linewidth,align=c]{example-image-duck} &
\includegraphics[width=\linewidth,align=c]{example-image-duck} &
My comments. \\
\end{tabularx}
\end{table}
\end{document}

Vertical align text to a box next to it

In the output below, I'm trying to align Author with the top of the box next to it. I've tried a couple of different boxes and whatnot, but I can't get it to align properly.
Here's the code:
\mbox{
Author
}
\fbox{\begin{minipage}[c]{12cm}
\medskip
$for(author)$
$author.name$\\$if(author.title)$\emph{$author.title$}\\$endif$$if(author.company)$$author.company$$endif$
\par\medskip
$endfor$
\medskip
\end{minipage}}
You should set the entire construction inside a tabular, and then also use a [t]op-aligned tabular for the framed box construction:
\documentclass{article}
\begin{document}
\begin{tabular}{l | l |}
\cline{2-2}
Author & \begin{tabular}[t]{#{}p{12cm}#{}}
Jack Appleseed \\
\emph{Marketing Manager} \\
Unimaginitive Solutions \\ \\
John Appleseed \\
\emph{Business Development Manager} \\
Unimaginitive Solutions \\
\end{tabular} \\
\cline{2-2}
\end{tabular}
\end{document}
I'm assuming you can use the following Pandoc construction (I haven't used Pandoc):
\begin{tabular}{l | l |}
\cline{2-2}
Author & \begin{tabular}[t]{#{}p{12cm}#{}}
$for(author)$
$author.name$ \\ $if(author.title)$\emph{$author.title$} \\ $endif$ $if(author.company)$ $author.company$ \\ $endif$
$endfor$
\end{tabular} \\
\cline{2-2}
\end{tabular}

How to create a new line in the table cell

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!

Resources