Tabularx と欠落している項目の項目化

Tabularx と欠落している項目の項目化

私がこれをするとき:

\begin{tabularx}{\textwidth}{|p{5cm}|p{5cm}|} 
\toprule
\textbf{KPI} & \textbf{Description} \endhead 
\toprule
\rowcolor{darkgrey} \textbf{The percentage of health and safety trained managers and employees in the workplace}  & \begin{itemize}
\item The percentage of trained managers for occupational health and safety in the institute.
\item The percentage of trained employees for occupational health and safety in the institute.
\end{itemize}  \\ 
\midrule
 \textbf{Frequency of health and safety committee meetings}  & \begin{itemize}\item The number of health and safety committee short meetings per month.
 \item The number of health and safety committee general meetings per year. 
\end{itemize} \\ 
\midrule
\rowcolor{darkgrey} \textbf{Frequency of inspection} & \begin{itemize}

\item Number of inspections per year.
\item Frequency of observation of unsafe behaviors.
 \end{itemize} \\ 
\midrule
\textbf{Frequency of auditing} & 
\begin{itemize}
\item Number of health and safety management system auditing per year.
\end{itemize}   \\ 
\midrule
\rowcolor{darkgrey}  \textbf{Health and safety management team members commitments}  & 
\begin{itemize}
\item Number of deliverables per team member. 
\item Number of participants in the committee meetings.
\end{itemize}   \\ 
\midrule
\textbf{Number of precaution procedures} & 
\begin{itemize}
\item Frequency of early warnings.
\item Number of first aid kits and fire drills.
\item Number of trained employees for first aid kits and fire drills.
\end{itemize}  \\
\bottomrule
\end{tabularx}

分かりました

! LaTeX Error: Something's wrong--perhaps a missing \item.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \end{tabularx}

これをどう解決すればいいでしょうか?

\usepackage{booktabs,tabularx}

答え1

私は表のレイアウトを少し変えることを提案します。あなたの例からわかるように、1番目と2番目のテキストはカラム同じベースライン上にないため、タイポグラフィとして不適切と見なされます。また、シェーディングを使用する場合、垂直および水平の罫線はすべて不要です。また、 -\rowcolor罫線booktabsと - 罫線、またはbooktabs- 罫線と垂直の罫線が互換性がないため、白い線が散らばって表示されます。表がドキュメントの一部である場合、テキストは左余白と右余白に揃わず、あまり見栄えがよくありません。

リスト項目の上のスペースをキャンセルするコードは、David Carlisleのコードから引用したものです。この答え

これが私の提案です。ご興味があれば、さまざまな手順を説明できます。

ここに画像の説明を入力してください

\documentclass{article}
\usepackage{array,booktabs}
\usepackage[table]{xcolor}
\usepackage{enumitem}
\definecolor{darkgrey}{cmyk}{0,0,0,.15}
\usepackage{lmodern, microtype}

\newcolumntype{P}{p{\dimexpr(0.5\linewidth-1em-2\tabcolsep)}}
\newcolumntype{Z}{p{\dimexpr(2em-2\tabcolsep)}}
\newcommand{\listbox}[1]{\parbox[t]{\dimexpr(\linewidth-\tabcolsep)}{\mbox{}\vspace{-\normalbaselineskip\relax}\begin{itemize}[nosep, leftmargin=1em,]#1\end{itemize}}}

\newcommand{\rowspace}{\addlinespace[0.5\normalbaselineskip]}

\setlength{\arrayrulewidth}{3pt}

%%---------------- show page layout. don't use in a real document!
%\usepackage{showframe}
%\renewcommand\ShowFrameLinethickness{0.15pt}
%\renewcommand*\ShowFrameColor{\color{red}}
%%---------------------------------------------------------------%

\begin{document}

\setlength{\tabcolsep}{1pt}
\noindent\begin{tabular}{>{\bfseries}PZP} 

KPI && \textbf{Description} \\
\addlinespace[0.25\normalbaselineskip]\toprule
\arrayrulecolor{darkgrey}\hline
\rowcolor{darkgrey}
The percentage of health and safety trained managers and employees in the workplace  & &
\listbox{\item The percentage of trained managers for occupational health and safety in the institute
\item The percentage of trained employees for occupational health and safety in the institute} \par\\
\rowspace
 Frequency o health and safety committee meetings  &&
 \listbox{\item The number of health and safety committee short meetings per month
 \item The number of health and safety committee general meetings per year} \par\\ 

\arrayrulecolor{darkgrey}\hline
\rowcolor{darkgrey}Frequency of inspection & &
\listbox{\item Number of inspections per year
\item Frequency of observation of unsafe behaviors} \par\\
\arrayrulecolor{darkgrey}\hline
\rowspace
Frequency of auditing & &
\listbox{\item Number of health and safety management system auditing per year}   \par\\ 

\arrayrulecolor{darkgrey}\hline
\rowcolor{darkgrey}Health and safety management team members commitments  & &
\listbox{\item Number of deliverables per team member 
\item Number of participants in the committee meetings}   \par\\ 
\arrayrulecolor{darkgrey}\hline
\rowspace
Number of precaution procedures & &
\listbox{\item Frequency of early warnings
\item Number of first aid kits and fire drills
\item Number of trained employees for first aid kits and fire drills} \par\\
\bottomrule[2pt]
\end{tabular}
\end{document}

答え2

もう一つの解決策は...

  • enumitemテーブル内のパッケージetoolboxリストの使用はitemizeテーブル内での使用に対応しています
  • 表の水平線にはパッケージで定義された線が使用されboldlineます
  • リスト付きの列の場合は、新しい列タイプを定義しますI(以下のMWEを参照)。

編集:

  • セルの上部の垂直スペースはパッケージの使用によって、下部はテーブルcellspaceの設定によって実現されます。itemize
  • 使用されていないコードフラグメントを削除し、列の型定義を修正しました
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{ragged2e}
\usepackage{boldline,
            cellspace,
            tabularx}
\setlength\cellspacetoplimit{5pt}
\usepackage{enumitem}
\usepackage{etoolbox}
\AtBeginEnvironment{table}{%
    \setlist[itemize]{nosep,     % <-- new list setup
                      leftmargin=*,
                      label=\textbullet,%% <===
                      after=\vspace{-0.8\baselineskip} %% <===
                      }
                           }% end of AtBeginEnvironment
\newcolumntype{I}{>{\csname @minipagetrue\endcsname%
                  \RaggedRight\itemize}X<{\enditemize}
                    }

\begin{document}
    \begin{table}[ht]
    \rowcolors{1}{white}{gray!15}
\begin{tabularx}{\linewidth}{>{\bfseries\RaggedRight}S{p{48mm}} I}%% <===
    \hlineB{2}
KPI & \multicolumn{1}{>{\bfseries}l}{Description} \\
    \hlineB{1.5}
The percentage of health and safety trained managers and employees in the workplace 
    &    \item  The percentage of trained managers for occupational health and safety in the institute.
         \item  The percentage of trained employees for occupational health and safety in the institute.
         \\
Frequency of health and safety committee meetings
    &   \item The number of health and safety committee short meetings per month.
        \item The number of health and safety committee general meetings per year.
        \\
Frequency of inspection 
    &   \item Number of inspections per year.
        \item Frequency of observation of unsafe behaviors.
        \\
Frequency of auditing
    &   \item Number of health and safety management system auditing per year.
        \\
Health and safety management team members commitments 
    &   \item Number of deliverables per team member.
        \item Number of participants in the committee meetings.
        \\
Number of precaution procedures  
    &   \item Frequency of early warnings.
        \item Number of first aid kits and fire drills.
        \item Number of trained employees for first aid kits and fire drills.   
        \\
    \hlineB{2}
\end{tabularx}
    \end{table}
\end{document}

結果は次のとおりです:

ここに画像の説明を入力してください

答え3

\endheadを に変更し\\、必要なパッケージを追加すると (さらにXtabularx が「動作」するように列タイプを に変更すると)、このエラーは解消されます。

\documentclass{article}
\usepackage{tabularx,booktabs,colortbl}
%\usepackage{xcolor}
\definecolor{darkgrey}{cmyk}{0,0,0,.4}
\begin{document}
\begin{tabularx}{\textwidth}{|p{5cm}|X|} 
\toprule
\textbf{KPI} & \textbf{Description} \\
\toprule
\rowcolor{darkgrey} \textbf{The percentage of health and safety trained managers and employees in the workplace}  & \begin{itemize}
\item The percentage of trained managers for occupational health and safety in the institute.
\item The percentage of trained employees for occupational health and safety in the institute.
\end{itemize}  \\ 
\midrule
 \textbf{Frequency of health and safety committee meetings}  & \begin{itemize}\item The number of health and safety committee short meetings per month.
 \item The number of health and safety committee general meetings per year. 
\end{itemize} \\ 
\midrule
\rowcolor{darkgrey} \textbf{Frequency of inspection} & \begin{itemize}

\item Number of inspections per year.
\item Frequency of observation of unsafe behaviors.
 \end{itemize} \\ 
\midrule
\textbf{Frequency of auditing} & 
\begin{itemize}
\item Number of health and safety management system auditing per year.
\end{itemize}   \\ 
\midrule
\rowcolor{darkgrey}  \textbf{Health and safety management team members commitments}  & 
\begin{itemize}
\item Number of deliverables per team member. 
\item Number of participants in the committee meetings.
\end{itemize}   \\ 
\midrule
\textbf{Number of precaution procedures} & 
\begin{itemize}
\item Frequency of early warnings.
\item Number of first aid kits and fire drills.
\item Number of trained employees for first aid kits and fire drills.
\end{itemize}  \\
\bottomrule
\end{tabularx}
\end{document}

ここに画像の説明を入力してください

関連情報