答案1
我一直希望有一天这会再次变得现代化。;-)
\documentclass{article}
\begin{document}
\begin{verbatim}
/\ /\
/\ / \/\ /\ / \
/ \ /\/ \ / \ /\ / \/\
/ \ / \ /\/\/\/ \ / \/ \/\
\end{verbatim}
\end{document}
使用 Ti 来实现这一点相当简单钾Z(我个人最喜欢的方案是第三个)。只需拨一些破折号图案即可。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[dash pattern=on 7.5pt off 3.5pt,shorten <=1.5pt,x=1ex,y=1em]
\draw[thick] (0,0) -- ++ (3,3) -- ++ (3,-3);
\draw[thick] (11,0) -- ++ (2,2) -- ++ (1,-1) -- ++ (3,3) -- ++ (2,-2)
-- ++ (1,1) -- ++ (3,-3);
\draw[thick] (33,0) foreach \X in {1,2,3}{-- ++ (1,1) -- ++ (1,-1)}
-- ++ (3,3) -- ++ (3,-3);
\draw[thick] (55,0) -- ++ (2,2) -- ++ (2,-2)
-- ++ (4,4) -- ++ (3,-3) -- ++ (1,1) -- ++ (2,-2) -- ++ (1,1) -- ++ (1,-1);
\end{tikzpicture}
\end{document}
或者,由于选择只有向上(+
)和向下(-
),我们可以使用parser
模块。
\documentclass{article}
\usepackage{tikz}
\usepgfmodule{parser}
\pgfparserdef{pft}{initial}{the character -}%
{\tikzset{insert path={-- ++(1,-1)}}}%
\pgfparserdef{pft}{initial}{the character +}%
{\tikzset{insert path={-- ++(1,1)}}}%
\pgfparserdef{pft}{initial}{the character ;}%
{\pgfparserswitch{final}}%
\tikzset{hillside/.code={\pgfparserparse{pft}#1;%
}}
\begin{document}
\begin{tikzpicture}[dash pattern=on 7.5pt off 3.5pt,shorten <=1.5pt,x=1ex,y=1em,
thick]
\draw (0,0)[hillside={+++---}];
\draw (11,0) [hillside={++-+++--+---}];
-- ++ (1,1) -- ++ (3,-3);
\draw[thick] (33,0) [hillside={+-+-+-+++---}];
\draw[thick] (55,0) [hillside={++--++++---+--+-}];
\end{tikzpicture}
\end{document}
那么您也可以取消破折号图案。
\documentclass{article}
\usepackage{tikz}
\usepgfmodule{parser}
\pgfparserdef{pft}{initial}{the character -}%
{\tikzset{insert path={edge[shorten <=1.75pt,shorten >=1.75pt] ++(1,-1) ++(1,-1)}}}%
\pgfparserdef{pft}{initial}{the character +}%
{\tikzset{insert path={edge[shorten <=1.75pt,shorten >=1.75pt] ++(1,1) ++(1,1)}}}%
\pgfparserdef{pft}{initial}{the character ;}%
{\pgfparserswitch{final}}%
\tikzset{hillside/.code={\pgfparserparse{pft}#1;%
}}
\begin{document}
\begin{tikzpicture}[x=1ex,y=1em,thick]
\draw (0,0)[hillside={+++---}];
\draw (11,0) [hillside={++-+++--+---}];
\draw (33,0) [hillside={+-+-+-+++---}];
\draw (55,0) [hillside={++--++++---+--+-}];
\end{tikzpicture}
\end{document}