在 tikz 線上畫一個不透明的圓圈(帶有一些文字)

在 tikz 線上畫一個不透明的圓圈(帶有一些文字)

我現在有以下程式碼 -

\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}

答案2

分兩部分畫線不需要手動計算其內部座標,但無法避免繪製更多線條:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\path (0,0) -- node (n) [circle,draw,minimum size=10pt,inner sep=0pt] {a} (3,0);
\draw (0,0) -- (n)  (n) -- (3,0);
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容