2

I've run into a problem that I can't seem to find a solution to. I am using the package tabularx since I work with small pages. My table has a mix of figures and text, and I would like the column to be vertically aligned.

Here if you check the 3rd line or the 8th line all the columns are not vertically aligned. Do you have some option to vertically align them please?

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

Here is the result:

Example

New result

5
  • 3
    Does this answer your question? Vertical centering of all columns in \tabularx environment (Basically, you need to execute \renewcommand\tabularxcolumn[1]{m{#1}} in the preamble.)
    – Mico
    Commented Mar 15, 2023 at 22:36
  • No, when I correct the example that i put here ,it's ok, but when I had it to my tabular, with the "pictures" (GHS sybol from ghsytem). the first coumn disappears and a new one (empty) appeared at the end of my table.
    – Juju
    Commented Mar 15, 2023 at 22:46
  • I edited the post to highlight the problem
    – Juju
    Commented Mar 15, 2023 at 22:53
  • 1
    Off topic: the first column would look nicer set ragged right. Commented Mar 15, 2023 at 23:18
  • My guess is that each line aligns perfectly with the baselines of the images in your last column. If so, you‘d need to lower them by e.g. using \raisebox, if I remember correctly.
    – MS-SPO
    Commented Mar 16, 2023 at 5:24

1 Answer 1

4

I'm afraid that ghsystem should be updated, because with TeX Live 2022 (but also 2021) it tries to do

\chemmacros_load_module:n {nomenclature}

but chemmacros in its most recent versions uses \chemmacros_module_load:n and there is no longer a nomenclature module.

Quite curious, as the packages are from the same author. And there's an issue report at the GitHub site

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

Anyway, you want to lower the graphic symbols in the last column, so they are vertically centered.

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

I defined a \cghspic command that does the vertical centering.

Note that {\color{<color>} text} should better be

\textcolor{<color>}{text}

and I amended the code accordingly. I also used \RaggedRight to avoid wide interword spaces in the first column.

enter image description here

3
  • Thanks for your answer and all your correction ! It's working on an isolated try, but when I implement it to the full paper, my first column disappears and A new one appear at the end (see the new photo in the post.
    – Juju
    Commented Mar 16, 2023 at 13:55
  • @Juju Sorry, but there must be something in your code that has the unwanted consequence.
    – egreg
    Commented Mar 16, 2023 at 14:24
  • thanks a lot, after checking the long list of package, and checking what could be the problem, it was the package makecell. Thanks again.
    – Juju
    Commented Mar 16, 2023 at 16:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .