我正在尝试将下表放入 Sharelatex 中:
我知道如何制作基本表格,但我发现制作像上面这样的表格很难,因为某些行的列有所不同。这是我到目前为止的代码:
\begin{table}[h]
\begin{tabular}{|m{4cm}|m{4cm}|m{4cm}|m{4cm}|m{4cm}|m{4cm}}
\hline
\multicolumn{4}{|c|}{Display Format} \\
\hline
&High information-density & Low information-density & \\
\hline
\end{tabular}
\caption{Number of respondents per treatment}
\label{table:3}
\end{table}
但是这并没有提供我想要的表格,我真的被困在这里了。有人能帮我解决这个问题吗?
答案1
尝试这个:
\documentclass{article}
\usepackage{sans}
\renewcommand{\arraystretch}{1.3}
\begin{document}
\begin{table}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
& \multicolumn{4}{|c|}{Display Format}& \\ \cline{2-5}
&\multicolumn{2}{|c|}{High information density}& \multicolumn{2}{|c|}{Low information density} &\\ \hline
Cookie type & Noticeable& Non-noticeable& Noticeable& Non-noticeable& Total \\ \hline
1\textsuperscript{st} - party cookies&29&17&27&20&93\\ \hline
1\textsuperscript{st}/3\textsuperscript{rd} party cookies&19&22&23&20&84\\ \hline
Total& 48&39&50&40&177\\ \hline
\end{tabular}
\caption{Number of respondants for treatment}
\end{table}
\end{document}
以及通过上述代码获得的表格图像:
答案2
你的桌子将会非常大......宽 24 厘米 :)- 看看以下内容是否是你想要的:
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{table}[h]
\renewcommand\arraystretch{1.3}
\begin{tabular}{|l | *{4}{>{\centering}p{2cm}|}c|}
%{|m{4cm}|m{4cm}|m{4cm}|m{4cm}|m{4cm}|m{4cm}}
\hline
& \multicolumn{4}{c|}{Display Format}
& \\
\hline
Cookie type
& \multicolumn{2}{c|}{High information-density}
& \multicolumn{2}{c|}{Low information-density}
& Total \\
\hline
1\textsuperscript{st} party cookies
& 29 & 17 & 27 & 20 & 93 \\
\hline
\end{tabular}
\caption{Number of respondents per treatment}
\label{table:3}
\end{table}
\end{document}
答案3
以下代码生成您的表格。\multicolumn
用于跨越多列。如果四个中心列不必等宽,则不需要包array
和新列类型C
;只需使用类型c
。
\documentclass[border=2pt]{standalone}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\renewcommand\familydefault{\sfdefault}
\begin{document}
{\def\arraystretch{1.2}%
\begin{tabular}{|c|C{2.3cm}|C{2.3cm}|C{2.3cm}|C{2.3cm}|c|}
\hline
&\multicolumn{4}{c|}{Display Format}{}&\\
\cline{2-5}
&\multicolumn{2}{c|}{High information density}&\multicolumn{2}{c|}{Low information density}&\\
\hline
Cookie Type & Noticeable & Non-noticeable & Noticeable & Non-noticeable & Total \\
\hline
1st party cookies & 29 & 17 & 27 & 20 & 93 \\
\hline
1st/3rd party cookies & 19 & 22 & 23 & 20 & 84 \\
\hline
Total & 48 & 39 & 50 & 40 & 177 \\
\hline
\end{tabular}}
\end{document}