Hi I am quite new to latex, but loving it so far. I am using Rmarkdown with xtable to create a table with a graph at the end.
A question was asked two years ago - Is it possible to create a barchart in a table? - on how to create a barchart inside a table. It worked perfectly.
My question: Can I put a number after the graph?
A solution by A.Ellett looked like this:

And the solution was:
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{array}
\usepackage{xcolor}
\def\mybar#1{%%
#1s & {\color{red}\rule{#1cm}{8pt}}}
\pagestyle{empty}
\begin{document}
\begin{tabular}{>{$\rhd$ }lrl}
Loop at line 151 in divergence & \mybar{3.420}\\
Loop at line 1071 in radiation & \mybar{3.270}\\
scalar face value & \mybar{3.090}\\
Loop at line 102 in get & \mybar{1.700}\\
get sensible enthalpy & \mybar{1.250}\\
\end{tabular}
\end{document}
Here he adds a new column with the values. Xtable had a problem with this extra column due to aligning. Can this be done without the extra column?
My solution so far:
The latex header:
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{array}
\usepackage{xcolor}
\definecolor{blueColor}{rgb}{0,.30667,.55111}
\def\mybar#1{%%
{\color{blueColor}\rule{#1mm}{9pt}}} %I only want the bar, not the extra column
The xtable solution:
align <- paste0(c("L{4cm}", rep("C{15mm}", 4), "L{3cm}"), collapse = "")
latexGraph <- function(x) gsub('GRAPH(.*)',paste('\\\\mybar{\\1}'),x)
print(xtable(x, align=align, auto = TRUE),
sanitize.text.function = latexGraph) #To add the graph to the table
How my function works now is: I have a column with numbers for example (1, 2, 3, 4, 5). To change those numbers to a graph, I change these numbers to: GRAPH1, GRAPH2, GRAPH3, GRAPH4, GRAPH5.
Xtable then uses my function (latexGraph) to 'sanatize' this column. The function changes the GRAPH4 to \mybar{\4}.




tikzis the easiest way. – Guilherme Zanotelli Sep 19 '16 at 07:07