Tabularx und fehlende Elemente auflisten

Tabularx und fehlende Elemente auflisten

wenn ich das mache:

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

Ich verstehe das

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

wie kann ich das lösen? Ich verwende

\usepackage{booktabs,tabularx}

Antwort1

Ich schlage ein etwas anderes Layout Ihrer Tabelle vor. Wie Sie an Ihrem Beispiel sehen, ist der Text in der ersten und zweitenSpalteliegt nicht auf derselben Grundlinie, was als schlechte Typografie gilt. Außerdem sind alle vertikalen und horizontalen Linien unnötig, wenn Sie Schattierungen verwenden. Außerdem erhalten Sie verstreute weiße Linien, da weder \rowcolor-Regeln booktabsnoch booktabs-Regeln und vertikale Linien kompatibel sind. Wenn Ihre Tabelle Teil eines Dokuments ist, wird der Text am linken und rechten Rand nicht ausgerichtet, was nicht sehr schön ist.

Der Code zum Entfernen von Leerzeichen über Listenelementen wurde aus dem Code von David Carlisle indiese Antwort.

Hier ist mein Vorschlag. Wenn Sie interessiert sind, kann ich Ihnen die einzelnen Schritte erklären.

Bildbeschreibung hier eingeben

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

Antwort2

Noch eine mögliche Lösung ...

  • mit der Verwendung von enumitemund etoolboxPaketlisten itemizeinnerhalb von Tabellen sind für die Verwendung in Tabellen geeignet
  • für horizontale Linien in der Tabelle werden im boldlinePaket definierte Zeilen verwendet
  • für Spalten mit Listen wird ein neuer Spaltentyp definiert I(siehe MWE unten)

Bearbeiten:

  • mehr vertikale Abstände in Zellen werden durch die Verwendung des cellspacePakets und unten mit Einstellungen von itemizein der Tabelle erreicht
  • Entfernt werden nicht verwendete Codefragmente und korrigierte Spaltentypdefinitionen
\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}

Ergebnis ist:

Bildbeschreibung hier eingeben

Antwort3

Indem Sie Ihr \endheadin ändern \\und die benötigten Pakete hinzufügen (plus einen Spaltentyp in ändern, Xdamit tabularx „funktioniert“), ist dieser Fehler behoben:

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

Bildbeschreibung hier eingeben

verwandte Informationen