对于报告,我需要以下图片,我想在 LaTeX/TikZ 中绘制它。
这个想法是,实线上有离散区间,在这些区间之上,我想写出它们中包含哪些元素......
(例如像我添加的图片。)
有没有一种相当简单的方法来绘制这个tikz
?
我从来没有合作过tikz
,所以也许你可以帮我画这个......
我想我将能够自己将其更改为其他间隔。
编辑:我在网上找到了代码并对其进行了修改。
\begin{tikzpicture}[decoration=brace]
% Die Grundlinie:
\draw(0,0)--(10,0);
% Striche und Beschriftung in Abständen 0, 2, 4, 6, ...
\foreach \x/\xtext in {0/$-m-n+1$,2/$-m-1$,4/$-m$,6/$0$,8/$m$,10/$m+n-1$}
\draw(\x,5pt)--(\x,-5pt) node[below] {\xtext};
% obere geschweifte Klammer mit Text darüber:
\draw[decorate, yshift=2ex] (0,0) -- node[above=0.4ex] {$0$'s} (2,0);
\draw[decorate, yshift=2ex] (10,0) -- node[above=0.4ex] {$l$'s and $0$'s with $l$'s separated by at least two $0$'s} (4,0);
\end{tikzpicture}
我得到的是:
为什么第二个括号是反过来的?
答案1
库中的支架decorations.pathreplacing
有一个选项mirror
,可以反转支架的面方向。因此,这就是您要添加的全部内容,以使其朝正确的方向。您可以这样做:
\documentclass[tikz,border=1mm]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
% Die Grundlinie:
\draw(0,0)--(10,0);
% Striche und Beschriftung in Abständen 0, 2, 4, 6, ...
\foreach \x/\xtext in {0/$-m-n+1$,2/$-m-1$,4/$-m$,6/$0$,8/$m$,10/$m+n-1$}
\draw(\x,5pt)--(\x,-5pt) node[below] {\xtext};
% obere geschweifte Klammer mit Text darüber:
\draw[decorate, decoration={brace}, yshift=2ex] (0,0) -- node[above=0.4ex] {$0$'s} (2,0);
\draw[decorate, decoration={brace, mirror}, yshift=2ex] (10,0) -- node[above=0.4ex] {$l$'s and $0$'s with $l$'s separated by at least two $0$'s} (4,0);
\end{tikzpicture}
\end{document}
答案2
这是一个pstricks
解决方案:
\documentclass[a4paper, pdf, x11names]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{pstricks-add}
\usepackage{stackengine}
\setstackEOL{\\}
\begin{document}
\centering
\psset{braceWidthOuter=4pt, braceWidthInner=4pt, braceWidth=0.8pt, labelsep =2ex}
\begin{pspicture}
\psset{linecolor =IndianRed3}
\psline(-1.2,0)(13.2,0)
\psdots[dotstyle=B|](0,0.02)(3,0.02)(4.2,0.02)(12,0.02)
\pnodes(0,0.6ex){Z1}(3,0.6ex){Z2}(4.2,0.6ex){L1}(12,0.6ex){L2}
\uput[d](Z1){$-m-n + 1$}\uput[d](Z2){$-m-1$\uput[d](L1){$-m$}}\uput[d](L2){$m + n - 1$}
\psset{rot=-90,linecolor=SlateGray4}
\psbrace*(Z2)(Z1){\makebox[0pt]{only $ 0 $’ s}}
\psbrace*(L2)(L1){\makebox[0pt]{\Centerstack{$ 0 $’s and $ l $’s\\$l $’s separated by at least $ 2 $ $ 0 $’s}}}
\end{pspicture}
\end{document}