TikZ 中的水平对齐节点

TikZ 中的水平对齐节点

下面的第一张图片看起来比右边的要好一点,但我不得不使用幻影将 H 和 I 与它们上方的线对齐。我还用 强制留出了一些垂直空间\\[0.2em]

这两种解决方案似乎都很老套。我应该怎么做呢?

图表

\documentclass[tikz]{standalone}

\usepackage{chemformula}

\begin{document}

\begin{tikzpicture}[very thick, scale=0.9]
\draw[|-|]  (0,0) node[below, align=center] {\\[0.2em]\ch{\phantom{2}H2}} node[left] {$E_0$} --  (0,3) node[left] {$E_1$};
\draw[|-|]  (1,0) node[below, align=center] {\\[0.2em]\ch{\phantom{2}I2}} node[right] {$E_0$} --  (1,1.5) node[right] {$E_1$};

\begin{scope}[xshift=3 cm]

\draw[|-|]  (0,0) node[below, align=center] {\\[0.2em]\ch{H2}} node[left] {$E_0$} --  (0,3) node[left] {$E_1$};
\draw[|-|]  (1,0) node[below, align=center] {\\[0.2em]\ch{I2}} node[right] {$E_0$} --  (1,1.5) node[right] {$E_1$};
\end{scope}
\end{tikzpicture}

\end{document}

答案1

\documentclass[tikz]{standalone}
\usepackage{chemformula}

\begin{document}
\begin{tikzpicture}[very thick, scale=0.9]
\draw[|-|]  (0,0) node[below=.2em] {\ch{H\rlap{2}}} node[left] {$E_0$} --  (0,3) node[left] {$E_1$};
\draw[|-|]  (1,0) node[below=.2em] {\ch{I\rlap{2}}} node[right] {$E_0$} --  (1,1.5) node[right] {$E_1$};
\end{tikzpicture}
\end{document}

演示

相关内容