# How do you draw what is in the image below on LaTeX

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. Mar 24 '20 at 15:33

## 1 Answer

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

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


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}


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}


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}


• 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. Mar 24 '20 at 15:44
• trees is the way to go Mar 24 '20 at 15:55
• how would I go about doing this Mar 24 '20 at 15:57
• +1 The dash pattern is amazing... fantastic... marvelous... perfect! Mar 24 '20 at 16:10
• @PaulGaborit Merci! (I added a parser based variant.)
– user194703
Mar 24 '20 at 16:20