I want to give a good visualization of two functions on the integers. Is there a way to write something that looks like this:

enter image description here

I thought of using tikz, but I am not sure how.


No need of TikZ for this :-)




& & \UpArr & & \UpArr & & \UpArr & & \UpArr & & \UpArr \\
\cdots & -5 & -4 & -3 & -2 & -1 & \phantom{-}0 & \phantom{-}1 & \phantom{-}2 & \phantom{-}3 & \phantom{-}4 & \phantom{-}5 & \cdots \\
& \DownArr & & \DownArr & & \DownArr & & \DownArr & & \DownArr \\


enter image description here

  • using the \mathclap of mathtools on the up and down arrows there would be no need for the \mkern-5mu which looks like it was obtained by hands, experimentally. – user4686 Sep 13 '13 at 17:34
  • 1
    i.e.: \raisebox{\depth}{$\mathclap{\uparrow}$}\rule{3.05em}{0.4pt}\raisebox{\depth}{$\mathclap{\uparrow}$} which needs no manual adjustment. And \raisebox{-\height}{$\mathclap{\downarrow}$}\rule[-0.4pt]{3.05em}{0.4pt}\raisebox{-\height}{$\mathclap{\downarrow}$}. – user4686 Sep 13 '13 at 17:40
  • Edit: my last suggestion better perhaps with \raisebox{2ex}{the whole thing with \downarrow}. – user4686 Sep 13 '13 at 17:46
  • @jfbu thanks for your suggestions! I've incorporated them in my updated answer. – Gonzalo Medina Sep 13 '13 at 23:42

Another option


% the loop runs over the to-be-displayed items
%     \x  : Holds the text
%     \xi : Counts the number of spins (starting from 1)
%     \xj : Holds the previous spin number
\foreach \x[count=\xi,evaluate=\x as \xj using {int(\xi-1)}] in {\dots,-5,-4,...,5,\dots}{
% Place a node with the name (n-<spin no>) and with the text in mathmode.
\node (n-\xi) at (0.8*\xi,0) {$\scriptstyle\x$};
% We want to draw backwards so we need to start from -4 which is the third node
% Test if we have passed the initial ... and -5
\ifnum\xi>2\relax   %  Without \relax TeX keeps on parsing numbers 
  \ifnum\xi<12\relax%  until it encounters something that doesn't look like a number
                    %  it's not necessary here (\ifnum) is one of those things and a
                    %  comment is too small to explain it :P Please search main site for it 
% Now we alternate up and down. This alternating can be smaller, say, only the "above"
% and below text and the coordinate is changed instead of the whole \draw.... Simply 
%  we draw from the current \xi'th node to the previous \xj'th one.
    \draw[<->] (n-\xi) |- ++(-0.4,0.4) node[above]{$\sigma$} -| (n-\xj) ;
    \draw[<->] (n-\xi) |- ++(-0.4,-0.4)  node[below]{$\tau$} -| (n-\xj);
% Close all the if cases

enter image description here

Now I see that it should have been \ifnum<13 which is an evidence of the shortcoming that it's better check the last value of the list instead of hardcoding it.

  • Would you please explain your code? Especially the foreach loop. Why do you relax if xi has a value higher 2 and lower 12? – schmendrich Sep 13 '13 at 7:54
  • @schmendrich It's just precaution to make TeX stop looking for a number further than the numbers to be compared. Here they are not relevant but a coding habit. I'll comment more soon when I have a little time. – percusse Sep 13 '13 at 8:00
  • 1
    @schmendrich Done. – percusse Sep 13 '13 at 10:11

A more flexible solution using the chains library. My paths.ortho library may help with the ud and du to paths.


 edge node/.code={\expandafter\def\expandafter\tikz@tonodes\expandafter{\tikz@tonodes#1}},
 empty edge nodes/.code={\let\tikz@tonodes\pgfutil@empty},
 integer function/.code={%
    \tikzset{#1=of \tikzchainprevious}%
      \tikzset{join=by {every odd integer function/.try={#1},
                        integer function \tikzchaincount/.try={#1}}}%
      \tikzset{join=by {every even integer function/.try={#1},
                        integer function \tikzchaincount/.try={#1}}}%
  uddu distance/.initial=.25cm,
  ud/.style={to path={
    -- ([yshift=\pgfkeysvalueof{/tikz/uddu distance}] \tikztostart.north)
    -- ([yshift=\pgfkeysvalueof{/tikz/uddu distance}] \tikztotarget.north) \tikztonodes
    -- (\tikztotarget)}},
  du/.style={to path={
    -- ([yshift=-\pgfkeysvalueof{/tikz/uddu distance}] \tikztostart.south)
    -- ([yshift=-\pgfkeysvalueof{/tikz/uddu distance}] \tikztotarget.south) \tikztonodes
    -- (\tikztotarget)}},
  every odd integer function/.style={ud, edge node={node[every odd node/.try]{$\sigma$}}},
  every even integer function/.style={du, edge node={node[every even node/.try]{$\tau$}}},
  every odd node/.style={midway, above},
  every even node/.style={midway, below}
  node distance=+.5em,
  text depth=+0pt,
  every join/.append style={<->},
  start chain=ch going {integer function=right},
  integer function 3/.style={bend left=90},
  integer function 5/.style={
    empty edge nodes, edge node={node [above] {$\sigma_5$}}},
  integer function 8/.style={blue},
\foreach \cnt in {-5, ..., 5}
  \node[on chain=ch, text width=width("$-0$"), align=center] {$\cnt$};

\node[left=of ch-begin] {$\cdots$}; \node[right=of ch-end]  {$\cdots$};


enter image description here


With PSTricks and a simple algorithm to follow.


    \foreach \x in {-6,6}{\rput(\x,0){$\cdots$}}
    \foreach \x in {-5,-4,...,5}{\rput(\x,0){$\x$}}
    \foreach \x in {-4,-2,...,4}{\pcbar[angle=90](\x,0)(!\x\space 1 add 0)\naput{$\sigma$}}
    \foreach \x in {-5,-3,...,3}{\pcbar[angle=-90](\x,0)(!\x\space 1 add 0)\nbput{$\tau$}}

enter image description here

  • 1
    Note that pstricks automatically loads pgffor by default. – kiss my armpit Sep 13 '13 at 5:44

enter image description here

MWE with Asymptote:

% fint.tex:
import roundedpath; defaultpen(fontsize(10pt));
int n=6; real dx=1.2,dy=0.9, hl=0.2, hh=0.8;
guide arsig=roundedpath((dx,dy*hl)--(dx,dy*hh)--(0,dy*hh)--(0,dy*hl),0.2);
guide artau=rotate(180)*arsig;
pen textPen=darkblue, sigPen=blue+0.8bp, tauPen= red+0.8bp;

void draw(int i,guide g,pen p){draw(shift((2i-n+1)*dx,0)*g,p,Arrows(HookHead,size=5,Fill));}

for(int i=0;i<n;++i){
%% Process:
% pdflatex fint.tex 
% asy -f pdf fint-*.asy     
% pdflatex fint.tex

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.