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 am a beginner in Latex, using it tentatively for industrial documents. I have reached a point where the anticipated benefits from using it in a Corporate environment appear to me very significant. I am trying to write a paper explaining this to my company. I have made a quick comparison in the table of the MWE below. However, (in order to demonstrate a unique capability of LaTex) I would like to illustrate the point by a bar chart, possibly generated on the fly from the raw data I would embed in the Latex source. I have been trying to use \pgfplotstableread and \pgfplotstabletypeset to generate the table instead of the tabular option, but I could not succeed, probably due to the white spaces of the text.

  1. Could someone suggest a way to generate such a table outside of a tabular environment? Some reformatting of the text contents of the table is possible if there is no other way.
  2. Is there a way to generate a bar chart illustrating the point of file size without manually entering the coordinates?
  3. As a side request, could someone perhap suggest a presentation format that would provide the maximum evidence of the point illustrated?

    \documentclass[11pt]{article}
    \usepackage{graphicx}
    \usepackage{siunitx}
    \usepackage{pgfplotstable}
    \sisetup{table-figures-decimal = 3}
    \sisetup{table-number-alignment=center-decimal-marker}
    \begin{document}
    \centering
    \begin{table}
    \begin{tabular}{|l|S|S|}
    File type&{Word 2003}&{\LaTeX} \\
    \hline
    Native file size (Mo)& 1.07&.112\\
    Compressed native file size (Mo)&.268 & 0.022\\
    Final PDF file size (Mo) &.302& .272\\
    \end{tabular}
    \caption{Comparison of file size Word 2003 vs \LaTeX}
    \end{table}
    \end{document} 
    
share|improve this question
    
Please have a look at this answer which is a pretty nice demonstration and creates the data file on the fly with filecontents package. And for the presentation you can always use beamer package. –  percusse Mar 29 '12 at 20:37
add comment

1 Answer

up vote 7 down vote accepted

You can generate a table and chart from basically any comma (or otherwise) delimited datafile. Here's an example for how your datapoints could be presented. I've chosen to transpose your datafile for the table, based on the idea that the numbers you want your audience to compare should be underneath each other, not next to each other. The transposition is done using \pgpflotstabletranspose.

I've made this example a bit fancy to show what can be done using \pgfplotstable. In a production environment, the code could be cleaned up a lot to use styles.

The datafile in this example is created using filecontents. In a real application, the CSV file would of course just live on the disk and be read by the TeX file.

In terms of the most effective presentation for this particular point, I think a simple column chart would be the most sensible choice, since it allows for a simple comparison of the pairs of data.

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{siunitx}
\usepackage{pgfplotstable}
\sisetup{
    table-figures-decimal = 3,
    table-number-alignment=center-decimal-marker
}
\usepackage{filecontents}
\usepackage{booktabs}

\begin{filecontents}{data.csv}
{File type},{Word 2003},{LaTeX}
Native,1.07,.112
Compressed native,.268,.022
Final PDF,.302,.272
\end{filecontents}

\pgfplotstableread[col sep=comma]{data.csv}{\datatable}
\pgfplotstabletranspose[colnames from=File type, input colnames to=File Type]{\transposed}{\datatable}

\begin{document}
\begin{table}
\centering
\pgfplotstabletypeset[
    string type,
    every head row/.style={
        before row={\toprule & \multicolumn{3}{c}{File size (Mo)}\\},
        after row=\midrule
    },
    every last row/.style={after row=\bottomrule},
    multicolumn names,
    display columns/0/.style={
        multicolumn names=l,
        column name={},
        column type=l
    },
    display columns/1/.style={column type=S},
    display columns/2/.style={column type=S},
    display columns/3/.style={column type=S},
    every row 0 column 0/.style={
        postproc cell content/.style={
            @cell content=\textcolor{cyan!50!black}{\textbf{##1}}
        }
    },
    every row 1 column 0/.style={
        postproc cell content/.style={
            @cell content=\textcolor{orange!75!black}{\textbf{##1}}
        }
    }
]{\transposed}
\caption{Comparison of file size Word 2003 vs \LaTeX}
\end{table}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
    ybar,
    xtick=data,
    xticklabels from table={\datatable}{[index]0},
    enlarge y limits=upper,
    ymin=0,
    ylabel=File size (Mo),
    legend entries={Word 2003, \LaTeX}
]
\addplot [fill=cyan!70, draw=cyan!50!black]  table [
    x expr=\coordindex,
    y index=1] {\datatable};
\addplot[fill=orange, draw=orange!50!black] table [
    x expr=\coordindex,
    y index=2] {\datatable};
\end{axis}
\end{tikzpicture}
\caption{Graphical comparison of file size Word 2003 vs \LaTeX}
\end{figure}
\end{document}
share|improve this answer
    
Thanks a lot. This is beautiful, and is a neat practical demo of one of the points I am trying to convey, ie that the direct translation of raw data from either a data file or from data embedded into the latex source is a leaner process than using a spreadsheet, making a graph, then pasting the graph into a word processor...and repeating th eloop a few times for adjusments... This approach of course implies skills that require some efforts and time to learn, as my difficulties to find a solution on my own illustrate... –  Yves Mar 30 '12 at 14:42
    
I seem to have an error message "missing number, treated as zero that I cannot figure out how to solve, with line:\pgfplotstabletranspose[colnames from=File type, input colnames to=File Type]{\transposed}{\datatable} –  Yves Mar 30 '12 at 15:42
    
Does that error occur if you just copy and paste the code from my answer? In that case, you might be using an old version of PGFplots (you can check your version by using \listfiles in your preamble and then looking at the end of the .log file). You'll want version 1.5.1 of PGFplots. –  Jake Mar 30 '12 at 15:50
    
Yes. Thanks. I have tried to investigate, but I am not competent for the job...I will check the version. This might be the problem, but I have tried in my office also, where I use a fairly recent installation, another platform, and I had the same difficulty. –  Yves Mar 30 '12 at 16:07
    
I use version 1.4.1 of pgfplot on my home computer. You were right...I am going to try to update. This will be an excellent exercise... –  Yves Mar 30 '12 at 16:09
show 7 more comments

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.