如何更改 TikZ 图表中的标签距离

如何更改 TikZ 图表中的标签距离

就 TikZ 而言,我完全是一个初学者,所以请原谅我的一些愚蠢行为。

我想用 TikZ 制作一个字段塔,但是内部标签和边缘的距离太大。我想减少这个距离。有没有一种简单的方法可以实现这一点,而不需要重写整个代码?我之前搜索过答案,但我发现的所有问题要么略有不同,要么答案变得非常复杂(至少对我来说)。

这是一个最小工作示例:

\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}                     % input encoding
\usepackage[T1]{fontenc}                        % use T1 fonts for font encoding
\usepackage{amsfonts}                           % math font
\usepackage{tikz}
\newcommand{\Fr}{\textbf{F}}
\newcommand{\F}{\mathbb{F}}
\begin{document}

\begin{center}
\begin{tikzpicture}[node distance = 2cm, auto]
      \node (F3)                                      {$\F_3$};
      \node (F33) [above of=F3,  left of=F3]          {$\F_{3^3}$};
      \node (F32) [above of=F3,  right of=F3]         {$\F_{3^2}$};
      \node (F36) [above of=F3,  node distance = 4cm] {$\F_{3^6}$};
      \node (F318)[above of=F33, node distance = 4cm] {$\F_{3^{18}}$};
      \node (F39) [above of=F33, left of=F33]         {$\F_{3^9}$};
      \draw[-] (F3)  to node        {3} (F33);
      \draw[-] (F3)  to node [swap] {2} (F32);
      \draw[-] (F32) to node [swap] {3} (F36);
      \draw[-] (F33) to node        {2} (F36);
      \draw[-] (F33) to node        {3} (F39);
      \draw[-] (F36) to node [swap] {3} (F318);
      \draw[-] (F39) to node        {2} (F318);
      \draw (F3)  to node [swap] {$\langle \Fr \rangle$}  (F33);
      \draw (F3)  to node        {$\langle \Fr \rangle$}  (F32);
      \draw (F32) to node        {$\langle \Fr^2 \rangle$}(F36);
      \draw (F33) to node [swap] {$\langle \Fr^3\rangle$} (F39);
      \draw (F33) to node [swap] {$\langle \Fr^3\rangle$} (F36);
      \draw (F36) to node        {$\langle \Fr^6\rangle$} (F318);
      \draw (F39) to node [swap] {$\langle \Fr^9\rangle$} (F318);
\end{tikzpicture}
\end{center}

\end{document}

答案1

笨拙的解决方案:

\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}                     % input encoding
\usepackage[T1]{fontenc}                        % use T1 fonts for font encoding
\usepackage{amsfonts}                           % math font
\usepackage{tikz}
\newcommand{\Fr}{\textbf{F}}
\newcommand{\F}{\mathbb{F}}

    \begin{document}
\begin{center}
    \begin{tikzpicture}[
node distance = 2cm, auto,
every node/.style = {inner sep=1pt,outer sep=0pt},
vrtc/.style = {inner sep=3pt}]
      \node (F3)  [vrtc]                                    {$\F_3$};
      \node (F33) [vrtc,above of=F3,  left of=F3]          {$\F_{3^3}$};
      \node (F32) [vrtc,above of=F3,  right of=F3]         {$\F_{3^2}$};
      \node (F36) [vrtc,above of=F3,  node distance = 4cm] {$\F_{3^6}$};
      \node (F318)[vrtc,above of=F33, node distance = 4cm] {$\F_{3^{18}}$};
      \node (F39) [vrtc,above of=F33, left of=F33]         {$\F_{3^9}$};
      \draw[-] (F3)  to node        {3} (F33);
      \draw[-] (F3)  to node [swap] {2} (F32);
      \draw[-] (F32) to node [swap] {3} (F36);
      \draw[-] (F33) to node        {2} (F36);
      \draw[-] (F33) to node        {3} (F39);
      \draw[-] (F36) to node [swap] {3} (F318);
      \draw[-] (F39) to node        {2} (F318);
      \draw (F3)  to node [swap] {$\langle \Fr \rangle$}  (F33);
      \draw (F3)  to node        {$\langle \Fr \rangle$}  (F32);
      \draw (F32) to node        {$\langle \Fr^2 \rangle$}(F36);
      \draw (F33) to node [swap] {$\langle \Fr^3\rangle$} (F39);
      \draw (F33) to node [swap] {$\langle \Fr^3\rangle$} (F36);
      \draw (F36) to node        {$\langle \Fr^6\rangle$} (F318);
      \draw (F39) to node [swap] {$\langle \Fr^9\rangle$} (F318);
\end{tikzpicture}
\end{center}
    \end{document}

在上面的代码中,我将所有节点的内部分离减少到 1pt 并定义节点vrtc,然后将其返回到 3pt。

在此处输入图片描述

相关内容