10

I'm making a table of molecule structures and some information about them. A minimum working example looks like this:

\documentclass{article}
\usepackage[version=3]{mhchem}
\usepackage{chemfig}
\begin{document}

  \begin{tabular}{|c|c|p{2.5cm}|}
    \hline
    Compound & Structure & Hazard Protection \\ \hline
    Cyclopentadiene & \chemfig{*5(-=-=-)} & Irritant: Avoid skin contact, ingestion, inhalation, use under hood. Flammable: avoid sources of ignition \\ \hline
  \end{tabular}
\end{document}

Which looks like this (Dots added to mark area of interest):

with molecule

I am wondering how to remove the space (Marked with red dots) on the non-structure columns created by the structure column. Removing the structure will do this, resulting in: without molecule

But that of course results in me not having the molecule. Is there a way that I make the cells independent of one another so they are always aligned to their top most boarder regardless of if a larger object exists on their row?

8

In effect, you want to align a picture at top in a table. There has been a number of discussions on this, A, B, C, and D are only a few them.

Anyway, actually, your pictures created by \chemfig have their base-lines set at the bottom of the picture. This makes them placed in that unwanted manner.

You could use the \smash command to make your box zero height and depth. But that would have an adverse effect like this.

enter image description here

Another option could be to use the adjustbox package. But that would mean installing (and learning to use) a new package.

IMHO your best bet is to use the \vtop command.

\vtop{%
  \null
  \hbox{%
    <figure>%
  }%
}

So, you will want to enclose your \chemfig commands inside \vtop{\null\hbox{}}.

You can even create a macro \topchemfig to have the desired effect and use it for all your structure figures.

(Somewhat unrelated to the issue at hand, but perhaps you will want to use \raggedright in rightmost cell to have the text better formatted.)

So, your MWE becomes something like this,

\documentclass{article}
\usepackage[version=3]{mhchem}
\usepackage{chemfig}

\def\topchemfig#1{\vtop{\null\hbox{\chemfig{#1}}}}

\begin{document}

  \begin{tabular}{|c|c|p{2.5cm}|}
    \hline
    Compound & Structure & Hazard Protection \\ \hline
    Cyclopentadiene & \topchemfig{*5(-=-=-)} & \raggedright Irritant: Avoid skin contact, ingestion, inhalation, use under hood. Flammable: avoid sources of ignition \\ \hline
  \end{tabular}
\end{document}

And your structure becomes perfectly aligned.

enter image description here

7

This is a job for adjustbox and its valign=t feature that makes the box as high as a normal line.

I add also the version using booktabs commands and no vertical rules. In any case, the first column should be left aligned and the last one is better set as ragged right, because it's very narrow. You might also try \RaggedRight instead of \raggedright (requires the ragged2e package), that allows hyphenation and maybe better fills the lines.

\documentclass{article}

\usepackage{adjustbox,array,booktabs}

\usepackage[version=3]{mhchem}
\usepackage{chemfig}

\begin{document}

\begin{tabular}{|l|c|>{\raggedright\arraybackslash}p{2.5cm}|}
\hline
Compound & Structure & Hazard Protection \\
\hline
Cyclopentadiene &
  \adjustbox{valign=t}{\chemfig{*5(-=-=-)}} &
  Irritant: Avoid skin contact, ingestion, inhalation, use
  under hood. Flammable: avoid sources of ignition \\
\hline
\end{tabular}

\bigskip

\begin{tabular}{lc>{\raggedright\arraybackslash}p{2.5cm}}
\toprule
Compound & Structure & Hazard Protection \\
\midrule
Cyclopentadiene &
  \adjustbox{valign=t}{\chemfig{*5(-=-=-)}} &
  Irritant: Avoid skin contact, ingestion, inhalation, use
  under hood. Flammable: avoid sources of ignition \\
\bottomrule
\end{tabular}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.