我使用Excel2Latex
插件并得到以下代码(我包含了调整框来缩放表格):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{todonotes}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{adjustbox}{max width=0.77\textwidth}
\begin{tabular}{lrrr}
\textcolor[rgb]{ .635, .482, .208}{} & \textcolor[rgb]{ .718, .353, .133}{\textbf{One}} & \textcolor[rgb]{ 0, .69, .314}{\textbf{Two}} & \multicolumn{1}{p{5.625em}}{\textcolor[rgb]{ 0, .439, .753}{\textbf{Three and Four}}} \\
\midrule
This is wat i want to test in latex test test test test test test test test test & \textcolor[rgb]{ .718, .353, .133}{3.5} & \textcolor[rgb]{ 0, .69, .314}{3.0} & \textcolor[rgb]{ 0, .439, .753}{2.0} \\
\end{tabular}%
\end{adjustbox}
\label{tab:addlabel}%
\end{table}%
\end{document}
Latex 结果中有两处错误:(i) 列宽不等(“一”、“二”、“三和四”)和 (ii) 这些单元格未在右下角对齐。我尝试更改
\multicolumn{1}{p{5.625em}
到
\multicolumn{1}{r}
但它不起作用。如果有人能帮助我就太好了。
答案1
使用该
array
包,您可以定义一种新的列类型,该列类型具有固定宽度并将单元格与底部对齐:\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}b{#1}}
我建议不要缩放包含文本的元素,否则会导致字体大小不合适。您可以使用较小的字体大小,而不是像以下示例那样包装第一列的内容:
\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{array}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}b{#1}}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabularx}{.77\linewidth}{
X
>{\color{red}}R{1.6cm}
>{\color{green}}R{1.6cm}
>{\color{blue}}R{1.6cm}
<{\color{black}}
}
\toprule
& One & Two & Three and Four \\
\midrule
This is wat i want to test in latex test test test test test test test test test & 3.5 & 3.0 & 2.0 \\
\bottomrule
\end{tabularx}%
\label{tab:addlabel}%
\end{table}%
\end{document}