如何在乳胶中生成包含不一致列表/项目的表格?

如何在乳胶中生成包含不一致列表/项目的表格?

我想在 LaTeX 中生成此 5 列表格的前两行:

在此处输入图片描述

正如您所看到的,它是一种特殊类型的表,我们可以在其中看到:

  • 里面有逐项列表但不一致,即第 4 列所有行里面都有逐项列表,第 2、3 和 5 列在某些但不是所有行中有逐项列表,第 1 列根本没有逐项列表。
  • 表格的良好对齐
  • 糖果眼的外观就像是booktabs为哪个包创建的
  • 这是一张紧凑的桌子,没有不愉快的空间
  • 列表有方形项目符号

代码:

\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}

我找到的最接近的答案是这里,但不幸的是,这个答案假设所有行都有逐项列表,而不是其中一些,所以在将此帖子标记为重复之前,请注意这一点。

答案1

答案是将列表放在 minipage 或 parbox 中,但这并不好玩。这是enumitem使用beforeafter键以及命令的另一种解决方案\tablistcommand:当您有一个仅包含列表的单元格时使用tabitemize,并清除before列表前面带有文本的键。这些行正确对齐。

\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}

在此处输入图片描述


编辑

这确实取决于您的使用情况,但我可能会在文档中制作这样的表格。如果您的表格很长,旋转它会更有意义。

\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}

在此处输入图片描述

答案2

这是一个枚举项版本:

在此处输入图片描述

我已经定义了环境tableitems的一个变体,并在您的表中使用它。请注意,对于那些没有标题的列表,itemize使用笨拙的 hack是错误的。如果没有标题,列表周围就会有一行空行。\vspace

代码

    \documentclass{scrartcl}
    \usepackage{graphicx}
    \usepackage{booktabs}
    \usepackage{enumitem}
    \usepackage{lscape}
    \newlist{tableitems}{itemize}{1}
    \usepackage{mathabx}% for \sqbullet
    \setlist[tableitems]{nosep,
                         topsep=0pt,
                         partopsep=0pt,
                         leftmargin=1em,
                         label=$\sqbullet$
    }
    \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
              &\vspace{-1em}
              \begin{tableitems}
                 \item No primary barriers required
                 \item PPE
              \end{tableitems}
              & bench and sink required
            \\\midrule
            2 & \vspace{-1ex}
            \begin{tableitems}
             \item  Agents associated with human diseases
             \item Routes of transmission include per-cutaneous injury,
                    ingestion, mucous membrane exposure
            \end{tableitems}
            & BSL-1 practice plus:
            \begin{tableitems}
               \item limited access
               \item Biohazard warning signs
               \item ``Sharps'' precautions
               \item Biosafety manual defining any needed waste
               decontamination or medical surveillance polices
            \end{tableitems}
             & Primary barriers:
            \begin{tableitems}
               \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{tableitems}
             & BSL-1 plus:
            \begin{tableitems}
               \item Autoclave available
            \end{tableitems}
            \\
            \bottomrule
          \end{tabular}%
      \end{table}
    \end{landscape}
    \end{document}

答案3

虽然不完美,但是看看它是否有用:

\documentclass{scrartcl}
    \usepackage{graphicx}
    \usepackage{caption}
    \usepackage{booktabs,makecell,tabularx}
\renewcommand\theadfont{\bfseries\sffamily}
\newcommand{\textblacksquare}{\rule[.2ex]{0.8ex}{0.8ex}}
    \usepackage{paralist}
    \usepackage{ragged2e}
    \usepackage[margin=1in,showframe]{geometry}
    \usepackage{rotating}

\begin{document}
    \thispagestyle{empty}           % hide page number
\begin{sidewaystable}
    \centering
    \small\sffamily
    \caption{Wide Itemized Mixed Table}
    \label{tab:wide-item-tbl}
  \begin{tabularx}{\textheight}{c*{4}{>{\RaggedRight\arraybackslash}X}}
    \toprule
\thead{BSL} 
    &   \thead{Agents} 
        &   \thead{Practices} 
            &   \thead{Primary barriers} 
                &   \thead{Secondary barriers}  \\
    \midrule
1   &   Not known to consistently cause diseases in healthy adults 
        &   standard microbiological practices
            &   \vspace{-2ex}
                    \begin{compactitem}[\textblacksquare]
                \item   No primary barriers required,
                \item   PPE
                    \end{compactitem}
                &   Laboratora bench and sink required \\
    \midrule
2   &   \vspace{-2ex}
            \begin{compactitem}[\textblacksquare]
        \item Agents associated with human diseases
        \item Routes of transmission include per-cutaneous injury, ingestion, mucous membrane exposure
            \end{compactitem}
        &   BSL-1 practice plus:
                \begin{compactitem}[\textblacksquare]
            \item   limited access
            \item   Biohazard warning signs
            \item   ``Sharps'' precautions
            \item   Biosafety manual defining any needed waste decontamination or medical surveillance polices
                \end{compactitem}
            &   Primary barriers:
                    \begin{compactitem}[\textblacksquare]
                \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{compactitem}
                &   BSL-1 plus:
                        \begin{compactitem}[\textblacksquare]
                    \item Autoclave available
                        \end{compactitem}   \\
    \bottomrule
    \end{tabularx}
\end{sidewaystable}
\end{document}

landscape我使用了sidewaystable来自包的列表,而不是来自包的rotating列表。 您可以使用包(我不太熟悉)获得类似的结果。 对于表,我宁愿使用包,而对于格式化,我使用来自包的列表。compactitemparalistenumitemtabularx\RaggedRightragged2e

在此处输入图片描述

附录: 似乎所有三个答案的组合将提供最佳解决方案 :-)。 因此,我将以下内容组合起来

  • $\sqbullet$来自软件包mathabx,正如 Andrew 在他的回答中所建议的那样
  • enumitemArash Esbati在他的回答中使用包的方式
  • tabularxsidewaystableRaggedRight对齐文本,makecell用于我在答案中所建议的列标题。

这样,“通用”代码就变成:

\documentclass{scrartcl}

\usepackage{booktabs,makecell,tabularx}
\renewcommand\theadfont{\bfseries\sffamily}
\usepackage{ragged2e}
\usepackage[a4paper,margin=1in,showframe]{geometry}
\usepackage{rotating}
%    
\usepackage{mathabx}% for \sqbullet
\usepackage{enumitem}% for nice list
\newcommand{\tablistcommand}{% <-- for eliminating vertical space
                             %     before and after itemize
            \leavevmode\par\vspace{-\baselineskip}
                            }
\newlist{tableitems}{itemize}{1}% <-- defined new list
\setlist[tableitems]{nosep,     % <-- new list setup
                     topsep     = 0pt               ,
                     partopsep  = 0pt               ,
                     leftmargin = *                 ,
                     label      = $\sqbullet$       ,
                     before     = \tablistcommand   ,
                     after      = \tablistcommand
                     }

    \begin{document}
      \thispagestyle{empty}
%---------------------------------------------------------------%
\begin{sidewaystable}[h]%table
    \centering
    \small\sffamily
\caption{Wide Itemized Mixed Table}
    \label{tab:wide-item-tbl}
\begin{tabularx}{\textwidth}{c*{4}{>{\RaggedRight\arraybackslash}X}}
    \toprule
\thead{BSL}
    &   \thead{Agents}
        &   \thead{Practices}
            &   \thead{Primary barriers}
                &   \thead{Secondary barriers}  \\
    \midrule
1   &   Not known to consistently cause diseases in healthy adults
        &   standard microbiological practices
            &   \begin{tableitems}
                \item   No primary barriers required,
                \item   PPE
                \end{tableitems}
                &   Laboratory bench and sink required \\
    \midrule
2   &   \begin{tableitems}
        \item Agents associated with human diseases
        \item Routes of transmission include per-cutaneous injury, ingestion, mucous membrane exposure
        \end{tableitems}
        &   BSL-1 practice plus:
            \begin{tableitems}[before=]% <-- nullifying before skip
            \item   limited access
            \item   Biohazard warning signs
            \item   ``Sharps'' precautions
            \item   Biosafety manual defining any needed waste decontamination or medical surveillance polices
            \end{tableitems}
            &   Primary barriers:
                \begin{tableitems}[before=]% <-- nullifying before skip
                \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{tableitems}
                &   BSL-1 plus:
                    \begin{tableitems}[before=]% <-- nullifying before skip
                    \item Autoclave available
                    \end{tableitems}   \\
    \bottomrule
\end{tabularx}
\end{sidewaystable}%table
%---------------------------------------------------------------%
    \end{document}

表格如下所示:

在此处输入图片描述

相关内容