这是我的尝试:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations,decorations.markings,decorations.text,arrows.meta,backgrounds}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[decoration={
markings,% switch on markings
mark=% actually add a mark
between positions 0 and 1 step 1mm
with
{
\draw[black!50] (-2pt,-3pt) -- (2pt,3pt);
}
}]
\begin{scope}[on background layer]
\draw[-{Stealth[scale=1]}] (-.5,0) -- (9.5,0) ;
\foreach \x in {0,1,...,9}
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
\foreach \x in {0,1,...,9}
\draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] {$\x$};
\draw[{Straight Barb[scale=2]}-{Bracket[scale=2]}] (2,0)--(7,0);
\end{scope}
\draw [postaction={decorate}] (2,0)--(7,0);
\end{tikzpicture}
\end{document}
我怎样才能使斜线一直到达间隔边界但又不超过它?
答案1
您可以手动绘制箭头并将它们作为要用线条填充的区域的一部分,这些线条是通过图案实现的。
它看起来很乱——确实如此——但主界面是关键没有 @
它是左分隔符和右分隔符的组合,并且具有与箭头提示相同的语法。
它们各自接受一个参数:线条的角度(即图案角度)。分隔符为angle
和bracket
无。
numline area
可以调整样式numline delimiters
来改变外观。
代码
\documentclass[varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, patterns.meta}
\tikzset{
@numline/@l/.style 2 args ={insert path={ ([shift={(#1)}] up:4pt) coordinate (area_start) #2 ++(down:8pt)}},
@numline/@r/.style 2 args ={insert path={#2([shift={(#1)}]down:4pt) #2 ++(up:8pt)}},
@numline/@langle/.style 2 args ={insert path={ ([shift={(#1)}] 3pt, 4pt) coordinate (area_start) -- (#1) -- +( 3pt, -4pt)}},
@numline/@rangle/.style 2 args ={insert path={#2([shift={(#1)}] -3pt, -4pt) -- (#1) -- +(-3pt, 4pt)}},
@numline/@lbracket/.style 2 args={insert path={ ([shift={(#1)}] 2pt, 4pt) coordinate (area_start) -| (#1) |- +( 2pt, -4pt)}},
@numline/@rbracket/.style 2 args={insert path={#2([shift={(#1)}] -2pt, -4pt) -| (#1) |- +(-2pt, 4pt)}},
/utils/create to paths for combo/.style args={#1_#2}{
#1-#2/.style={to path={[insert path/.expanded={
edge[path only, numline area={##1}, @numline/@#1_#2=--](\tikztotarget)
edge[path only, numline delimiters, @numline/@#1_#2=] (\tikztotarget)}]}},
@numline/@#1_#2/.style={to path={[@numline/@l#1={\tikztostart}{},
@numline/@r#2={\tikztotarget}{##1}] ##1 (area_start)}}},
/utils/create to paths for combo/.list={
angle_bracket, angle_angle, bracket_angle, bracket_bracket,
_bracket, angle_, _angle, bracket_}}
\tikzset{
numline delimiters/.style={thick, draw},
numline area/.style={pattern color=gray, thin, pattern={Lines[angle=#1]}}}
\begin{document}
\begin{tikzpicture}
\draw[-Stealth] (-.5,0) -- (9.5,0) ;
\foreach \x in {0,1,...,9}
\draw[shift=(right:\x)] (0pt,3pt) -- (0pt,-3pt) node[below] {$\x$};
\path (2,0) to[angle-bracket=80] (7,0);
\end{tikzpicture}
\begin{tikzpicture}
\draw[-Stealth] (-.5,0) -- (9.5,0) ;
\foreach \x in {0,1,...,9}
\draw[shift=(right:\x)] (0pt,3pt) -- (0pt,-3pt) node[below] {$\x$};
\path (2,0) to[bracket-angle=-80] (7,0);
\end{tikzpicture}
\begin{tikzpicture}
\draw[-Stealth] (-.5,0) coordinate (start) -- (9.5,0) coordinate (end);
\foreach \x in {0,1,...,9}
\draw[shift=(right:\x)] (0pt,3pt) -- (0pt,-3pt) node[below] {$\x$};
\path (start) to[-angle =-80] (2,0);
\path (7,0) to[bracket-=-80] (end);
\end{tikzpicture}
\begin{tikzpicture}
\draw[-Stealth] (-.5,0) coordinate (start) -- (9.5,0) coordinate (end);
\foreach \x in {0,1,...,9}
\draw[shift=(right:\x)] (0pt,3pt) -- (0pt,-3pt) node[below] {$\x$};
\path (start) to[-bracket=80] (2,0);
\path (7,0) to[angle- =80] (end);
\end{tikzpicture}
\end{document}