
我現在有以下程式碼 -
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (3,0);
\draw (1.5,0) circle (5pt) node{a};
\end{tikzpicture}
\end{document}
如果我們看到輸出,圓圈內有我不想要的線。另外我不想把線分成兩部分(即
\begin{tikzpicture}
\draw (0,0) -- (1.3,0);
\draw (1.7,0) -- (3,0);
\draw (1.5,0) circle (5pt) node{a};
\end{tikzpicture}
)
這段程式碼為我提供了完全符合我想要的輸出,但我不想手動進行計算並在整個圖片中繪製這麼多線條。如何有一個不透明的圓圈,但也有一些文字?
答案1
一種蠻力的方法是將圓圈填滿為白色。為了縮短程式碼,將圓繪製為節點並將其放在路徑的中間。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- node[circle,minimum size=10pt,inner sep=0pt,fill=white,draw]{a} (3,0);
\end{tikzpicture}
\end{document}
如果你不想用白色覆蓋任何東西,你仍然可以用一種方法來完成,
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\path (0,0) -- node[circle,minimum size=10pt,inner sep=0pt,draw](a){a} (3,0)
(a) edge (0,0) edge (3,0);
\end{tikzpicture}
\end{document}