3

I need a custom label for my chemical structures and everything works fine but the label isn't centered. Does anyone know how to center the label?

\documentclass{minimal}
\usepackage{hyperref}

\makeatletter
\newcounter{chem}
\addtocounter{chem}{1}
\newcommand{\chemlabel}[1]{%
  \hypertarget{#1}{\textbf{\number\value{chem}}}
   \protected@write\@auxout{}{\string\newlabel {#1}
   {{\number\value{chem}}{\thepage}{\number\value{chem}}{#1}{}}}% 
  \refstepcounter{chem} 
}
\makeatother

\usepackage{chemfig}
\begin{document}

\chemname{\chemfig{*6(-=-=-=)}}{Benzen}
\chemname{\chemfig{*6(-=-=-=)}}{\chemlabel{str:benzen}}
\chemname{\chemfig{*6(-=-=-=)}}{\chemlabel{str:benzen1}}
\chemname{\chemfig{*6(-=-=-=)}}{\chemlabel{str:benzen2}}
\chemname{\chemfig{*6(-=-=-=)}}{\chemlabel{str:benzen3}}


\end{document} 

2

You need some % at the end of lines in your definition of \chemlabel otherwise the ends of lines appear as spaces:

\documentclass{article}
\usepackage{hyperref}

\makeatletter
\newcounter{chem}
\addtocounter{chem}{1}
\newcommand{\chemlabel}[1]{%
  \hypertarget{#1}{\textbf{\number\value{chem}}}% <<<<
   \protected@write\@auxout{}{\string\newlabel {#1}
   {{\number\value{chem}}{\thepage}{\number\value{chem}}{#1}{}}}% 
  \refstepcounter{chem}% <<<<
}
\makeatother

\usepackage{chemfig}
\begin{document}

\chemname{\chemfig{*6(-=-=-=)}}{Benzen}
\chemname{\chemfig{*6(-=-=-=)}}{\chemlabel{str:benzen}}
\chemname{\chemfig{*6(-=-=-=)}}{\chemlabel{str:benzen1}}
\chemname{\chemfig{*6(-=-=-=)}}{\chemlabel{str:benzen2}}
\chemname{\chemfig{*6(-=-=-=)}}{\chemlabel{str:benzen3}}


\end{document}

enter image description here

BTW: do you know chemnum?

  • Why simple when you can make it even hard. I didn't know the chemnum-package but thank you very much! – SLx64 Jun 16 '14 at 20:14

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.