我正在設計一維勢井圖。我正在努力將標籤正確放置在右手線下方。我畫了一條看不見的線並將節點定位在末端。除此之外,如何為紅線之外的區域添加灰色陰影?
乾杯
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[-stealth] (-0.5,0) -- (pi,0) node[right]{\(x\)};
\draw[-stealth] (0,-0.5) -- (0,4) node[above]{\(V(x)\)};
\draw[thick, red, ->, >=stealth] (0,0) -- (0,3) node[left, blue]{\(\)};
\draw[thick, red,->, >=stealth] (2.5,0) -- (2.5,3);
% \node[draw] at (2.5,-0.2) node[right, black]{\(a\)};
\draw[line width=0pt] (0,0) -- (2.5,0) node[below, black]{\(a\)};
\end{tikzpicture}
\end{document}
答案1
像這樣
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\fill[gray!50] (-.5,-.5) rectangle (pi,4);
\fill[white] (0,0) rectangle (2.5,3);
\draw[-stealth] (-0.5,0) -- (pi,0) node[right]{\(x\)};
\draw[-stealth] (0,-0.5) -- (0,4) node[above]{\(V(x)\)};
\draw[thick, red, ->, >=stealth] (0,0) -- (0,3) node[left, blue]{\(x\)};
\draw[thick, red,->, >=stealth] (2.5,0) node[below,black] {$a$} -- (2.5,3);
\end{tikzpicture}
\end{document}
注意,如果你想畫一條看不見的線,你不應該使用line width=0pt
,因為它仍然大於零。改用\path
(其實\draw
和\path[draw]
是一樣的):
\path (0,0) -- (2.5,0) node[below, black]{\(a\)};