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 try to display on one Beamer slide a bar graph and a table with numbers taken from the same input file (to avoid repetition when copying the data). For now, I am stuck on this error message:

PGFPlots: reading {benchmarks.data}
! TeX capacity exceeded, sorry [input stack size=5000].
\@setfontsize #1#2#3->\@nomath #1
                        \ifx \protect \@typeset@protect \let \@curr...
l.33 \end{frame}

My data file is the folllowing:

paradigm                                          position  time
{\scriptsize \shortstack{Procedural\\(append)}}     1       53
{\scriptsize \shortstack{Procedural\\(prepend)}}    2       64
{\scriptsize Object-Oriented}                       3       45
{\scriptsize Functional}                            4       44
{\scriptsize List Comprehension}                    5       30

And, here is a stripped down version of my LaTeX code:

\documentclass[10pt]{beamer}
\usepackage{pgfplots,pgfplotstable}

\begin{document}

\begin{frame}
  \frametitle{Benchmark Results}
  \begin{columns}[m]
    \begin{column}{.5\textwidth}
      \begin{tikzpicture}[scale=.75]
        \begin{axis}[%
          ybar, bar width=0.65cm,%
          xmin=0.5,xmax=5.5, xtick=data,%
          xticklabels from table={benchmarks.data}{paradigm},%
          xticklabel style={rotate=45,anchor=north east,inner sep=0mm},%
          ylabel={\Large Time (s)}, ylabel near ticks]
          \addplot table [x=position,y=time] {benchmarks.data};
        \end{axis}
      \end{tikzpicture}      
    \end{column}
    \begin{column}{.35\textwidth}
      \pgfplotstabletypesetfile[%
      every even row/.style={before row={\rowcolor{blue!15}}},
      every head row/.style={before row=\toprule, after row=\midrule},
      every last row/.style={after row=\bottomrule},
      columns/paradigm/.style={column name={Paradigm}},
      columns/position/.style={column name={Position}},
      columns/time/.style={column name={Time (s)}}] {benchmarks.data}
    \end{column}
  \end{columns}
 \end{frame}

\end{document}

The most strange things is that the bar chart is working well, but I cannot make the table compile properly.

Any help is welcome !

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

The table automatically assumes numerical input but you have text in the paradigm column hence it needs string type indicator. Also you can prefix/append code to the cells by postprocessing options.

\documentclass[10pt]{beamer}
\usepackage{pgfplotstable,booktabs,colortbl,lmodern}
\pgfplotsset{compat=1.8}
\pgfplotstableread{
paradigm position time
{\shortstack{Procedural\\(append)}}     1       53
{\shortstack{Procedural\\(prepend)}}    2       64
{Object-Oriented}                       3       45
{Functional}                            4       44
{List Comprehension}                    5       30
}\mytable


\begin{document}

\begin{frame}
  \frametitle{Benchmark Results}
  \begin{columns}[m]
    \begin{column}{.5\textwidth}
      \begin{tikzpicture}[scale=.65]
        \begin{axis}[%
          ybar, bar width=0.65cm,%
          xmin=0.5,xmax=5.5, xtick=data,%
          xticklabels from table={\mytable}{paradigm},%
          xticklabel style={rotate=45,anchor=north east,inner sep=0mm},%
          ylabel={\Large Time (s)}, ylabel near ticks]
          \addplot table [x=position,y=time] {\mytable};
        \end{axis}
      \end{tikzpicture}      
    \end{column}
    \begin{column}{.5\textwidth}
      \pgfplotstabletypesetfile[%
      every even row/.style={before row={\rowcolor{blue!15}}},
      every head row/.style={before row=\toprule, after row=\midrule},
      every last row/.style={after row=\bottomrule},
      columns/paradigm/.style={
                     column name={Paradigm},
                     string type,
                     postproc cell content/.style={@cell content/.add={\scriptsize}{}}
                    },
      columns/position/.style={column name={Position}},
      columns/time/.style={column name={Time (s)}}] {\mytable}
    \end{column}
  \end{columns}
 \end{frame}

\end{document}

enter image description here

Sorry for the inline data. I was kind of lazy to include the filecontents package.

share|improve this answer
    
Damn, it was really simple. Thanks a lot ! Now, I will try to get rid of this position column... :) –  perror May 9 '13 at 11:37
    
@perror You can start with the option columns={paradigm,time} in the table and remove the position column related options. –  percusse May 9 '13 at 12:45
    
It worked as you said ! But, I am a bit surprised that you cannot get rid of this position column that I only use to set the x-position. Oh well, I'm fine with this anyway. Thanks ! –  perror May 9 '13 at 14:16
    
@perror Oh now I get it you want to get rid of it from the table. You can use x expr = \coordindex+1 instead of x=position to use the coordinate counter. It starts from 0 so I often add one to it. –  percusse May 9 '13 at 14:45
add comment

The answer was definitely given by percusse, so if you vote for this answer, vote also for percusse's one.

This answer is just here to provide the complete LaTeX code (and the final render) in order to gather all the tricks I did use (this may be useful to other people).

Anyway, if you see possible improvement, feel free to comment on it.

\documentclass[10pt]{beamer}

\usepackage{multirow, pgfplotstable,booktabs,colortbl,lmodern}

\pgfplotstableread{
paradigm        time2_7     time3_2
{Procedural (append)}   118.95      170.42
{Procedural (prepend)}  145.71      193.77
{Object-Oriented}        97.51      154.07
{Functional}             95.17      149.88
{List Comprehension}    106.26      162.37
}\mytable

\begin{document}

\begin{frame}
  \frametitle{Benchmark Results}

  \vfill
  \begin{columns}[m]
    \begin{column}{.5\textwidth}
      \begin{tikzpicture}[scale=.625]
        \begin{axis}[
          ybar, bar width=8pt,ymin=0,
          xmin=0.5,xmax=5.5, xtick=data,
          xticklabels from table={\mytable}{paradigm},
          xticklabel style={rotate=45,anchor=north east,inner sep=0mm},
          ylabel={\Large Time (s)}, ylabel near ticks]
          \addplot table [x expr=\coordindex+1,y=time2_7] {\mytable};
          \addlegendentry{Python 2.7};
          \addplot table [x expr=\coordindex+1,y=time3_2] {\mytable};
          \addlegendentry{Python 3.2};
        \end{axis}
      \end{tikzpicture}
    \end{column}

    \begin{column}{.6\textwidth}\scriptsize
      \pgfplotstabletypesetfile[
        columns={paradigm, time2_7, time3_2},
        every even row/.style={before row={\rowcolor{blue!15}}},
        every head row/.style={
          before row={\toprule 
            \multirow{2}{*}{\bfseries Programming Paradigm} & \multicolumn{2}{c}{\bfseries Time (s)}\\ \cmidrule{2-3}},
          after row=\midrule},
        every last row/.style={after row=\bottomrule},
        columns/paradigm/.style={
          column name={},
          string type},
        columns/time2_7/.style={
          column name={Python 2.7},
          postproc cell content/.style={@cell content/.add={}{\,s}}},
        columns/time3_2/.style={
          column name={Python 3.2},
          postproc cell content/.style={@cell content/.add={}{\,s}}}] 
          {\mytable}
    \end{column}
  \end{columns}
  \vfill

\end{frame}
\end{document}

And the final result is the following:

enter image description here

share|improve this answer
    
I had hard time to generate the PNG from the PDF with convert, do you use some specific settings or tool for this ? –  perror May 9 '13 at 15:45
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.