[Tex/LaTex] How to produce this table in latex with inconsistent lists/items

enumitemitemizemacrostablestabularx

I want to produce the first two rows of this 5-column table in LaTeX:

enter image description here

As you can see it is a special type of tables where we see:

  • itemized lists inside but inconsistently, ie. column 4 all rows have itemizes lists inside, columns 2,3, and 5 do have itemized lists in some but not all rows, column 1 has no itemized lists at all.
  • the nice alignment of the table
  • the candy-eye appearance like that what booktabspackage was created for
  • it is a compact table that contains no unpleasant spaces
  • the lists have square bullets

Code:

\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{array}
\usepackage{lscape}
\begin{document}
\begin{landscape}
  \thispagestyle{empty}           % hide page number
  \begin{table}
    \centering
    \setlength{\belowcaptionskip}{\abovecaptionskip}% Correct skip for caption on top
    \caption{Wide Itemized Mixed Table}
    \label{tab:wide-item-tbl}
      \begin{tabular}{lp{2in}p{2in}p{2in}p{2in}}
        \toprule
        \textbf{BSL} & \textbf{Agents} & \textbf{Practices} & \textbf{Primary barriers} & \textbf{Secondary barriers} \\
        \midrule
        1 & Not known to consistently cause diseases in healthy adults & standard microbiological practices & no primary barriers required, PPE & bench and sink required \\
        2 & - Agents associated with human diseases  - Routes of transmission include per-cutaneous injury, ingestion, mucous membrane exposure & BSL-1 practice plus: - limited access - Biohazard warning signs - ``Sharps'' precautions - Biosafety manual defining any needed waste decontamination or medical surveillance polices & Primary barriers: - BSCs or other physical containment devices used for all manipulations of agents that cause splashes or aerosols of infectious materials - PPE: Laboratory coats, gloves, face and eye protection, as needed & BSL-1 plus: - Autoclave available\\
        \bottomrule
      \end{tabular}%
  \end{table}
\end{landscape}
\end{document}

The nearest answer I found was here, but unfortunately this answer assumes that all rows have itemized list and not some of them, so please for your kind attention to this point before labeling this post as duplicate.

Best Answer

The answer would be to put the list inside a minipage or parbox, but that is not really fun. Here is another solution with enumitem using the before and after keys and the command \tablistcommand: Use tabitemize when you have a cell with a list only, and clear out the before key with text preceding the list. The lines are correctly aligned.

\documentclass[landscape]{scrartcl}
\usepackage{booktabs,array,enumitem,ragged2e}

\newcommand{\tablistcommand}{%
  \leavevmode\par\vspace{-\baselineskip}%
}

\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize]{%
  leftmargin = *               ,
  label      = \textbullet     ,
  nosep                        ,
  before     = \tablistcommand ,
  after      = \tablistcommand
}

\begin{document}
\thispagestyle{empty}
\begin{table}
  \centering
  \caption{Wide Itemized Mixed Table}
  \label{tab:wide-item-tbl}
  \begin{tabular}{@{}l*{4}{>{\RaggedRight}p{2in}}@{}}
    \toprule
    \textbf{BSL} & \textbf{Agents} & \textbf{Practices}
    & \textbf{Primary barriers} & \textbf{Secondary barriers} \\
    \midrule
    1 & Not known to consistently cause diseases in healthy adults
      & standard microbiological practices
      & \begin{tabitemize}
        \item no primary barriers required,
        \item  PPE
        \end{tabitemize}
      & bench and sink required \tabularnewline
    2 & \begin{tabitemize}
        \item Agents associated with human diseases
        \item Routes of transmission include per-cutaneous injury,
          ingestion, mucous membrane exposure
        \end{tabitemize}
      & BSL-1 practice plus:
        \begin{tabitemize}[before=]
        \item limited access
        \item Biohazard warning signs
        \item ``Sharps'' precautions
        \item Biosafety manual defining any needed waste
          decontamination or medical surveillance polices
        \end{tabitemize}
      & Primary barriers:
        \begin{tabitemize}[before=]
        \item BSCs or other physical containment devices used for all
          manipulations of agents that cause splashes or aerosols of
          infectious materials
        \item PPE: Laboratory coats, gloves, face and eye protection,
          as needed
        \end{tabitemize}
      & BSL-1 plus:
        \begin{tabitemize}[before=]
        \item Autoclave available
        \end{tabitemize}\tabularnewline
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

enter image description here


EDIT

It really depends on your use case, but I would probably make a table like this in a document. If you have a very long table, it would make more sense to rotate it.

\documentclass[a4paper]{article}
\usepackage{%
  booktabs,tabularx,enumitem,ragged2e,%
  caption,lipsum,showframe,geometry}

\captionsetup[table]{%
  format        = plain        ,
  font          = footnotesize ,
  labelfont     = bf           , 
  justification = centerlast   , 
  labelsep      = period       ,
  position      = top          ,
  aboveskip     = 5pt          ,
  belowskip     = 0pt
}

\newcommand{\tablistcommand}{%
  \leavevmode\par\vspace{-\baselineskip}%
}

\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize]{%
  leftmargin = *               ,
  label      = \textbullet     ,
  nosep                        ,
  before     = \tablistcommand ,
  after      = \tablistcommand
}

\begin{document}
\lipsum[1]

\begin{table}[!h]
  \caption{Wide Itemized Mixed Table}
  \label{tab:wide-item-tbl}
  \footnotesize
  \begin{tabularx}{\linewidth}{@{}l*{4}{>{\RaggedRight}X}@{}}
    \toprule
    \scriptsize BSL & \scriptsize Agents & \scriptsize Practices
    & \scriptsize Primary barriers & \scriptsize Secondary barriers \\
    \midrule
    1 & Not known to consistently cause diseases in healthy adults
      & standard microbiological practices
      & \begin{tabitemize}
        \item no primary barriers required,
        \item  PPE
        \end{tabitemize}
      & bench and sink required \tabularnewline\addlinespace
    2 & \begin{tabitemize}
        \item Agents associated with human diseases
        \item Routes of transmission include per-cutaneous injury,
          ingestion, mucous membrane exposure
        \end{tabitemize}
      & BSL-1 practice plus:
        \begin{tabitemize}[before=]
        \item limited access
        \item Biohazard warning signs
        \item ``Sharps'' precautions
        \item Biosafety manual defining any needed waste
          decontamination or medical surveillance polices
        \end{tabitemize}
      & Primary barriers:
        \begin{tabitemize}[before=]
        \item BSCs or other physical containment devices used for all
          manipulations of agents that cause splashes or aerosols of
          infectious materials
        \item PPE: Laboratory coats, gloves, face and eye protection,
          as needed
        \end{tabitemize}
      & BSL-1 plus:
        \begin{tabitemize}[before=]
        \item Autoclave available
        \end{tabitemize}\tabularnewline
    \bottomrule
  \end{tabularx}
\end{table}

\lipsum[1]
\end{document}

enter image description here

Related Question