如何在乳膠中產生具有不一致清單/項目的表格?

如何在乳膠中產生具有不一致清單/項目的表格?

我想用 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

答案是將清單放入小型頁面或 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並在您的表中使用它。請注意\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使用sidewaystablefrom packagerotating和 for list inside table compactitemfrom package paralist。您可以透過包包獲得類似的結果enumitem(我不太熟悉)。對於表,我寧願使用tabularx包,其中我使用包\RaggedRight中的格式進行格式化。ragged2e

在此輸入影像描述

附錄: 看來所有三個答案的組合將給出最佳解決方案:-)。所以我結合以下內容

  • $\sqbullet$來自mathabx安德魯在他的回答中建議的軟體包
  • enumitemArash Esbati在他的回答中使用 package 的方式
  • tabularxsidewaystable以及RaggedRight文字對齊,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}

這樣,表格如下:

在此輸入影像描述

相關內容