I'm using booktabs to display some profiling data. I would like to add bars to each row to visually indicate the quantities in one column.

I would like to use a table instead of a barchart since there are additional columns that don't require visualisation.


Screenshot from vtune illustrating what I am looking for.

Could I maybe draw inside a cell using tikz? Or do I need to abandon the table and wrangle a pgfplots barchart to look like a table?

  • 2
    just use \colorbox{\strut\hspace{1.14cm}} ... \colorbox{\strut\hspace{3.42cm}} – David Carlisle Apr 23 '14 at 13:38
  • You could also format a PGFPlots plot to neatly fit into the table. Compared to David's suggestion, this has the advantage of taking care of the scaling automatically. – Jake Apr 23 '14 at 15:17

How about something like this:

  #1s & {\color{red}\rule{#1cm}{8pt}}}


\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}\\


enter image description here

  • 1
    Awesome. I ended up adding some scaling. \pgfmathsetmacro{\len}{#1*0.04} – John Apr 25 '14 at 14:09
  • Where should I put \pgfmathsetmacro{\len}{#1*0.04} to add scale? – user3573959 May 14 '15 at 12:47

Example using TikZ:





\definecolor{chart Idle}{gray}{.6}
\definecolor{chart Poor}{RGB}{242,28,28}
\definecolor{chart Ok}{RGB}{248,172,37}
\definecolor{chart Ideal}{RGB}{1,151,0}
\definecolor{chart Over}{RGB}{0,125,234}

  \tikz[x=\tempdim, y=\tempdim]\draw(0,0) -- (.5,.5) -- (0,1) --cycle;%
  \ifdim\lastkern=1sp %
      inner sep=0pt,
      fill={chart #2},
      rounded corners=1pt,

  #1 & \ChartBox{55mm/3.420*#1}{#2}%
  \multirow{2}{*}{Source Function\,/\,Function\,/\,Call Stack}%
  \multicolumn{2}{c}{CPU Time by Utilization}\\
\multicolumn{1}{c}{}& \multicolumn{2}{l}{%
\relax[Loop at line 151 in \function{divergence_part_1}] &
  \chart{3.420}{Poor} \\
\relax[Loop at line 1071 in \function{radiation_fvm}] &
  \chart{3.270}{Poor} \\
\function{scalar_face_value} &
  \chart{3.090}{Poor} \\
\relax[Loop at line 102 in \function{get_match}] &
  \chart{1.700}{Poor} \\
\function{get_sensible_enthalpy_diff} &
  \chart{1.250}{Poor} \\
\function{compare_vec3} &
  \chart{1.140}{Poor} \\


  • I am utterly amazed at this faithful and beautiful reproduction. But I'm accepting the simpler solution. – John Apr 25 '14 at 14:10

Example using PGFPlots (adapted from Pgfplots: plot graph inside table) , which takes care of the scaling and lets you generate the table and graph from a datafile:


% The data file
% In a real application, this would be a text file in your file system
function,cpu time
Loop at line 151,3.42
Loop at line 107,3.27
Scalar face value,3.09
Loop at line 102,1.7
Get sensible enthalpy,1.25
Compare vec3,1.14

\pgfplotstableread[col sep=comma]{data.txt}\data

% Define the command for the plot
\begin{tikzpicture}[trim axis right]
  scale only axis,
  enlarge y limits={abs=0.5},
  axis y line*=middle,
  axis x line*=bottom,
  bar width=1.5ex,
  visualization depends on=x \as \rawx,
  nodes near coords,
  every node near coord/.style={
    shift={(axis direction cs:-\rawx,0)}

\addplot [draw=black, fill=red]
table [x=cpu time,y expr=\coordindex]{\data};


% Get number of rows in datafile

% Print the table
\pgfplotstabletypeset[columns={function, cpu time},
  % Booktabs rules
  every head row/.style={before row=\toprule,after row=\midrule},
  every last row/.style={after row=[3ex]\bottomrule},
  % Set header name
  columns/function/.style={string type,column type=l,column name=Function},
  columns/cpu time/.style={
    column name={CPU Time},
    assign cell content/.code={% use \multirow for Z column:
    \pgfkeyssetvalue{/pgfplots/table/@cell content}
    \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.