文字在 tabularx 儲存格中未垂直對齊

文字在 tabularx 儲存格中未垂直對齊

我遇到了一個似乎無法找到解決方案的問題。我正在使用該包,tabularx因為我處理小頁面。我的表格混合了數字和文本,我希望該列垂直對齊。

在這裡,如果您檢查第 3 行或第 8 行,則所有列都未垂直對齊。請問您有垂直對齊它們的選項嗎?

\documentclass[10pt]{article}
\usepackage[paperheight=9.45in,paperwidth=6.69in,margin=0.5in,heightrounded]{geometry}
\synctex=1
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{xcolor}
\usepackage{tabularx,booktabs}
\usepackage{ghsystem}
\renewcommand\tabularxcolumn[1]{m{#1}}% for vertical centering text in X column
\begin{document}
\begin{center}
\begin{tabularx}{0.95\textwidth}{|X|c|c|c|c|}
\hline
    Nom & CAS & Masse Molaire & Utilisation & Dangers \\
\hline
    Anisole & 100-66-3 & 108.1 & {\color{orange} Synthèse} & \ghspic[scale=0.4]{exclam} \ghspic[scale=0.4]{flame}\\
\hline
    Chlorure d’aluminium anhydre & 7446-70-0 & 133.3 & {\color{orange} Synthèse} & \ghspic[scale=0.4]{acid} \\
\hline
    Chlorure de Fer anhydre & 7705-08-0 & 162.2 & {\color{orange} Synthèse} & \ghspic[scale=0.4]{acid} \ghspic[scale=0.4]{exclam}\\
\hline
    Chlorure d'isobutanoyle & 79-30-1 & 106.5 & {\color{orange} Synthèse} & \ghspic[scale=0.4]{acid} \ghspic[scale=0.4]{flame} \\
\hline
    Dichlorométhane sec & 75-30-2 & 84.9 & {\color{orange} Synthèse}, {\color{purple} Lavage} & \ghspic[scale=0.4]{exclam} \ghspic[scale=0.4]{health} \\
\hline
    Soude & 1310-73-2 & 40 & {\color{purple} Lavage} & \ghspic[scale=0.4]{acid} \\
\hline
    Solution de carbonate de potassium saturée & 584-08-7 & 138.2 & {\color{purple} Lavage} & \ghspic[scale=0.4]{exclam} \\
\hline
    Sulfate de sodium anhydre & 7757-82-6 & 142 & {\color{purple} Lavage} & // \\
\hline
    Acide chlorhydrique concentrée & 7647-01-0 & 36.5 & {\color{purple} Lavage} & \ghspic[scale=0.4]{acid} \ghspic[scale=0.4]{exclam} \\
\hline
    Solution saturée en chlorure d'ammonium & 12125-02-9 & 53.5 & {\color{purple} Lavage} & \ghspic[scale=0.4]{exclam}\\
\hline 
    Cyclohexane & 110-82-7 & 84.2 & {\color{brown} CCM} & \ghspic[scale=0.4]{exclam} \ghspic[scale=0.4]{flame} \ghspic[scale=0.4]{health} \ghspic[scale=0.4]{aqpol} \\
\hline
    Éther diéthylique & 60-29-7 & 74.12 & {\color{brown} CCM} & \ghspic[scale=0.4]{exclam} \ghspic[scale=0.4]{flame} \\
\hline
\end{tabularx}
\end{center}
\end{document}

結果如下:

例子

新結果

答案1

恐怕應該ghsystem更新,因為 TeX Live 2022(還有 2021)它試圖做到這一點

\chemmacros_load_module:n {nomenclature}

chemmacros在其最新版本中使用\chemmacros_module_load:n並且不再有nomenclature模組。

很好奇,因為這些包來自同一作者。 GitHub 站點上有一個問題報告

https://github.com/cgnieder/ghsystem/issues/13

無論如何,您想要降低最後一列中的圖形符號,使它們垂直居中。

\documentclass[10pt]{article}
\usepackage[paperheight=9.45in,paperwidth=6.69in,margin=0.5in,heightrounded]{geometry}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{xcolor}
\usepackage{tabularx,booktabs}

% fix the error in ghsystem if using TL 2021 or later
\ExplSyntaxOn
\cs_new_protected:Nn \chemmacros_load_module:n { }
\ExplSyntaxOff

\usepackage{ghsystem}
\usepackage{ragged2e}

\newcommand{\cghspic}[2][]{%
  \begingroup\renewcommand{\arraystretch}{0}%
  \begin{tabular}{@{}c@{}}\ghspic[#1]{#2}\end{tabular}%
  \endgroup
}

\begin{document}

\begin{center}
\renewcommand\tabularxcolumn[1]{>{\RaggedRight}m{#1}}% for vertical centering text in X column
\begin{tabularx}{0.95\textwidth}{|X|c|c|c|c|}
\hline
    Nom & CAS & Masse Molaire & Utilisation & Dangers \\
\hline
    Anisole & 100-66-3 & 108.1 & \textcolor{orange}{Synthèse} & \cghspic[scale=0.4]{exclam} \cghspic[scale=0.4]{flame}\\
\hline
    Chlorure d’aluminium anhydre & 7446-70-0 & 133.3 & \textcolor{orange}{Synthèse} & \cghspic[scale=0.4]{acid} \\
\hline
    Chlorure de Fer anhydre & 7705-08-0 & 162.2 & \textcolor{orange}{Synthèse} & \cghspic[scale=0.4]{acid} \cghspic[scale=0.4]{exclam}\\
\hline
    Chlorure d'isobutanoyle & 79-30-1 & 106.5 & \textcolor{orange}{Synthèse} & \cghspic[scale=0.4]{acid} \cghspic[scale=0.4]{flame} \\
\hline
    Dichlorométhane sec & 75-30-2 & 84.9 & \textcolor{orange}{Synthèse}, \textcolor{purple}{Lavage} & \cghspic[scale=0.4]{exclam} \cghspic[scale=0.4]{health} \\
\hline
    Soude & 1310-73-2 & 40 & \textcolor{purple}{Lavage} & \cghspic[scale=0.4]{acid} \\
\hline
    Solution de carbonate de potassium saturée & 584-08-7 & 138.2 & \textcolor{purple}{Lavage} & \cghspic[scale=0.4]{exclam} \\
\hline
    Sulfate de sodium anhydre & 7757-82-6 & 142 & \textcolor{purple}{Lavage} & // \\
\hline
    Acide chlorhydrique concentrée & 7647-01-0 & 36.5 & \textcolor{purple}{Lavage} & \cghspic[scale=0.4]{acid} \cghspic[scale=0.4]{exclam} \\
\hline
    Solution saturée en chlorure d'ammonium & 12125-02-9 & 53.5 & \textcolor{purple}{Lavage} & \cghspic[scale=0.4]{exclam}\\
\hline 
    Cyclohexane & 110-82-7 & 84.2 & \textcolor{brown}{CCM} & \cghspic[scale=0.4]{exclam} \cghspic[scale=0.4]{flame} \cghspic[scale=0.4]{health} \cghspic[scale=0.4]{aqpol} \\
\hline
    Éther diéthylique & 60-29-7 & 74.12 & \textcolor{brown}{CCM} & \cghspic[scale=0.4]{exclam} \cghspic[scale=0.4]{flame} \\
\hline
\end{tabularx}
\end{center}

\end{document}

我定義了一個\cghspic執行垂直居中的命令。

注意{\color{<color>} text}最好應該是

\textcolor{<color>}{text}

我相應地修改了程式碼。我還曾經\RaggedRight避免在第一列出現過寬的字間空格。

在此輸入影像描述

相關內容