2

I have to include a lot of boxplots in my document and would like to automate this with a custom command. I'd like to be able to write something like this:

\boxplots[
  range={1,2,3,4,5},
  questions={
    {
       label=How many years ago did you start?
       key=How many years   
    },
    {
       label=How many hours do you spend playing?  
    }
  }
]

If the key argument isn't provided in the question list, it should default to the label argument. The command should look something like this (no proper LaTeX syntax):

\newcommand{\boxplots}[2] {
  \begin{tikzpicture}
    \begin{axis} [
      xmin=MIN(#1),
      xmax=MAX(#1),
      xtick=#1
      ytick={1,...,LEN(#2)},
      yticklabels=
        \foreach reversed \q in #2
          \stepcounter{questioncounter}
          \textbf{Q.\thequestioncounter} {\q[label]}
    ]
      \foreach reversed \q in #2
        \addplot+[boxplot={box extend=0.5}]
          table [
            y={\q[key]}
          ]{\userstudyResults};
    \end{axis}
  \end{tikzpicture}
}

The yticklabels should resolve to

{
  \textbf{Q.2} How many hours do you spend playing?,
  \textbf{Q.1} How many years ago did you start?
}

Problems I'm facing:

  • reverse iterating over a list provided as argument
  • calculating min and max of a list provided as argument
  • calculating length of a list provided as argument
  • named arguments
  • default argument

Thanks for helping me out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.