问题:
尝试使用空圆圈tikz
并在圆圈右侧添加文本。我无法找到解决这两个问题的正确命令。
最小工作示例(MWE):
\documentclass{article}
\usepackage{tikz, environ}
\usetikzlibrary{arrows.meta}
% --------------------------------------------------------------
% Scales tikzpicture to text width
% --------------------------------------------------------------
\makeatletter
\newsavebox{\measure@tikzpicture}
\NewEnviron{scaletikzpicturetowidth}[1]{%
\def\tikz@width{#1}%
\def\tikzscale{1}\begin{lrbox}{\measure@tikzpicture}%
\BODY
\end{lrbox}%
\pgfmathparse{#1/\wd\measure@tikzpicture}%
\edef\tikzscale{\pgfmathresult}%
\BODY
}
\makeatother
\begin{document}
\begin{scaletikzpicturetowidth}{\textwidth}
\begin{tikzpicture}[scale=\tikzscale, xscale=1.3]
\draw [thick] (0,0) -- (8,0);
\draw (0,-.2) -- (0, .2);
\draw (1,-.2) -- (1, .2);
\draw (2,-.2) -- (2, .2);
\draw (3,-.2) -- (3, .2);
\draw (4,-.2) -- (4, .2);
\draw (5,-.2) -- (5, .2);
\draw (6,-.2) -- (6, .2);
\draw (7,-.2) -- (7, .2);
\draw (8,-.2) -- (8, .2);
\draw[dashed, {Circle}-{Circle}] (0,-1) -- (4,-1);
\draw[dashed, {Circle}-{Circle}] (2,-1.75) -- (6,-1.75);
\draw[dashed, {Circle}-{Circle}] (2,-2.5) -- (4,-2.5);
\node[above] at (1,0.25){$-5$};
\node[above] at (2,0.25){$-4$};
\node[above] at (3,0.25){$-3$};
\node[above] at (4,0.25){$-2$};
\node[above] at (5,0.25){$-1$};
\node[above] at (6,0.25){$0$};
\node[above] at (7,0.25){$1$};
\node[align=right, below] at (7.5,-.4){Text here};
\end{tikzpicture}
\end{scaletikzpicturetowidth}
\end{document}
电流输出:
期望输出:
答案1
加载时您所做的一切都是正确的arrows.meta
(因为它取代了arrows
),您只需添加[open]
打开的圆圈和node[right]{...}
文本。当然,我不知道您想要哪些文本以及哪些圆圈应该是打开的,所以我添加了一些通用的东西并打开了 50% 的圆圈。
\documentclass{article}
\usepackage{tikz, environ}
\usetikzlibrary{arrows.meta}
% --------------------------------------------------------------
% Scales tikzpicture to text width
% --------------------------------------------------------------
\makeatletter
\newsavebox{\measure@tikzpicture}
\NewEnviron{scaletikzpicturetowidth}[1]{%
\def\tikz@width{#1}%
\def\tikzscale{1}\begin{lrbox}{\measure@tikzpicture}%
\BODY
\end{lrbox}%
\pgfmathparse{#1/\wd\measure@tikzpicture}%
\edef\tikzscale{\pgfmathresult}%
\BODY
}
\makeatother
\begin{document}
\begin{scaletikzpicturetowidth}{\textwidth}
\begin{tikzpicture}[scale=\tikzscale, xscale=1.3]
\draw [thick] (0,0) -- (8,0);
\draw (0,-.2) -- (0, .2);
\draw (1,-.2) -- (1, .2);
\draw (2,-.2) -- (2, .2);
\draw (3,-.2) -- (3, .2);
\draw (4,-.2) -- (4, .2);
\draw (5,-.2) -- (5, .2);
\draw (6,-.2) -- (6, .2);
\draw (7,-.2) -- (7, .2);
\draw (8,-.2) -- (8, .2);
\draw[dashed, {Circle}-{Circle[open]}] (0,-1) -- (4,-1) node[right]{abc};
\draw[dashed, {Circle}-{Circle[open]}] (2,-1.75) -- (6,-1.75)node[right]{xyz};
\draw[dashed, {Circle}-{Circle[open]}] (2,-2.5) -- (4,-2.5)node[right]{uvw};
\node[above] at (1,0.25){$-5$};
\node[above] at (2,0.25){$-4$};
\node[above] at (3,0.25){$-3$};
\node[above] at (4,0.25){$-2$};
\node[above] at (5,0.25){$-1$};
\node[above] at (6,0.25){$0$};
\node[above] at (7,0.25){$1$};
\node[align=right, below] at (7.5,-.4){Text here};
\end{tikzpicture}
\end{scaletikzpicturetowidth}
\end{document}