对齐节点标签(TikZ)

对齐节点标签(TikZ)

我使用 TikZ 创建了这张图片。但是,如您所见,节点标签在水平方向上并不完全对齐,因为节点的高度不同(我假设是由于指数和索引)。有什么办法可以解决这个问题吗?当我在这里时:请随意批评和改进我的代码,我对 Latex 和 TikZ 还很陌生,所以有机会学习...

在此处输入图片描述

\documentclass{scrbook}
\usepackage{tikz-cd}
\usepackage{chemformula}

\begin{document}
\begin{figure}

\centering

\begin{tikzpicture}[y={(0,-1cm)}]
\def\s{3} % separation between nodes

\node[label=below:{\small Singulett-Sauerstoff}] (A) at (0,0) {\Large \ch{^{1}O_2}};
\node[label=below:{\small (Triplett-)Sauerstoff}] (B) at (0,\s) {\Large \ch{^{3}O_2}};
\node[label=below:{\small Superoxid}] (C) at (\s,\s) {\Large \ch{O_2^{-.}}};
\node[label=below:{\small Peroxynitrit}] (D) at (\s,0) {\Large \ch{ONOO-}};
\node[label=below:{\small Wasserstoffperoxid}] (E) at (2*\s,\s) {\Large \ch{H2O2}};
\node[label={[align=center,below]\\\\ \small Hydroxylradikal\\\small+ Hydroxidion}] (F) at (2*\s,2*\s) {\Large \ch{^{.}OH + ^{-}OH}};
\node (G) at (3*\s,2*\s) {\Large \ch{2 H2O}};

\draw [-Latex, thick, shorten >= 6mm, shorten <= 2mm] (B) -- (A);
\draw [-Latex, thick,shorten >= 6mm, shorten <= 2mm] (C) -- (D);
\draw [-Latex, thick,shorten >= 2mm, shorten <= 2mm] (B) -- (C) node[midway, above]{\ch{+ e^{-}}};
\draw [-Latex, thick,shorten >= 2mm, shorten <= 2mm] (C) -- (E);
\draw [-Latex, thick,shorten >= 2mm, shorten <= 6mm] (E) -- (F);
\draw [-Latex, thick,shorten >= 2mm, shorten <= 2mm] (F) -- (G);

\end{tikzpicture}
\end{figure}
\end{document}

答案1

仅限 chemfig

\documentclass{article}
\usepackage{chemfig}
\begin{document}
\schemestart
\chemname{\chemfig{^3O_2}}{\small (Triplett-)Sauerstoff}
\arrow[90]
\chemname{\chemfig{^1O_2}}{\small Singulett-Sauerstoff}
\arrow(@c1.mid east--.mid west){->[ + \chemfig{e^{-}}]}[,1.5]
\chemname{\chemfig{\charge{14:6pt=\.}{O}_2^{-}}}{\small Superoxid}
\arrow[90]
\chemname{\chemfig{ONOO^{-}}}{\small Peroxynitrit}
\arrow(@c3.mid east--.mid west){->}[,1.3]
\chemname{\chemfig{H_2O_2}}{\small Wasserstoffperoxid}
\arrow[-90]
\chemname{\subscheme{\chemfig{^{\phantom{-}}\charge{150=\.}{O}H} \+ \chemfig{^{-}OH}}}{\small Hydroxylradikal \\\small+ Hydroxidion}
\arrow(@c6.mid east--.mid west)
2 \chemfig{H_2O}
\schemestop
\end{document}

在此处输入图片描述

为了\chemname更好地对齐

\documentclass{article}
\usepackage{chemfig}
\begin{document}
\schemestart
\chemfig{^3O_2^{\vphantom{-}}}
\arrow{->[ + \chemfig{e^{-}}]}[,1.5]
\chemfig{^{\vphantom{3}}\charge{14:6pt=\.}{O}_2^{-}}
\arrow{->}[,1.3]
\chemfig{H_2O_2^{\vphantom{-}}}
\arrow(@c1--){0}[-90,0.1]
\mbox{\small\strut (Triplett-)Sauerstoff}
\arrow(@c2--){0}[-90,0.1]
\mbox{\small\strut Superoxid}
\arrow(@c3--){0}[-90,0.1]
\mbox{\small\strut Wasserstoffperoxid}
\arrow[-90,,,,shorten <=-4pt]
\subscheme{\chemfig{^{\phantom{-}}\charge{150=\.}{O}H_{\vphantom{2}}} \+{,,1pt} \chemfig{^{-}OH_{\vphantom{2}}}}
\arrow
\subscheme{2 \chemfig{H_2O^{\phantom{-}}}}
\arrow(@c7--){0}[-90,0.1]
\begin{tabular}{c}
\small Hydroxylradikal \\[-1pt]
\small + \\[-2pt]
\small Hydroxidion
\end{tabular}
\arrow(@c1--){}[90,,,,shorten >=-3pt]
\mbox{\small\strut Singulett-Sauerstoff}
\arrow{0}[90,0.1]
\chemfig{^1O_2}
\arrow(@c2--){}[90,,,,shorten >=-3pt]
\mbox{\small\strut Peroxynitrit}
\arrow{0}[90,0.1]
\chemfig{_{\vphantom{2}}ONOO^{-}}
\schemestop
\end{document}

在此处输入图片描述

答案2

我对你的代码做了一些小改动。

在此处输入图片描述

\documentclass[varwidth=\maxdimen]{standalone}
\usepackage{tikz}
\usepackage{chemformula}
\usepackage{makecell}

\begin{document}
    \begin{figure}
        
        \centering
        
        \begin{tikzpicture}[y={(0,-1cm)}]
            
            \tikzset{%
                every node/.style={font=\strut},
            }
            
            \def\s{3} % separation between nodes
            
            \node (A) at (0,0) {\Large \ch{^{1}O_2}}; 
            \node[below=5pt] at (A) {\small Singulett-Sauerstoff};
            \node (B) at (0,\s) {\Large \ch{^{3}O_2}};
            \node[below=5pt] at (B) {\small (Triplett-)Sauerstoff};
            \node (C) at (\s,\s) {\Large \ch{O_2^{-.}}};
            \node[below=5pt] at (C) {\small Superoxid};
            \node (D) at (\s,0) {\Large \ch{ONOO-}};
            \node[below=5pt] at (D) {\small Peroxynitrit};
            \node (E) at (2*\s,\s) {\Large \ch{H2O2}};
            \node[below=5pt] at (E) {\small Wasserstoffperoxid};
            \node (F) at (2*\s,2*\s) {\Large \ch{^{.}OH + ^{-}OH}};
            \node[below=5pt] at (F) {\small \makecell[c]{Hydroxylradikal \\ + \\ Hydroxidion}};
            \node (G) at (3*\s,2*\s) {\Large \ch{2 H2O}};
            
            \draw [-Latex, thick, shorten >= 6mm, shorten <= 2mm] (B) -- (A);
            \draw [-Latex, thick,shorten >= 6mm, shorten <= 2mm] (C) -- (D);
            \draw [-Latex, thick,shorten >= 2mm, shorten <= 2mm] (B) -- (C) node[midway, above]{\ch{+ e^{-}}};
            \draw [-Latex, thick,shorten >= 2mm, shorten <= 2mm] (C) -- (E);
            \draw [-Latex, thick,shorten >= 2mm, shorten <= 6mm] (E) -- (F);
            \draw [-Latex, thick,shorten >= 2mm, shorten <= 2mm] (F) -- (G);
            
        \end{tikzpicture}
    \end{figure}
\end{document}

font=\strut使得节点大小相等并\makecell可以用于更好的标签。

答案3

使用tikz-cdmakecellamsmath(在 旁边chemformula):

\documentclass[border=3.141592]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta}
\usepackage{makecell}
\usepackage{amsmath}
\usepackage{chemformula}

\begin{document}
    \begin{tikzcd}[sep=large, 
every arrow/.append style = {-{Straight Barb[scale=0.8]}, semithick},
 /tikz/font = \Large\linespread{0.76}\selectfont
                ]
\makecell[t]{\ch{^{1}O_2}\\ \text{\small Singulett-Sauerstoff}}
    &   \makecell[t]{\ch{ONOO-}\\   \text{\small Peroxynitrit}}  
        &   &   \\
\makecell[t]{\ch{^{3}O_2}\\ \text{\small (Triplett-) Sauerstoff}}
\ar[u]\ar[r,"+e^{-}"]
    &   \makecell[t]{\ch{O_2^{-.}}\\   \text{\small Superoxid}}
        \ar[u]  \ar[r]
        &   \makecell[t]{\ch{H2O2}\\   \text{\small Wasserstoffperoxid}}
            \ar[d]
            &   \\
     &   &  \makecell[t]{\ch{^{.}OH + ^{-}OH}\\
                          \text{\small Hydroxylradikal} + \\
                          \text{\small Hydroxidion}} 
            \ar[r]   
            &   2\ch{H2O}
   \end{tikzcd}
\end{document}

在此处输入图片描述

答案4

虽然可以为标签指定样式选项,但我更喜欢将它们设为单独的节点。此外,基锚点会与基线对齐,而不是与中心对齐。

\documentclass{standalone}
\usepackage{tikz-cd}
\usepackage{chemformula}

\begin{document}

\begin{tikzpicture}[y={(0,-1cm)}]
\def\s{3} % separation between nodes

\node (A) at (0,0) {\Large \ch{^{1}O_2}};
\node[below, inner sep=0pt] (AL) at (A.south) {\small Singulett-Sauerstoff};% first row align point
\node (B) at (0,\s) {\Large \ch{^{3}O_2}};
\node[below, inner sep=0pt] (BL) at (B.south) {\small (Triplett-)Sauerstoff};% second row align point
\node (C) at (\s,\s) {\Large \ch{O_2^{-.}}};
\node[anchor=base] at (BL.base -| C) {\small Superoxid};
\node (D) at (\s,0) {\Large \ch{ONOO-}};
\node[anchor=base] at (AL.base -| D) {\small Peroxynitrit};
\node (E) at (2*\s,\s) {\Large \ch{H2O2}};
\node[anchor=base] at (BL.base -| E) {\small Wasserstoffperoxid};
\node (F) at (2*\s,2*\s) {\Large \ch{^{.}OH + ^{-}OH}};
\node[below, inner sep=0pt, align=center] at (F.south) {\small Hydroxylradikal\\\small+ Hydroxidion};
\node (G) at (3*\s,2*\s) {\Large \ch{2 H2O}};

\draw [-Latex, thick, shorten >= 6mm, shorten <= 2mm] (B) -- (A);
\draw [-Latex, thick,shorten >= 6mm, shorten <= 2mm] (C) -- (D);
\draw [-Latex, thick,shorten >= 2mm, shorten <= 2mm] (B) -- (C) node[midway, above]{\ch{+ e^{-}}};
\draw [-Latex, thick,shorten >= 2mm, shorten <= 2mm] (C) -- (E);
\draw [-Latex, thick,shorten >= 2mm, shorten <= 6mm] (E) -- (F);
\draw [-Latex, thick,shorten >= 2mm, shorten <= 2mm] (F) -- (G);

\end{tikzpicture}
\end{document}

演示

相关内容