
對於報告,我需要下面的圖片,我想用 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}