0

I have needed to put (magnitude) bars next to numbers in tables. For this task I found this solution fantastic: Is it possible to create a barchart in a table? I have relied on this a number of times.

The problem I'm encountering now though is that my numbers are pretty small and I would like to scale them up, so readers can better judge the magnitude of my numbers. I have tried using larger units. Inches seems to be the largest unit in Latex and that still won't give me large enough bars.

In the link to the solution user3573959 seems to have the same problem. But his questions has remains unanswered. I tried a few places to plug the scale into that the original poster of the original question (John) provided -- without success. Find a MWE below, the bit that is intended to provide the scaling (according to user3573959) is commented out for now.

Any help will be much appreciated. Thanks in advance!

\documentclass[t]{beamer}
\mode<presentation>
{
  \usetheme{default}
  \usecolortheme{default}
  \usefonttheme{default}
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{footline}[frame number]
  \setbeamertemplate{caption}[numbered]
} 
%\pgfmathsetmacro{\len}{#1*5}
\def\mybar#1{%%
  #1\% & {\color{lightgray}\rule{#1in}{8pt}}}

\begin{document}
\begin{frame}
\begin{block}

\tiny
\begin{tabular}{l|l|lll|lll}
Decade&Wordcount&\multicolumn{3}{|c|}{item01}&\multicolumn{3}{|c}{item02}\\
    &   & N &   \multicolumn{2}{c|}{freq}    & N    & \multicolumn{2}{c}{freq} \\\hline
1800&119589&33 & \mybar{0.02759}&9 & \mybar{0.00753}\\
1810&154930&64 & \mybar{0.04131}&11 & \mybar{0.0071}\\
1820&85511&49 & \mybar{0.0573}&15 & \mybar{0.01754}\\
1830&164233&94 & \mybar{0.05724}&32 & \mybar{0.01948}\\
\end{tabular}
\end{block}

\end{frame}

\end{document}
Mat
  • 197

1 Answers1

1

Simply use \dimexpr in your definition of \mybar:

\documentclass[t]{beamer}
\mode<presentation>
{
  \usetheme{default}
  \usecolortheme{default}
  \usefonttheme{default}
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{footline}[frame number]
  \setbeamertemplate{caption}[numbered]
}
%\pgfmathsetmacro{\len}{#1*5}
\def\mybar#1{%%
  #1\% & {\color{lightgray}\rule{\dimexpr#1in*14\relax}{8pt}}}

\begin{document}
\begin{frame}
\tiny
\begin{tabular}{l|l|lll|lll}
Decade&Wordcount&\multicolumn{3}{|c|}{item01}&\multicolumn{3}{|c}{item02}\\
    & & N & \multicolumn{2}{c|}{freq} & N & \multicolumn{2}{c}{freq} \\\hline
1700&10097&6 & \mybar{0.05942}&2 & \mybar{0.01981}\\
1710&141251&43 & \mybar{0.03044}&3 & \mybar{0.00212}\\
1720&171035&47 & \mybar{0.02748}&16 & \mybar{0.00935}\\
1730&96002&17 & \mybar{0.01771}&19 & \mybar{0.01979}\\
1740&190771&64 & \mybar{0.03355}&3 & \mybar{0.00157}\\
1750&116881&67 & \mybar{0.05732}&4 & \mybar{0.00342}\\
1760&195612&66 & \mybar{0.03374}&9 & \mybar{0.0046}\\
1770&145412&66 & \mybar{0.04539}&16 & \mybar{0.011}\\
1780&189086&104 & \mybar{0.055}&8 & \mybar{0.00423}\\
1790&206106&89 & \mybar{0.04318}&22 & \mybar{0.01067}\\
1800&119589&33 & \mybar{0.02759}&9 & \mybar{0.00753}\\
1810&154930&64 & \mybar{0.04131}&11 & \mybar{0.0071}\\
1820&85511&49 & \mybar{0.0573}&15 & \mybar{0.01754}\\
1830&164233&94 & \mybar{0.05724}&32 & \mybar{0.01948}\\
1840&228263&101 & \mybar{0.04425}&36 & \mybar{0.01577}\\
1850&138121&78 & \mybar{0.05647}&18 & \mybar{0.01303}\\
1860&155562&78 & \mybar{0.05014}&21 & \mybar{0.0135}\\
1870&119327&72 & \mybar{0.06034}&24 & \mybar{0.02011}\\
1880&168688&64 & \mybar{0.03794}&7 & \mybar{0.00415}\\
1890&143624&72 & \mybar{0.05013}&24 & \mybar{0.01671}\\
1900&117377&52 & \mybar{0.0443}&10 & \mybar{0.00852}\\
1910&121755&76 & \mybar{0.06242}&13 & \mybar{0.01068}\\\hline
all: &3179233&1402&\mybar{0.0441}&322&\mybar{0.01013}\\
\end{tabular}

\end{frame}

\end{document} 

enter image description here

Bernard
  • 271,350