我想知道如何在 (La)TeX 中为具有固定/已知列宽的表格创建以下列。我一直在尝试彩色盒子但我找不到让文本位于彩色框上方(而不是内部)的方法。
答案1
我认为你应该寻找pgfplots
或pgfplotstable
(也在 pgfplots 中)包,但如果您更喜欢手动完成,这可能是一个起点:
\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
% #1 - column width (3cm by default)
% #2 - value to be shown
% #3 - maximum value in column
\newcommand{\mybar}[3][3cm]{
\begin{tikzpicture}
\node[minimum width=#1] (top) {#2};
\node[draw=green!80!black, fill=green!30, minimum width={(#2/#3)*#1}, below right=0pt of top.south west] {};
\end{tikzpicture}
}
\begin{document}
\begin{tabular}{cc}
\mybar{0.54040399}{0.605198872} & \mybar{0.33004729}{0.33004729} \\
\mybar{0.53584356}{0.605198872} & \mybar{0.31441314}{0.33004729} \\
\mybar{0.30299224}{0.605198872} & \mybar{0.24153336}{0.33004729} \\
\mybar{0.605198872}{0.605198872} & \mybar{0.22097618}{0.33004729}
\end{tabular}
\end{document}