1

I am drawing some figures with TikZ for a beamer presentation. I want one figure to look something like this:

A fancy axis

Additionally, I want to add labels under the intervals (the sections in between ticks on the axis). When trying to do this, I seem to be making some kind of syntactic mistake (see last section of the code below) - TeX seems to think I am missing a $ or have forgotten }, but I have utterly failed at spotting the mistake after numerous attempts.

I don't feel that well to ask for "debugging" help (since it will likely help no one but me), but considering I am quite pressed for time and still have to do lots of other figures and content... I figure someone might have fun telling me where my code sucks (and the why would be interesting as well). Here is my MWE (which is a beamer document since I will be using overlays for gradually uncovering figures):

\documentclass{beamer}
\usepackage{tikz}
\tikzset{%
  % Styles for visibility and hiding of elements in overlays%
  invisible/.style={opacity=0},%
  visible on/.style={alt=#1{}{invisible}},%
  alt/.code args={<#1>#2#3}{%
    \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}% \pgfkeysalso doesn't change the path
}}%
\usetikzlibrary{calc}
\colorlet{excitementcolor}{blue!40!green!70!white}
\colorlet{refractioncolor}{orange!80!white}
\colorlet{restingcolor}{white}

%................................
\begin{document}
  \begin{frame}
    \center
    \begin{tikzpicture}
      \def\shadeheight{2pt}
      \def\tickheight{0.15}
      \tikzset{axisstyle/.style={draw,semithick,fill=black,->}}
      % The shaded background%
      \shade[left color=refractioncolor]%
        (-2.5,-\shadeheight) rectangle (0.2,\shadeheight);%
      \shade[left color=white, right color=excitementcolor]%
        (0.4,-\shadeheight) rectangle (2.5,\shadeheight);%
      % The axis itself%
      \path[axisstyle]%
        (-2.5,0.0) -- (3.1,0) node[right] {$c_{ij}$};
      % Draw big ticks on axis%
      \foreach \x in {-2.5,...,2.5}{
        \draw (\x,-\tickheight) -- (\x,\tickheight); 
      }
      \node[above] at (0,\tickheight) {$0$};

      % Draw interval labels
      \foreach \x/\xt in {-2/$ [-\alpha,-\beta) $, -1/$ [ -\beta, -\gamma) $,  
                           0/$ [-\gamma,\delta) $,  1/$ [\delta,\epsilon)  $,  
                           2/$ [\epsilon,1+r)   $ }{  
        \node[below] at (\x,-\shadeheight) {\xt};
      }

    \end{tikzpicture}
  \end{frame}
\end{document}
MaxAxeHax
  • 1,210
  • The comma in the second variable is actually used as a delimiter between the tupels, you need to write -/{$[-\alpha,\beta)$} or something along the lines. How TikZ distinguish the comma between \alpha and -\beta and the one between $ and -1? Then there is a ] missing in the \node[above before. – Qrrbrbirlbel Jul 16 '13 at 19:43
  • @Qrrbrbirlbel Thanks a lot. I'm guessing I should delete this question, since it will be of no real use to the community, but am not quite sure. A short answer explaining the comma needs to be distinguished and why might be useful... thoughts? – MaxAxeHax Jul 16 '13 at 19:49
  • This problem turns up every now and then, for example in http://tex.stackexchange.com/questions/35082/string-list-in-tikz-foreach There may be other that explains things in more detail as well. We could close this as a duplicate, if you agree. – Torbjørn T. Jul 19 '13 at 06:22
  • @TorbjørnT. Yes, I very much do. I searched for a similar problem but I don't seem to be very good at searching. Should probably take the time to learn how to do an advanced search. – MaxAxeHax Jul 20 '13 at 11:07

0 Answers0