如何设置固定宽度的列? [英] How to set the fixed width of columns?
问题描述
大家好,我在乳胶上创建表格的代码如下:
Hello everyone I am creating a table on latex my code looks like this:
\begin{table}[H]
\centering
\caption{caption}
\label{my-label}
\begin{tabular}{lll}
\hline
\multicolumn{3}{|c|}{\cellcolor[HTML]{34CDF9}{\color[HTML]{000000} Matriz confusión Genero.}} \\ \hline
\multicolumn{1}{|l|}{} & \multicolumn{1}{l|}{M} & \multicolumn{1}{l|}{F} \\ \hline
\multicolumn{1}{|l|}{M} & \multicolumn{1}{l|}{43} & \multicolumn{1}{l|}{7} \\ \hline
\multicolumn{1}{|l|}{F} & \multicolumn{1}{l|}{11} & \multicolumn{1}{l|}{39} \\ \hline
\end{tabular}
\end{table}
它运作良好,但是当我尝试固定尝试的列的宽度时出现问题:
It works well but the problem comes when I try to fix the width of the columns I tried:
\begin{tabular}{l{2cm}|l{2cm}|l{2cm}}
结果是同一张表,但列的长度可变,我想固定列的长度,我想感谢解决此问题的任何建议.
The result is the same table, with variable length of columns, I would like to fix the length of the columns, I would like to appreciate any suggestion to solve this problem.
推荐答案
请考虑以下代码:
\documentclass[a4paper]{article}
\usepackage{}
\begin{document}
\begin{table}%[H]
\centering
\caption{caption}
\label{my-label}
\begin{tabular}{|p{20mm}|p{15mm}|p{10mm}|}
\hline
% \multicolumn{3}{|c|}{\cellcolor[HTML]{34CDF9}{\color[HTML]{000000} Matriz confusión Genero.}} \\ \hline
\multicolumn{3}{|c|}{Matriz confusión Genero.} \\ \hline
& M & F \\ \hline
M & 43 & 7 \\ \hline
F & 11 & 39 \\ \hline
\end{tabular}
\end{table}
\end{document}
输出下表:
您可能对该行特别感兴趣
You may be interested in particular in the line
\begin{tabular}{|p{20mm}|p{15mm}|p{10mm}|}
实现 段落对齐具有给定宽度(分别为20、15和10毫米)的列.
implementing paragraph alignment for the contents of a column of given width (here 20, 15 and 10 mm respectively).
为简化起见,您应该摆脱所有这些\multicolumn{1}{}{}
并进行更改
To make it simpler, you should just get rid of all of those \multicolumn{1}{}{}
and change
\begin{tabular}{l{2cm}|l{2cm}|l{2cm}}
到
\begin{tabular}{|p{2cm}|p{2cm}|p{2cm}|}
这篇关于如何设置固定宽度的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!