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

Я предлагаю немного иную компоновку вашей таблицы. Как вы видите из вашего примера, текст в первом и второмстолбецне находится на одной базовой линии, что считается плохой типографикой. Кроме того, все вертикальные и горизонтальные линии не нужны, когда вы используете затенение. Кроме того, вы получаете белые линии, разбросанные вокруг, потому что ни \rowcolorи booktabs-правила, ни booktabs-правила и вертикальные линии несовместимы. Если ваша таблица является частью документа, текст не будет выровнен по левому и правому полю, не очень хорошо.

Код для отмены пробела над элементами списка адаптирован из кода Дэвида Карлайла вэтот ответ.

Вот мое предложение, и если вам интересно, я могу объяснить различные шаги.

введите описание изображения здесь

\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на \\и добавив необходимые пакеты (плюс изменив тип столбца на , Xчтобы tabularx «работал»), эта ошибка исчезла:

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

введите описание изображения здесь

Связанный контент