我試著用 tikz 並排繪製一些結,給它們貼上標籤,但它不適用於我的程式碼。我使用的套件: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}
答案1
正如評論中所提到的,您的程式碼有幾個錯誤:沒有文件類、額外的\end{figure}
、濫用let
PGF 語法以及未能包含calc
所需的程式庫。 (你包括幾件事不是編譯範例所需的,但省略了幾個需要的。
也就是說,一旦這些錯誤被修復,這兩個數字的大小似乎也會類似地調整。事實上,它們看起來是一樣的。
我最好的猜測是,儘管出現了錯誤並產生了可預見的不需要的結果,但您仍在繼續編譯。即使是警告也不應該被簡單地忽視。錯誤需要修復。 TeX 告訴您出現問題並且它不知道該怎麼做。一般來說,如果你堅持的話,它會嘗試做一些事情,但這並不是為了產生預期的輸出。它的目的是可能為調試目的提供有用的信息。
\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}