Tabularx e discriminar item faltante

Tabularx e discriminar item faltante

quando eu faço isso:

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

Eu entendi isso

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

Como posso resolver isso ? estou a usar

\usepackage{booktabs,tabularx}

Responder1

Sugiro um layout ligeiramente diferente da sua tabela. Como você pode ver no seu exemplo, o texto no primeiro e no segundocolunanão está na mesma linha de base, o que é considerado uma tipografia ruim. Além disso, todas as regras verticais e horizontais são desnecessárias quando você usa sombreamento. Além disso, você obtém linhas brancas espalhadas porque nem \rowcolorand booktabs-rules, nem booktabs-rules e regras verticais são compatíveis. Se o seu tabular fizer parte de um documento, o texto não ficará alinhado nas margens esquerda e direita, o que não é muito bonito.

O código para cancelar o espaço acima dos itens da lista é adaptado do código de David Carlisle emesta resposta.

Aqui está a minha sugestão e, se você estiver interessado, posso explicar as diferentes etapas.

insira a descrição da imagem aqui

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

Responder2

Mais uma solução possível...

  • com uso de enumiteme etoolboxlistas de pacotes itemizedentro de tabelas são adequadas para uso em tabelas
  • para regras horizontais na tabela são utilizadas linhas definidas no boldlinepacote
  • para coluna com listas é definir um novo tipo de coluna I(veja MWE abaixo)

Editar:

  • mais espaços verticais superiores nas células são obtidos usando o cellspacepacote e inferiores com configurações itemizena tabela
  • removidos não são usados ​​fragmentos de código e definições de tipo de coluna corrigidas
\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}

O resultado é:

insira a descrição da imagem aqui

Responder3

Ao alterar seu \endheadto \\e adicionar os pacotes necessários (além de alterar o tipo de coluna para Xpara permitir que o tabularx "funcione"), esse erro desapareceu:

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

insira a descrição da imagem aqui

informação relacionada