1

I am trying to draw some knots side by side with tikz, the label them, but it just doesn't work with my code. I use the package: caption, subcaption, tikz (knots).

\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{matrix, arrows, knots}
\usepackage{graphicx}

\begin{document}
  \begin{figure}
    \begin{subfigure}[b]{0.45\textwidth}
      \centering
        \resizebox{\linewidth}{!}{           
          \begin{tikzpicture}
            \foreach \brk in {0,1,2} {
            \begin{scope}[rotate=\brk * 120]
            \node[knot crossing, transform shape,
            inner sep=1.5pt] (k\brk) at (0,-1) {};
            \end{scope}
            }
            \foreach \brk in {0,1,2} {
            \pgfmathparse{int(Mod(\brk - 1,3))}
            \edef\brl{\pgfmathresult}
            \draw[thick,red] (k\brk) .. controls (
            k\brk.4 north west) and (k\brl.4 north east) .. (k\brl.center);
            \draw[thick,red] (k\brk.center) .. controls (k\brk.16 south west) and (k\brl.16 south east) .. (k\brl);
            }
        \end{tikzpicture}
      }
    \caption{Trefoil}
    \label{a}
   \end{subfigure}
   \begin{subfigure}[b]{0.45\textwidth}
      \centering
        \resizebox{\linewidth}{!}{ 
          \begin{tikzpicture}
            \def\foil{3}
            \foreach \brk in {1,...,\foil} {
            \begin{scope}[rotate=\brk * 360/\foil]
            \node[transform shape, knot crossing, inner sep=1.5pt] (k\brk) at (0,-1) {};
            \end{scope}
            }
            \draw[thick,red] (0,0) \foreach \brk in {1,...,\foil} {let \na=\brk, \nb={int(Mod(\brk,\foil)+1)}, \nc={int(Mod(\brk+1,\foil)+1)} in (k\na) .. controls (k\na.16 south east) and (k\nb.16 south west) .. (k\nb.center) .. controls (k\nb.4 north east) and (k\nc.4 north west) .. (k\nc)};
          \end{tikzpicture}
        }
        \caption{Cinquefoil}
        \label{b}
      \end{subfigure}
    \end{figure}
  \caption{Examples of knots} 
  \end{figure}
\end{document}
3
  • What is not working? Also, please include a compilable MWE. You are missing a k in front of \brk in controls (\brk.4 north west) and (k\brl.4 north east).
    – sodd
    Feb 16, 2016 at 14:19
  • Thanks for the correction. The second resizebox seems to work incorrectly.
    – Unknot
    Feb 16, 2016 at 14:54
  • 2
    Your code still contains several errors; no \documentclass, two \end{figure}. Also, replace \na, \nb and \nc with \n0, \n1 and \n2 respectively.
    – sodd
    Feb 16, 2016 at 15:10

1 Answer 1

2

As mentioned in comments, your code has several errors: no document class, an extra \end{figure}, misuse of the let PGF syntax and failure to include the calc library which that requires. (You include several things not required to get your example compiling, but omit several which are needed.)

That said, once those errors are fixed, the two figures seem to be resized similarly. Indeed, they appear identical.

My best guess is that you are continuing compilation despite errors with predictably unwanted results. Even warnings should not be simply ignored. Errors need fixing. TeX is telling you that things have gone wrong and it cannot figure out what to do. Generally, it will try to do something if you insist, but this is not aimed at producing the intended output. It is aimed at possibly providing useful information for debugging purposes.

knots

\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{knots,calc}
\begin{document}
\begin{figure}
  \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \resizebox{\linewidth}{!}{
      \begin{tikzpicture}
        \foreach \brk in {0,1,2} {
          \begin{scope}[rotate=\brk * 120]
            \node[knot crossing, transform shape,
            inner sep=1.5pt] (k\brk) at (0,-1) {};
          \end{scope}
        }
        \foreach \brk in {0,1,2} {
          \pgfmathparse{int(Mod(\brk - 1,3))}
          \edef\brl{\pgfmathresult}
          \draw[thick,red] (k\brk) .. controls (
          k\brk.4 north west) and (k\brl.4 north east) .. (k\brl.center);
          \draw[thick,red] (k\brk.center) .. controls (k\brk.16 south west) and (k\brl.16 south east) .. (k\brl);
        }
      \end{tikzpicture}
    }
    \caption{Trefoil}
    \label{a}
  \end{subfigure}
  \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \resizebox{\linewidth}{!}{
      \begin{tikzpicture}
        \def\foil{3}
        \foreach \brk in {1,...,\foil} {
          \begin{scope}[rotate=\brk * 360/\foil]
            \node[transform shape, knot crossing, inner sep=1.5pt] (k\brk) at (0,-1) {};
          \end{scope}
        }
        \draw[thick,red] (0,0) \foreach \brk in {1,...,\foil} {let \n0=\brk, \n1={int(Mod(\brk,\foil)+1)}, \n2={int(Mod(\brk+1,\foil)+1)} in (k\n0) .. controls (k\n0.16 south east) and (k\n1.16 south west) .. (k\n1.center) .. controls (k\n1.4 north east) and (k\n2.4 north west) .. (k\n2)};
      \end{tikzpicture}
    }
    \caption{Cinquefoil}
    \label{b}
  \end{subfigure}
\caption{Examples of knots}
\end{figure}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.