Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How would I draw a picture like this in tex?

I'm not sure of the scaling ratio. I believe it can be arbitrary. i.e. As long as the length of $\ell_j$ is less than $\ell_i$, $\forall \, j>i$

enter image description here

Any help would be appreciated.

share|improve this question
    
Any particular function, or just demonstrate a method? –  Steven B. Segletes Feb 26 at 19:12
8  
Can you show us what you've tried so far? –  Paul Gessler Feb 26 at 19:12
    
@StevenB.Segletes Any method would be fine. –  Anthony Peter Feb 26 at 19:13
4  
This seems almost trivial compared to the other diagrams you have requested. Have you studied the code in the other answers? If you get more specific in terms of which aspects you are having difficulty with, it would be a lot easier to help you where you can actually adapt it for future diagrams. –  Peter Grill Feb 26 at 19:13
2  
At least you could tell us the relation between line lengths. –  Ignasi Feb 26 at 19:13

4 Answers 4

up vote 22 down vote accepted

With a TikZ \foreach loop it is just three lines. To control the decay change the part

... -- (\x,-10/\x);

to your liking, e.g.

... -- (\x,{-5/sqrt(\x)});

Example

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
    \foreach \x in {1,...,11} {
        \draw[|-|] (\x,0) node[above] {$\ell_{\x}$} -- (\x,-10/\x);
    }
    \node at (12,-10/12/2) {$\cdots$};
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer
    
How do you add the ellipses? –  Anthony Peter Feb 26 at 19:34
    
@AnthonyPeter See my updated answer. Keep in mind, that you might want to adjust the y-component of the ellipsis, if you adjust the decay. –  Henri Menke Feb 26 at 19:38

Done without tikz. One passes a label and space-separated real-number list to \graphmydata. Configurable parameters include the unit length (scale) associated with the data (\graphunits), the rule thickness (\rlwd), the horizontal gap between items (\myhgap), and the tick length (\ticklength).

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\usepackage{readarray}
\usepackage{ifthen}
\def\rlwd{.4pt}
\def\myhgap{1.5em}
\def\ticklength{.5ex}
\newlength\graphunits
\graphunits 1cm
\def\tick{\rule{\ticklength}{\rlwd}}

\newcommand\dline[1]{%
  \setstackgap{S}{0pt}\Shortunderstack{\tick\\\rule[-#1]{\rlwd}{#1} \\\tick}}

\newcommand\mygraph[2]{%
  \stackunder[3pt]{\hsmash{#1}}{\dline{#2\graphunits}}\hspace{\myhgap}\ignorespaces}

\newcounter{index}
\def\graphmydata#1#2{%
  \readArrayij{#2}{datablock}{1}%
  \setcounter{index}{0}%
  \whiledo{\theindex<\datablockCELLS}{%
    \stepcounter{index}%
    \mygraph{$#1_{\theindex}$}{\arrayij{datablock}{\theindex}{1}}%
  }%
  \raisebox{-\baselineskip+5pt}{$\cdots$}%
}
\begin{document}
\graphmydata{l}{3 1.5 0.75 0.375 0.1875 0.09375}
\end{document}

enter image description here

Thus, changing the parameters to

\def\rlwd{.8pt}
\def\myhgap{1.6em}
\def\ticklength{.8ex}
\graphunits 0.02cm
\graphmydata{p}{103.4 52.2 26.6 13.8 7.4 4.2 2.6 1.8 1.4 1.2 1}

yields

enter image description here


EDIT: for those wishing to import data from a file, rather than from a \def, the readarray package can import the data from a file. Here is that version:

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\usepackage{readarray}
\usepackage{ifthen}
\usepackage{filecontents}
\def\rlwd{.4pt}
\def\myhgap{1.5em}
\def\ticklength{.5ex}
\newlength\graphunits
\graphunits 1cm
\def\tick{\rule{\ticklength}{\rlwd}}

\newcommand\dline[1]{%
  \setstackgap{S}{0pt}\Shortunderstack{\tick\\\rule[-#1]{\rlwd}{#1} \\\tick}}

\newcommand\mygraph[2]{%
  \stackunder[3pt]{\hsmash{#1}}{\dline{#2\graphunits}}\hspace{\myhgap}\ignorespaces}

\newcounter{index}
\def\graphmydatafile#1#2{%
  \readdef{#2}{\mydata}%
  \readArrayij{\mydata}{datablock}{1}%
  \setcounter{index}{0}%
  \whiledo{\theindex<\datablockCELLS}{%
    \stepcounter{index}%
    \mygraph{$#1_{\theindex}$}{\arrayij{datablock}{\theindex}{1}}%
  }%
  \raisebox{-\baselineskip+5pt}{$\cdots$}%
}

\begin{filecontents}{mydatafile.dat}
3
1.5
0.75
0.375
0.1875
0.09375%
\end{filecontents}

\begin{document}
\graphmydatafile{l}{mydatafile.dat}
\end{document}
share|improve this answer

Done with MetaPost, and the gmp package as interface (to be run with the shell-escape option activated).

There are noticeably more lines than with tikz, mainly because I had to define myself a macro that draws the segments with perpendicular marks at their extremities, since MetaPost has no build-in macro for that. Yet it was no big deal. Anyway, MetaPost is by nature more verbose than tikz, pstricks of its related (La)TeX package mfpic, but defining auxiliary macros with it when needed is fortunately easy (at least I find it so)).

\documentclass[12pt]{article}
\usepackage[latex, shellescape]{gmp}
\gmpoptions{everymp={%
  input latexmp;
  setupLaTeXMP(options="12pt", textextlabel = enable, mode = rerun);
  % mark length
  lmark := 6bp;
  % auxiliary macro for segments with marks at their extremities
  vardef segment(expr A, B) =
    save v; pair v; v = 0.5lmark*unitvector(B-A) rotated 90;
    image(draw A--B; for M = A, B: draw M+v -- M-v; endfor;)
  enddef;
  % function defining the length of the segments (borrowed from Henri Menke)
  vardef f(expr x) = -10/x enddef;}}

\begin{document}
\begin{center}
  \begin{mpost*}
    u := 1cm; n := 11;
    for i= 1 upto n-1:
      draw segment(u*(i, 0), u*(i, f(i)));
      label.top("$\ell_{" & decimal(i) & "}$", u*(i, 0));
    endfor;
    label("$\ldots$", u*(n, 0.5f(n)));
  \end{mpost*}
\end{center}
\end{document}

enter image description here

share|improve this answer
    
You don't need to write a custom segment function: if you set ahangle:=180; ahlength:=3 then you can use drawdblarrow to make the bars. –  Thruston Feb 27 at 10:40

No fun without PSTricks. The following is the most optimized PSTricks solution. Can you do more?

\documentclass[pstricks]{standalone}
\SpecialCoor
\begin{document}
\begin{pspicture}[arrows=|-|](0,-11)(13,1)
    \foreach \i in {1,...,11}{\uput[90](\i,0){$l_{\i}$}\psline(\i,0)(*{\i} {-10/x})}
    \rput(*12 {-5/x}){\ldots}
\end{pspicture}
\end{document}

enter image description here

share|improve this answer
    
\SpecialCoor and pgfmath and multido should be available by default I think! –  cyanide-based food Feb 27 at 3:43
    
Just to know: When does one need to use pgf packages while working with PSTricks code ? There should always be an equivalent package in both right ? –  texenthusiast Feb 27 at 3:51
    
@texenthusiast: pgfmath is a multipurpose package that can be used for both PSTricks and TikZ and others. If it is used together with pgffor, it allows us to use \foreach \x[count=\c from 1]... that is useful in some PSTrics cases. I think PSTricks maintainers forgot to include pgfmath while pgffor is already loaded by default. –  cyanide-based food Feb 27 at 3:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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