![有没有什么简单的方法可以让 TikZ 将箭头尖放在绘制的线之外?](https://linux22.com/image/441559/%E6%9C%89%E6%B2%A1%E6%9C%89%E4%BB%80%E4%B9%88%E7%AE%80%E5%8D%95%E7%9A%84%E6%96%B9%E6%B3%95%E5%8F%AF%E4%BB%A5%E8%AE%A9%20TikZ%20%E5%B0%86%E7%AE%AD%E5%A4%B4%E5%B0%96%E6%94%BE%E5%9C%A8%E7%BB%98%E5%88%B6%E7%9A%84%E7%BA%BF%E4%B9%8B%E5%A4%96%EF%BC%9F.png)
我经常需要表示数学间隔,并且我发现手动调整打开的括号很烦人(请参阅下面的 MWE)。
有什么办法吗:
- 定义一个新的箭头,该箭头从线的末端开始并进一步延伸(从而超出起点和/或终点坐标);
- 使这个新的箭头尖可扩展,以避免像 MWE 那样丑陋的渲染;
- 奖励:在代码中设计包含透明度组。
我在这里搜索,终于找到了TikZ:精确控制箭头位置但是语法已经改变,而我还不够熟练来适应新的语法。
\documentclass{article}
\usepackage{tikz, amssymb}
\usetikzlibrary{arrows.meta}
\begin{document}
\tikzset{
interv oo/.style={{Bracket[reversed, sharp, length=.75ex]}-{Bracket[reversed, sharp, length=.75ex]}, shorten <=-.75ex, shorten >=-0.75ex},
interv of/.style={{Bracket[reversed, sharp, length=.75ex]}-{Bracket[sharp, length=.75ex]}, shorten <=-.75ex},
interv fo/.style={{Bracket[sharp, length=.75ex]}-{Bracket[reversed, sharp, length=.75ex]}, shorten >=-0.75ex},
interv ff/.style={{Bracket[sharp, length=.75ex]}-{Bracket[sharp, length=.75ex]}},
interv oi/.style={{Bracket[reversed, sharp, length=.75ex]}-, shorten <=-.75ex},
interv io/.style={-{Bracket[sharp, length=.75ex]}, shorten >=-0.75ex},
interv fi/.style={{Bracket[sharp, length=.75ex]}-},
interv if/.style={-{Bracket[sharp, length=.75ex]}},
label/.style={below, font=\footnotesize} }
\begin{tikzpicture}
\draw (-3,0) -- (3,0) node[anchor=south] {$\mathbb{R}$};
\foreach \x in {-1,0,1} \draw (\x,2pt) -- (\x, -2pt) node[anchor=north] {$\x$};
\begin{scope}[opacity=.5, transparency group]
\draw[line width=3pt, blue, interv oo] (-1,0) -- (1,0);
\end{scope}
\end{tikzpicture}
\end{document}
提前谢谢了。
编辑 :tabularray
这是我最终得出的结论。对我来说似乎已经足够令人满意了。我刚刚了解到了它的用途。
\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{geometry}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, arrows}
\usepackage{tabularray}
\frenchbsetup{StandardLists=true} % Resolves conflict between babel and enumitem
\geometry{
top=1.5cm, bottom=1.5cm, left=1cm, right=1cm,
headheight=1cm, headsep=0.5cm,
footskip=1cm}
\setlength{\parindent}{0mm} % No paragraphe indentation
\begin{document}
\tikzset{
interv oo/.style={{Bracket[reversed, sharp, length=0pt 2, sep=0pt -1.5]}-{Bracket[reversed, sharp, length=0pt 2, sep=0pt -1.5]}},
interv of/.style={{Bracket[reversed, sharp, length=0pt 2, sep=0pt -1.5]}-{Bracket[sharp, length=0pt 2]}},
interv fo/.style={{Bracket[sharp, length=0pt 2]}-{Bracket[reversed, sharp, length=0pt 2, sep=0pt -1.5]}},
interv ff/.style={{Bracket[sharp, length=0pt 2]}-{Bracket[sharp, length=0pt 2]}},
interv oi/.style={{Bracket[reversed, sharp, length=0pt 2, sep=0pt -1.5]}-},
interv io/.style={-{Bracket[reversed, sharp, length=0pt 2, sep=0pt -1.5]}},
interv fi/.style={{Bracket[sharp, length=0pt 2]}-},
interv if/.style={-{Bracket[sharp, length=0pt 2]}},
label/.style={below, font=\footnotesize} }
Compléter le tableau suivant:
\begin{tblr}{hlines, vlines,
cell{2-5}{1,4}={mode=dmath},
colspec={X[1,c,m] X[3,c,m] X[2.2,c,m] X[1.2,c,m]},
rowsep=10pt,
row{1} = {font=\bfseries, rowsep=4pt},
}
Inégalité & Phrase & Représentation graphique & Intervalle \\
\ldots x\ldots & {$x$ est un réel\\ strictement supérieur à $-2$\\ et strictement inférieur à $4$} & \begin{tikzpicture}[scale=0.5, >=stealth, baseline={([yshift=-.5ex]current bounding box.center)}]
% Bornes
\def\xm{-4.9}
\def\xM{-\xm}
% Intervalle
\draw[line width=4.5pt, green, interv oo] (-2,0) -- (4,0) ;
% Repère
\draw[thick,->] (\xm,0) -- (\xM,0) ;
\foreach \x in {-4,...,4} { \draw (\x, -2mm) -- ++(0, 4mm) ; }
\node[label] at (0,0) {0} ;
\node[label] at (1,0) {1} ;
\node[label, above, white] (0,0) {0} ; % Pour équilibrer le dessin verticalement
\end{tikzpicture} & x\in\ldots \\
& & \begin{tikzpicture}[scale=0.5, >=stealth, baseline={([yshift=-.5ex]current bounding box.center)}]
% Bornes
\def\xm{-4.9}
\def\xM{-\xm}
% Intervalle
\draw[line width=2.5pt, red, interv of] (-2,0) -- (4,0) ;
% Repère
\draw[thick,->] (\xm,0) -- (\xM,0) ;
\foreach \x in {-4,...,4} { \draw (\x, -2mm) -- ++(0, 4mm) ; }
\node[label] at (0,0) {0} ;
\node[label] at (1,0) {1} ;
\node[label, above, white] (0,0) {0} ; % Pour équilibrer le dessin verticalement
\end{tikzpicture} & \\
& & \begin{tikzpicture}[scale=0.5, >=stealth, baseline={([yshift=-.5ex]current bounding box.center)}]
% Bornes
\def\xm{-4.9}
\def\xM{-\xm}
% Intervalle
\draw[line width=2.5pt, orange, interv fo] (-2,0) -- (4,0) ;
% Repère
\draw[thick,->] (\xm,0) -- (\xM,0) ;
\foreach \x in {-4,...,4} { \draw (\x, -2mm) -- ++(0, 4mm) ; }
\node[label] at (0,0) {0} ;
\node[label] at (1,0) {1} ;
\node[label, above, white] (0,0) {0} ; % Pour équilibrer le dessin verticalement
\end{tikzpicture} & \\
& & \begin{tikzpicture}[scale=0.5, >=stealth, baseline={([yshift=-.5ex]current bounding box.center)}]
% Bornes
\def\xm{-4.9}
\def\xM{-\xm}
% Intervalle
\draw[line width=2.5pt, yellow!70!orange, interv ff] (-2,0) -- (4,0) ;
% Repère
\draw[thick,->] (\xm,0) -- (\xM,0) ;
\foreach \x in {-4,...,4} { \draw (\x, -2mm) -- ++(0, 4mm) ; }
\node[label] at (0,0) {0} ;
\node[label] at (1,0) {1} ;
\node[label, above, white] (0,0) {0} ; % Pour équilibrer le dessin verticalement
\end{tikzpicture} & \\
& & \begin{tikzpicture}[scale=0.5, >=stealth, baseline={([yshift=-.5ex]current bounding box.center)}]
% Bornes
\def\xm{-4.9}
\def\xM{-\xm}
% Intervalle
\begin{scope}[transparency group, opacity=.5]
\draw[line width=2.5pt, cyan, interv oi] (-2,0) -- (\xM,0) ;
\end{scope}
% Repère
\draw[thick,->] (\xm,0) -- (\xM,0) ;
\foreach \x in {-4,...,4} { \draw (\x, -2mm) -- ++(0, 4mm) ; }
\node[label] at (0,0) {0} ;
\node[label] at (1,0) {1} ;
\node[label, above, white] (0,0) {0} ; % Pour équilibrer le dessin verticalement
\end{tikzpicture} & \\
& & \begin{tikzpicture}[scale=0.5, >=stealth, baseline={([yshift=-.5ex]current bounding box.center)}]
% Bornes
\def\xm{-4.9}
\def\xM{-\xm}
% Intervalle
\draw[line width=2.5pt, purple, interv io] (\xm,0) -- (4,0) ;
% Repère
\draw[thick,->] (\xm,0) -- (\xM,0) ;
\foreach \x in {-4,...,4} { \draw (\x, -2mm) -- ++(0, 4mm) ; }
\node[label] at (0,0) {0} ;
\node[label] at (1,0) {1} ;
\node[label, above, white] (0,0) {0} ; % Pour équilibrer le dessin verticalement
\end{tikzpicture} & \\
& & \begin{tikzpicture}[scale=0.5, >=stealth, baseline={([yshift=-.5ex]current bounding box.center)}]
% Bornes
\def\xm{-4.9}
\def\xM{-\xm}
% Intervalle
\begin{scope}[transparency group, opacity=.5]
\draw[line width=2.5pt, gray, interv fi] (-2,0) -- (\xM,0) ;
\end{scope}
% Repère
\draw[thick,->] (\xm,0) -- (\xM,0) ;
\foreach \x in {-4,...,4} { \draw (\x, -2mm) -- ++(0, 4mm) ; }
\node[label] at (0,0) {0} ;
\node[label] at (1,0) {1} ;
\node[label, above, white] (0,0) {0} ; % Pour équilibrer le dessin verticalement
\end{tikzpicture} & \\
& & \begin{tikzpicture}[scale=0.5, >=stealth, baseline={([yshift=-.5ex]current bounding box.center)}]
% Bornes
\def\xm{-4.9}
\def\xM{-\xm}
% Intervalle
\begin{scope}[transparency group, opacity=.5]
\draw[line width=2.5pt, blue!50!white, interv if] (\xm,0) -- (4,0) ;
\end{scope}
% Repère
\draw[thick,->] (\xm,0) -- (\xM,0) ;
\foreach \x in {-4,...,4} { \draw (\x, -2mm) -- ++(0, 4mm) ; }
\node[label] at (0,0) {0} ;
\node[label] at (1,0) {1} ;
\node[label, above, white] (0,0) {0} ; % Pour équilibrer le dessin verticalement
\end{tikzpicture} & \\
\end{tblr}
\end{document}
答案1
您可以使用sep
选项(将箭头从线的端点坐标移开)来执行此操作 - 它使用与相同的语法length
。如果您想要头部的绝对长度,您可以改回0pt 1
(.75ex
或者使用em
或pt
表示水平距离)
\documentclass[tikz, border=1 cm]{standalone}
\usepackage{amssymb}
\usetikzlibrary{arrows.meta}
\begin{document}
\tikzset{
interv oo/.style={{Bracket[reversed, sharp, length=0pt 1, sep=0pt -1]}-{Bracket[reversed, sharp, length=0pt 1, sep=0pt -1]}},
}
\begin{tikzpicture}
\draw (-3,0) -- (3,0) node[anchor=south] {$\mathbb{R}$};
\foreach \x in {-1,0,1} \draw (\x,2pt) -- (\x, -2pt) node[anchor=north] {$\x$};
\begin{scope}[opacity=.5, transparency group]
\draw[line width=5pt, blue, interv oo] (-1,0) -- (1,0);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
好问题(+1)!
不幸的是,据我所知,箭头的设计是,给定箭头长度时也要考虑箭头头的长度。这在很多情况下是非常理想的特征,但在您和一些类似情况下,有些人希望箭头头在箭头线之后(之前)开始。
暂时唯一可行的办法是定义箭头长度并将箭头线延长此长度。也许您应该添加箭头长度的依赖关系,以及从使用的箭头线加粗所需的线条延伸。例如像这样:
\documentclass[border=3mm]{standalone}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\tikzset{
interv oo/.style={{Bracket[reversed, length=0pt 2]}-{Bracket[reversed, length=0pt 2]}, shorten <=-2\pgflinewidth, shorten >=-2\pgflinewidth},
% I didn't check other definition
label/.style={font=\footnotesize, below=#1},
label/.default = {}
}
\begin{tikzpicture}
\draw (-3,1) -- (3,1) node[above] {$\mathbb{R}$};
\draw (-3,0) -- (3,0) node[above] {$\mathbb{R}$};
\foreach \x in {-1,0,1}
{
\draw (\x,1.1) -- ++ (0,-0.2) node[label=1.5ex] {$\x$};
\draw (\x,0.1) -- ++ (0,-0.2) node[label=1.5ex] {$\x$};
}
\begin{scope}[opacity=.5, transparency group]
\draw[line width=3pt, blue, interv oo] (-1,1) -- (1,1);
\draw[line width=2pt, blue, interv oo] (-1,0) -- (1,0);
\end{scope}
\end{tikzpicture}
通过上述解决方案,箭头尺寸与线宽成比例缩放(这是令人愉快的特征)。
当然,如果有一个箭头选项,可以将箭头推到箭头线的外面,那会很有趣。
编辑: 其使用的一个例子(在你的情况下应该是):
interv oo/.style={{Bracket[reversed, outside]}-{Bracket[reversed, outside]}},
可能是图书馆的作者或其他 Ti钾Z guru 会提供这样的选项,我只能建议它的名字:外部:-)。但这是功能请求。您可以写信给 GitHub。