7

How can I draw the following diagram using TikZ/PGF?

Enter image description here

I have been able to draw up to the following diagram:

Enter image description here

Using the following code:

\[
  \begin{tikzpicture}[node distance = 2cm, auto]
  \node (Q) {$\mathbb{Q}$};
  \node (E) [above of=Q, left of=Q] {$\mathbb{Q}(\sqrt{2})$};
  \node (E1) [above of=Q] {$\mathbb{Q}(\sqrt{6})$};
  \node (F) [above of=Q, right of=Q] {$\mathbb{Q}(\sqrt{3})$};
  \node (K) [above of=Q, node distance = 4cm] {$\mathbb{Q}(\sqrt{2}, \sqrt{3})$};
  \draw[-] (Q) to node {$2$} (E);
  \draw[-] (Q) to node [swap] {$2$} (F);
  \draw[-] (E) to node {$2$} (K);
  \draw[-] (F) to node [swap] {$2$} (K);
  \draw[-] (Q) to node [swap] {$2$} (E1);
  \draw[-] (E1) to node [swap] {$2$} (K);
  \end{tikzpicture}
\]

How can I extend this code to the above one?

12
  • 3
    Please provide a compilable minimal working example and not only a snippet of the code you use. Jan 24, 2022 at 13:38
  • 2
    It will probably be better to see it as a 4 by 4 matrix. I'd also use tikz-cd as it is made for this kind of stuff.
    – daleif
    Jan 24, 2022 at 13:43
  • @daleif, thanks for the idea. But my old latex editor does not accept tikz-cd
    – learner
    Jan 25, 2022 at 13:52
  • The editor has nothing to do with the packages. If you have tikz-cd installed you can use it no matter which editor. And if doing diagrams like this you should use it.
    – daleif
    Jan 25, 2022 at 13:57
  • 1
    Then miktex should just auto install tikz-cd if it is missing. And a proper updated TeXStudio should have syntax highlighting for it.
    – daleif
    Jan 25, 2022 at 14:16

3 Answers 3

6

Using the code you already have, you could simply do something like this (but since the code you provided does not exactly result in the image you posted, I don't know what you really want to achieve):

\documentclass[tikz, border=1mm]{standalone}
\usepackage{amssymb}

\begin{document}
 
\begin{tikzpicture}[node distance = 2cm, auto]
    \node (Q) {$\mathbb{Q}$};
    \node (E) [above of=Q, left of=Q] {$\mathbb{Q}(\sqrt{2})$};
    \node (E1) [above of=Q] {$\mathbb{Q}(\sqrt{6})$};
    \node (F) [above of=Q, right of=Q] {$\mathbb{Q}(\sqrt{3})$};
    \node (K) [above of=Q, node distance = 4cm] {$\mathbb{Q}(\sqrt{2}, \sqrt{3})$};

    \node (G) [right of=F] {\color{blue}$\mathbb{Q}(\sqrt{\gamma})$};

    \draw[-] (Q) to node {$2$} (E);
    \draw[-] (Q) to node {$2$} (F);
    \draw[-] (E) to node {$2$} (K);
    \draw[-] (F) to node {$2$} (K);
    \draw[-] (Q) to node {$2$} (E1);
    \draw[-] (E1) to node {$2$} (K);

    \draw[-] (Q) to node [swap] {$3$} (G);
    \draw[-] (G) to node [swap] {$2$} (K);
\end{tikzpicture}

\end{document}

enter image description here


Edit

In case you need the vertical offset of the nodes as well, you could achieve this by using a matrix, or (as noted in the comments) using tikz-cd:

\documentclass[tikz, border=1mm]{standalone}
\usetikzlibrary{matrix}
\usepackage{amssymb}

\begin{document}
 
\begin{tikzpicture}

    \matrix (m) [matrix of math nodes, row sep=2em, column sep=1em] {
      & \color{blue}\mathbb{Q}(\zeta, \sqrt[3]{2}) & & \\
      & \mathbb{Q}(\sqrt[3]{2}) & \mathbb{Q}(\zeta\sqrt[3]{2}) & \mathbb{Q}(\zeta^2\sqrt[3]{2}) \\
      \color{blue}\mathbb{Q}(\zeta) & & & \\
      & \color{blue}\mathbb{Q} & & \\
    };

    \begin{scope}[every node/.style={font=\footnotesize}]
        \draw (m-1-2) to node[left] {3} (m-3-1)
                      to node[below left] {2} (m-4-2);
        \draw (m-1-2) to node[right] {2} (m-2-2)
                      to node[right] {3} (m-4-2);
        \draw (m-1-2) to node[below left] {2} (m-2-3)
                      to node[right] {3} (m-4-2);
        \draw (m-1-2) to node[above right] {2} (m-2-4)
                      to node[below right] {3} (m-4-2);
    \end{scope}

\end{tikzpicture}

\end{document}

enter image description here

3
  • 1
    Yes, I also get the OP's image, but it differs a lot from the result they would like to have (not only regarding the offset). Therefore, it was not clear to me, whether they also wanted this offset or not. I just made a rough guess that they wanted to include another node at the right (or left) oft the diagram. Jan 24, 2022 at 14:24
  • I see. Well, in this case, daleifs comment about doing all this with a tikz-cd matrix is probably better. Jan 24, 2022 at 14:26
  • Thank you very much for your both codes. I really liked the first one that extend my original code
    – learner
    Jan 25, 2022 at 14:07
4

Instead of extending your code, I use plain TikZ. We even can write the one-liner code for the figure ^^

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{tikzpicture}
\path
(0,0) node (C) {$\mathbb{Q}(\sqrt[3]{2})$}
(2,0) node (R1) {$\mathbb{Q}(\zeta\sqrt[3]{2})$}
(4,0) node (R2) {$\mathbb{Q}(\zeta^2\sqrt[3]{2})$}
(0,1.5) node[blue] (A) {$\mathbb{Q}(\zeta,\sqrt[3]{2})$}
(0,-2) node[blue] (B) {$\mathbb{Q}$}
(-2,-1)  node[blue] (L) {$\mathbb{Q}(\zeta)$}
;
\draw[nodes={scale=.8}] (A)
to node[above]{$2$} (R2)
to node[below]{$3$} (B)
to node[below]{$2$} (L)
to node[left]{$3$} (A)
to node[below]{$2$} (R1)
to node[above]{$3$} (B)
to node[right]{$3$} (C)
to node[right]{$2$} (A)
;       
\end{tikzpicture}
\end{document}
1
  • Thank you very much for your nice answer. It worked nicely
    – learner
    Jan 25, 2022 at 14:05
3

For completeness, here is one made using tikz-cd

\documentclass[tikz,border=5mm]{standalone}
\usepackage{amsmath,amssymb,tikz-cd}
\usetikzlibrary{babel} % incase " is active
\begin{document}
\begin{tikzcd}
  &
  \mathbb{Q}(\sqrt[3]{2})
  \arrow[ddl,-,"3"']
  \arrow[d,-,"2"]
  \arrow[dr,-,"2"']
  \arrow[drr,-,"2"]
  &
  &
  \\
  &
  \mathbb{Q}(\sqrt[3]{2})
  \arrow[dd,-,"3"]
  &
  \mathbb{Q}(\zeta,\sqrt[3]{2})
  \arrow[ddl,-,"3"']
  &
  \mathbb{Q}(\zeta^2\sqrt[3]{2})
  \arrow[ddll,-,"3"]
  \\
  \mathbb{Q}(\zeta)
  \arrow[dr,-,"2"']
  &
  &
  &
  \\
  &
  \mathbb{Q}
  &
  &
  \\
\end{tikzcd}
\end{document}

enter image description here

1
  • Thank you for your answer. I really appreciate it
    – learner
    Jan 25, 2022 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .