用于写入数据的全宽表

用于写入数据的全宽表

我知道这里和那里有大量的全宽表格问题,我希望这不会被视为重复,但我需要有这个表格并写出有机化学实验室的答案,但似乎无法拉伸列。

任何建议或为我指明正确方向都非常感谢。到我毕业时,我想我会把这一切都解决掉!

前言

\documentclass{article}

\usepackage[letterpaper, portrait, margin=2cm]{geometry}
\usepackage[english]{babel}
\usepackage[protrusion=true,expansion=true]{microtype}  
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage[utf8]{inputenc}
\pagenumbering{roman}
\usepackage{graphicx}
\usepackage[svgnames,table,xcdraw,dvipsnames]{xcolor} 
\usepackage[version=3]{mhchem}
\usepackage{chemfig}
\usepackage{gensymb}
\usepackage[most]{tcolorbox}
\usepackage{multirow}

桌子

% There are two more below this but the one should give me a grasp for the others

\section*{Data Tables}

\begin{table}[h]
\begin{tabular}{|l|l|l|l|l|}
\hline
               & \multicolumn{4}{c|}{\textbf{Test}}                                                            \\ \cline{2-5} 
\multirow{-2}{*}{} & \multicolumn{2}{l|}{Density/Solubility} &     \multicolumn{2}{l|}{Flammability}      \\ \hline
Compound           & Observation  & Conclusion               & Observation &     Conclusion               \\ \hline
Cyclohexane        &              & \cellcolor[HTML]{9B9B9B} &             &     \cellcolor[HTML]{9B9B9B} \\ \hline
Cyclohexene        &              & \cellcolor[HTML]{9B9B9B} &             &     \cellcolor[HTML]{9B9B9B} \\ \hline
Toluene            &              & \cellcolor[HTML]{9B9B9B} &             & \cellcolor[HTML]{9B9B9B} \\ \hline
Unknown \#           &              &                          &             &                          \\ \hline
Unknown \#           &              &                          &             &                          \\ \hline
\end{tabular}
\end{table}

我现在拥有的

基本上,现在的桌子宽度是 10.5 厘米。我希望它能再延伸 8 厘米,这样我就有空间在所有单元格中书写。

答案1

tabularx确保全宽的解决方案。该makecell包允许换行和单元格的通用格式,特别是内容的默认位置是垂直和水平居中:

\documentclass{article}

\usepackage[letterpaper, portrait, margin=2cm, showframe]{geometry}
\usepackage[english]{babel}
\usepackage[protrusion=true,expansion=true]{microtype}
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage[utf8]{inputenc}
\pagenumbering{roman}
\usepackage{graphicx}
\usepackage[svgnames,table,xcdraw,dvipsnames]{xcolor}
\usepackage[version=3]{mhchem}
\usepackage{chemfig}
\usepackage{gensymb}
\usepackage[most]{tcolorbox}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{makecell}

\begin{document}
% There are two more below this but the one should give me a grasp for the others

\section*{Data Tables}

\begin{table}[h]
\renewcommand\arraystretch{1.25}
\begin{tabularx}{\linewidth}{|l|*{3}{X|>{\arraybackslash}X|}}
\hline
& \multicolumn{4}{c|}{\textbf{Test}} \\
\cline{2-5}
\multirow{-2}{*}{} & \multicolumn{2}{c|}{Density/Solubility} & \multicolumn{2}{c|}{Flammability} \\
\hline
Compound & \makecell{Observation} & \makecell{Conclusion} & \makecell{Observation} & \makecell{Conclusion} \\
\hline
Cyclohexane & & \cellcolor[HTML]{9B9B9B} & & \cellcolor[HTML]{9B9B9B} \\
\hline
 Cyclohexene & & \cellcolor[HTML]{9B9B9B} & & \cellcolor[HTML]{9B9B9B} \\
 \hline
 Toluene & & \cellcolor[HTML]{9B9B9B} & & \cellcolor[HTML]{9B9B9B} \\
 \hline
 Unknown \# & & & & \\
 \hline
 Unknown \# & & & & \\
 \hline
\end{tabularx}
\end{table}

\end{document} 

在此处输入图片描述

答案2

使用p列类型来指定列宽。参数是列的宽度。

\documentclass{article}

\usepackage[letterpaper, portrait, margin=2cm]{geometry}
\usepackage[english]{babel}
\usepackage[protrusion=true,expansion=true]{microtype}  
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage[utf8]{inputenc}
\pagenumbering{roman}
\usepackage{graphicx}
\usepackage[svgnames,table,xcdraw,dvipsnames]{xcolor} 
\usepackage[version=3]{mhchem}
\usepackage{chemfig}
\usepackage{gensymb}
\usepackage[most]{tcolorbox}
\usepackage{multirow}

\begin{document}
% There are two more below this but the one should give me a grasp for the others

\section*{Data Tables}

\begin{table}[h]
\begin{tabular}{|l|p{3cm}|p{3cm}|p{3cm}|p{3cm}|}
\hline
               & \multicolumn{4}{c|}{\textbf{Test}}                                                            \\ \cline{2-5} 
\multirow{-2}{*}{} & \multicolumn{2}{l|}{Density/Solubility} &     \multicolumn{2}{l|}{Flammability}      \\ \hline
Compound           & Observation  & Conclusion               & Observation &     Conclusion               \\ \hline
Cyclohexane        &              & \cellcolor[HTML]{9B9B9B} &             &     \cellcolor[HTML]{9B9B9B} \\ \hline
Cyclohexene        &              & \cellcolor[HTML]{9B9B9B} &             &     \cellcolor[HTML]{9B9B9B} \\ \hline
Toluene            &              & \cellcolor[HTML]{9B9B9B} &             & \cellcolor[HTML]{9B9B9B} \\ \hline
Unknown \#           &              &                          &             &                          \\ \hline
Unknown \#           &              &                          &             &                          \\ \hline
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

相关内容