Annotated chemical equation

I saw a question on X/Twitter by @ritsudesu_yoro about drawing arrows and adding labels to chemical equation. @RARARARAICHUUU recommended doing it in TikZ, and I fully agree with this suggestion. So I wrote quickly some TikZ code to demonstrate how such drawings can be done.

This is the result:

Annotated chemical equation result

And this is the code:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{lmodern}
\usepackage{chemformula}
\usetikzlibrary{quotes,positioning,tikzmark}
\renewcommand*{\familydefault}{\sfdefault}
\newcommand*{\plus}{\texttt{+}}
\newcommand*{\minus}{\texttt{-}}
\newcommand*{\down}{3mm}
\begin{document}
\begin{tikzpicture}[remember picture, node distance = 1.8cm,
    every edge/.append style = {->, -stealth},
    every edge quotes/.append style
      = {font = \fontsize{4}{5}\selectfont},
    small/.style = {font = \fontsize{3}{4}\selectfont}, above]
  \node (O2) {\ch{\tikzmarknode{left}{O}2}};
  \node[right of = O2]  (H2O2) {\ch{H2\tikzmarknode{middle}{O}2}};
  \node[right of = H2O2] (H2O) {\ch{H2\tikzmarknode{right}{O}}};
  \node[small] at (left.north)          {0};
  \node[small] at (right.north) {\minus II};
  \node[small] at (middle.north) {\minus I};
  \coordinate[below = 2mm of  left] (1);
  \coordinate[below = 2mm of right] (2);
  \coordinate[below = \down of   2] (3);
  \draw (O2.east)   edge["{\plus 0,68\,V}"]    (H2O2.west)
        (H2O2.east) edge["{\plus 1,78\,V}"]     (H2O.west)
        (1) --++(0,-\down) to["{\plus 1,23\,V}" below] (3)
        (3) edge (2);
\end{tikzpicture}
\end{document}

You can click on “Run LaTeX here” to see the online compiled LaTeX output. You can zoom it to better see it.

How does it work? I

  • loaded the lmodern package so I can use the Latin Modern font to get very small font sizes for the labels
  • used \fontsize and \selectfont to get the labels in size smaller than \tiny
  • used the chemformula package for writing chemical formulas in upright font shape
  • chose \sfdefault to get sans serif fonts
  • defined plus and minus symbols in typewriter font, so they are smaller than normal plus and minus symbols
  • defined styles when things for repeated use
  • used the tikzmark library to mark positions within chemical formulas, specifically the O for oxygen
  • used relative positioning
  • defined coordinates 1, 2, 3 based on tikzmark coordinates for later drawin the big arrow
  • wrote a single \draw command to draw all arrows between the nodes
  • used edges with labels using the quotes library syntax
  • put the label text in braces {…} when there was a comma in the label, to protect from parsing

Learning TikZ is challenging but really rewarding. A good book can help learning the basics quickly, such as TikZによるLaTeXグラフィックス.