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.

I would like to have the data series for a sparkline defined in terms of a macro -- or some alternative -- as opposed to have it set explicitly in the sparkline environment itself. My attempts so far have failed. As an MWE, the following would do:

\documentclass[12pt]{memoir}

\usepackage{xcolor,tikz,sparklines}

\begin{document}
\xdef\SparkMacro{0 1 0.5 1.5 1 0.25} 
\renewcommand{\sparklineheight}{1.75}
\begin{sparkline}{3}
\sparkrectangle 0 1.75
\spark \SparkMacro\ / % doesn't work
% \spark 0 1 0.5 1.5 1 0.25 /% does work
\end{sparkline}
\end{document}

How could I have those data passed to the environment sparklinewithout having to type (or copy and paste) them explicitly?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You need \expandafter to expand the data before \spark sees it. Also you need a real space not \ at the end. The easiest is to make sure your macro ends with space.

\documentclass[12pt]{memoir}

\usepackage{xcolor,tikz,sparklines}

\begin{document}
\xdef\SparkMacro{0 1 0.5 1.5 1 0.25 } 
\renewcommand{\sparklineheight}{1.75}
\begin{sparkline}{3}
\sparkrectangle 0 1.75
\expandafter\spark \SparkMacro / % doesn't work
%\spark 0 1 0.5 1.5 1 0.25 /% does work
\end{sparkline}
\end{document}
share|improve this answer
    
Right. I had it in front of me, but my mind was not clear about the spaces and got into a mess with several \expandafter commands. Thank you so much. –  Marcos Sep 2 '12 at 17:04
    
Another alternative is to not include the space in SparkMacro but use \SparkMacro{} / –  Aditya Sep 2 '12 at 17:27
add comment

In Is there a package that provides graphing in the style of Ed Tufte? I created a solution for sparklines which is not based on the sparkline package, but on pgfplots.

The advantage is: you can provide input by means of numerical tables, provide a numerical table and plot data based on mathematical expressions on those tables, or provide a mathematical expression right-away.

The mentioned solution features bar plots, line plots, and scatter plots, and it can also determine the minimum/maximum coordinate automatically.

See Is there a package that provides graphing in the style of Ed Tufte? for details

share|improve this answer
    
Thanks so much for pointing this out. I already knew of the package and I think it is a great contribution to graphics integration in TeX-based documents, even though I am more familiar with PSTricks-based graphics generation -- just from my regular use of them. I'm sure that I'll go to Tikz-based methods for some tasks, though. –  Marcos Sep 12 '12 at 19:11
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.