How can I make a list with itemize in a cell of table? - latex

I'm trying to make this table:
But I haven't found the possibility to include a list in a cell.

You can use itemize in all column types which allow linebreaks, e.g. in a p column of fixed with:
\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{tabular}{|l|p{3cm}|}
\hline
abc & \begin{itemize}[left=0pt,topsep=0pt]
\item abc
\item def
\end{itemize}\nointerlineskip\\
\hline
abc & abc\\
\hline
\end{tabular}
\end{document}

Related

How to remove the spacing in the itemize function in a table

I am trying to use the following code in the table using latex
\begin{table}[htb!]
\caption {Table}
\begin{center}
\small\setlength\tabcolsep{5.2pt}
\renewcommand{\arraystretch}{0.005}
\begin{tabular}{|p{0.14\textwidth}|p{0.14\textwidth}|p{0.14\textwidth}|}
\hline
\textbf{Text}& \textbf{Text} & \textbf{Text}\\
\hline
Text & \begin{itemize} \item{Text} \item {Text} \item \end{itemize} & Text \\
\hline
\hline
\end{tabular}
\label{tab1}
\end{center}
\end{table}
How to make the Text using the itemize to align to the left and remove the spacing between each bullet points as shown in the photo
How to remove or decrease the row spacing in the table
The following code should align the itemize text to the left and remove the spacing between bullet points:
\begin{itemize}[leftmargin=*, noitemsep, topsep=0pt]
\item Text
\item Text
\end{itemize}
To decrease the row spacing in the table, you can use the following command in the preamble:
\renewcommand{\arraystretch}{0.5}
Or you can adjust the number in the argument to set the desired row spacing.
You need to load enumitem to gain access to addition options. Then, either apply settings in-place for a specific list or clone itemize with additional settings.
In settings, you have to negate vertical spacing added by environments. But then, this messes up with the lists which you want to mix with a regular texts. So, one workaround is to clone itemize into two separate lists you use with or without surrounding text--you can still apply global settings common for two lists. Here's an example:
\documentclass{article}
\usepackage{array}
\usepackage{tabularx}
\usepackage{enumitem}
\newlist{tabitemize}{itemize}{1}
\newlist{soloitemize}{itemize}{1}
\setlist[tabitemize,soloitemize]{
nosep, nolistsep,
topsep=6pt,
align=left,
left=0pt,
label=$\bullet$,
}
\setlist*[soloitemize]{
before=\vspace{\dimexpr-6pt-\topsep},
after=\vspace{-10pt},
}
\begin{document}
Regular text with a regular itemize:
\begin{itemize}
\item Text
\item Text
\item X
\end{itemize}
\begin{table}[htb!]
\renewcommand*{\arraystretch}{1.25}
\caption {Table with custom itemize}
\begin{center}
\small\setlength\tabcolsep{5.2pt}
\begin{tabular}{|p{0.14\textwidth}|p{0.14\textwidth}|p{0.14\textwidth}|}
\hline
\textbf{Text} & \textbf{Text} & \textbf{Text}\\
\hline
Text & \begin{soloitemize}
\item Text
\item Text
\item Text
\item Text
\item X
\end{soloitemize} & Text text
\begin{tabitemize}
\item Text
\item X
\end{tabitemize}
Text \\
\hline
\hline
\end{tabular}
\label{tab1}
\end{center}
\end{table}
Regular text.
\end{document}

indentation in a latex tabular

I would like to know if it is possible to add indentation in a latex tabular.
Instead of indenting text, I would use two columns and merge them for cells which should start at the left:
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{Q[0.3cm]l}
\SetCell[c=2]{} Délits & \\
\SetCell[c=2]{} Circulation & \\
\SetCell[c=2]{} dont & \\
& conduit en état alcoolique\\
\end{tblr}
\end{document}

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}

Centering table in itemize environment

I would like to include a centered tabular inside an itemize environment item, is this possible? This is what I am working with, but I can't find a way to center the tabular. Paragraphs are not allowed inside items...
\documentclass{article}
\begin{document}
\begin{itemize}
\item Text before tabular
\newline
\begin{tabular}{ccc}
a & b & c \\
a & b & c \\
\end{tabular}
\newline
text after tabular
\item second item
\end{itemize}
\end{document}
Do you want the table centered relative to the other list contents or to the whole page?
For the whole page, what is wrong with the obvious solution:
\newenvironment{nscenter}
{\parskip=0pt\par\nopagebreak\centering}
{\par\noindent\ignorespacesafterend}
\begin{itemize}
\item Text before tabular
\begin{nscenter}
\begin{tabular}{ccc}
a & b & c \\
a & b & c \\
\end{tabular}
\end{nscenter}
text after tabular
\item second item
\end{itemize}
(with credit to this answer).
For centering relative to the other contents, this works:
\begin{itemize}
\item \begin{tabular}[t]{#{}l#{}}
Text before tabular\\
\multicolumn{1}{c}{
\begin{tabular}{ccc}
a & b & c \\
a & b & c \\
\end{tabular}}\\
Text after tabular\\
\end{tabular}
\item Second item
\end{itemize}
But I admit that it's not very pretty. Maybe someone else has a better solution?

rowcolors fill whole row and not just the table row

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.

Resources