我想获得如下所示的 tikz 图片。您能帮我完成代码以实现该结果吗?
\documentclass[11pt]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=50]
\draw (-0.2,0) -- (1.2,0);
\draw (0, 0) node[below=7pt] {$a_1$};
\draw[] (0,-0.1) -- (0,0.1);
\draw (1, 0) node[below=7pt] {$a_2$};
\draw[] (1,-0.1) -- (1,0.1);
\end{tikzpicture}
\end{document}
编辑
我喜欢@Qrrbrbirlbel 的提议,但我想让“[”和“)”符号稍微大一点。有什么想法吗?
答案1
您可以根据自己的喜好调整大小(更新会删除初始代码中多余的一行)。
\documentclass[border=6pt,tikz]{standalone}
\usepackage[T1]{fontenc} % better to have fontenc *before* inputenc
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-0.2,0) -- (1.2,0);
\draw [thick] (0.1,-.25) -- (0,-.25) -- (0,.25) -- (0.1,.25);
\draw (0,-.25) node [anchor=north] {$a_1$};
\draw (1,-.25) node [anchor=north] {$a_2$};
\draw [thick] (0.7,-.25) .. controls (1.05,-0.2) and (1.05,0.2)
.. (0.7,.25);
\end{tikzpicture}
\end{document}
答案2
我在这里只使用箭头。
要获得更大的箭头,您需要增加线宽。
您还可以使用带有缩放比例(仅或有效)或其他选项的自定义decorations.markings
宏库在线上放置“箭头”。\arrow
yscale
xscale
您还可以向行中添加文本内容,例如 a[
和 a )
,您可以控制字体(大小、系列等),并且还可以根据需要缩放节点。
arrows.meta
CVS 版本的 TikZ 库(参见如何安装当前版本的 TikZ?)让我们能够非常轻松地使用arrows={[scale=2]}
(或任何选项)。也可以直接为箭头提供选项,例如
\draw [{Bracket[right,red]}-{Arc Barb[arc=270]}] …;
代码
\documentclass[tikz, border={0pt 0pt 0pt 6pt}]{standalone}
\usetikzlibrary{arrows,decorations.markings}
\usetikzlibrary{arrows.meta}% CVS
\begin{document}
\begin{tikzpicture}[inner sep=+0pt]
\draw (+0pt,+0pt) -- ++(right:+10pt) coordinate (@);
\draw[[-)] (@) node[below=+6pt] {$a_1$} -- ++ (right:+50pt) node[below=+6pt] {$a_2$} coordinate (@);
\draw (@) -- ++ (right:+10pt);
\end{tikzpicture}
\tikz[inner sep=+0pt, outer sep=+0pt, nodes={below=+6pt}]
\draw[decoration={
markings, mark=at position .2 with {\arrow[line width=.7\pgflinewidth,scale=2]{[}},
mark=at position .8 with {\arrow[line width=.7\pgflinewidth,scale=2]{)}}},
postaction=decorate]
(+0pt,+0pt) -- node[pos=.2, below=+3pt] {$a_1$} node[pos=.8, below=+3pt] {$a_2$} ++(right:+70pt);
\tikz[label position=below, inner sep=+0pt, outer sep=+0pt, every label/.style={font=},
label distance=+3pt, nodes={font=\bfseries}]
\draw (+0pt,+0pt) -- node[pos=.2,label=$a_1$] {[} node[pos=.8,label=$a_2$] {)} ++(right:+70pt);
\begin{tikzpicture}[inner sep=+0pt, arrows={[scale=2]}]% CVS
\draw (+0pt,+0pt) -- ++(right:+10pt) coordinate (@);
\draw[Bracket-Arc Barb] (@) node[below=+6pt] {$a_1$} -- ++ (right:+50pt) node[below=+6pt] {$a_2$} coordinate (@);
\draw (@) -- ++ (right:+10pt);
\end{tikzpicture}
\end{document}
输出
答案3
262 次击键(现有答案为 299 次击键),使用 PSTricks。
\documentclass[pstricks]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(5,1)
\pstGeonode[PointName={a_1,a_2},PosAngle=-90,PointSymbol=none](1.2,.6){A}(3.8,.6){B}
\pcline[nodesep=-1](A)(B)
\psline{[-)}(A)(B)
\end{pspicture}
\end{document}
因为想要获得更大的[
和)
,我修改了上述代码,如下所示。
\documentclass[pstricks]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(5,1)
\pstGeonode[PointName={a_1,a_2},PosAngle=-90,PointSymbol=none,PointNameSep=13pt](1.2,.65){A}(3.8,.65){B}
\pcline[nodesep=-1](A)(B)
\psline[arrowscale=2]{[-)}(A)(B)
\end{pspicture}
\end{document}