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.

In my plots, I have one bar (labelled dummy below) whose tick label needs to be typeset differently. Here's my current attempt (and minimal example), which doesn't quite work yet:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{etoolbox}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
  ybar,
  symbolic x coords={foo,bar,dummy},
  xtick=data,
  xticklabel={\ifdefstrequal{\tick}{dummy}{\textcolor{gray}{\tick}}{\tick}}]
  \addplot coordinates {
    (foo,2)
    (bar,4)
    (dummy,3)
  };
\end{axis}
\end{tikzpicture}
\end{document}

Now, I definitely need matching on the symbolic x coords name; comparing the \ticknum is unfortunately not an option, as the position of the dummy bar changes from plot to plot, and I don't want to touch the definition of xticklabel each time. So is there a way to do an appropriate string comparison with \tick?

share|improve this question
    
In your actual application, will you provide your data as coordinates, or do they come in a file/table? –  Jake Apr 15 '12 at 14:16
    
I'm using coordinates. If the solution would work for table too, however, that would be great. –  Andreas Apr 15 '12 at 14:33
add comment

1 Answer

up vote 5 down vote accepted

You could use the ifthen package:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{ifthen}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
  ybar,
  symbolic x coords={foo,bar,dummy},
  xtick=data,
  xticklabel=\ifthenelse{\equal{\tick}{dummy}}{\textcolor{red}{\tick}}{\tick}]
  \addplot coordinates {
    (foo,2)
    (bar,4)
    (dummy,3)
  };
\end{axis}
\end{tikzpicture}
\end{document}

If you want to use etoolbox, you'll have to use \ifdefstring{<macro>}{<string>}, which compares the content of a macro to a string.

\documentclass{article}

\usepackage{pgfplots}
\usepackage{etoolbox}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
  ybar,
  symbolic x coords={foo,bar,dummy},
  xtick=data,
  xticklabel=\ifdefstring{\tick}{dummy}{\textcolor{red}{\tick}}{\tick}]
  \addplot coordinates {
    (foo,2)
    (bar,4)
    (dummy,3)
  };
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
1  
Works. But out of curiosity, how would a solution using etoolbox look like, in particular in the light of Why is the ifthen package obsolete? –  Andreas Apr 15 '12 at 16:02
    
@Andreas: I've edited my answer to show how to do it with etoolbox. –  Jake Apr 15 '12 at 16:06
add comment

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.