如何在表格中的条形图中添加比例

如何在表格中的条形图中添加比例

我有以下包含条形图的表格。我想在条形图底部添加刻度(x 轴)。

有人能指导我如何在 LaTeX 中实现这一点吗?

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

答案1

她使用 TikZ 给出了一个快速而粗略的答案,我认为困难在于避免由于数字宽度而导致轴偏移。也许一些 TikZ 专家会找到一种更简洁的方法来做到这一点。

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{array}
\usepackage{xcolor}
\usepackage{tikz}
    \usetikzlibrary{calc}
\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}\\
 using tikzscalar face value               & \mybar{3.090}\\
Loop at line 102 in get         & \mybar{1.700}\\
get sensible enthalpy           & \mybar{1.250}\\
&& \begin{tikzpicture}
    \draw[->] (0,0) -- (4.5,0);
    \foreach \x in {0,1,...,4}
      \draw[thin] (\x,0) -- (\x,-0.1);
    \foreach \x in {0,1,...,4}    
      \node at ({\x+0.15}, {0-0.1}) [below] {\x};
\end{tikzpicture}\\
\end{tabular}

\end{document}

在此处输入图片描述

相关内容