0

enter image description here I've tried multiple line drawing techniques but none of them seem to be producing the above, once they are drawn is it also possible to group them in a single row such that they can be moved altogether. Thanks in advance.

  • Welcome to TeX.SE! Do you like to have image as you show, or lines can be draw solid with help of some package as is tikz or pstricks, etc?. If you like to reproduce image as it ism, use verbatim environment. Please, show us, what you try so far. – Zarko Mar 24 at 15:33
11

I always hoped this would become modern again one day. ;-)

\documentclass{article}
\begin{document}
\begin{verbatim}
              /\                                  /\
  /\         /  \/\               /\             /  \
 /  \     /\/      \             /  \       /\  /    \/\
/    \   /          \     /\/\/\/    \     /  \/        \/\
\end{verbatim}
\end{document}

enter image description here

It is rather straightforward to do that with TikZ (with my personal favorite proposal being the third one). Just dial some dash pattern.

\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}

enter image description here

Or, since the choices are only up (+) and down (-), we can use the parser module.

\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}

enter image description here

You may also do away with the dash pattern, then.

\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}

enter image description here

| improve this answer | |
  • I would like to draw the lines and not use a picture, I've tried using coordinates with the \draw function but this is very tedious. – Broccoli Mar 24 at 15:44
  • trees is the way to go – js bibra Mar 24 at 15:55
  • how would I go about doing this – Broccoli Mar 24 at 15:57
  • 3
    +1 The dash pattern is amazing... fantastic... marvelous... perfect! – Paul Gaborit Mar 24 at 16:10
  • @PaulGaborit Merci! (I added a parser based variant.) – Schrödinger's cat Mar 24 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.