如何制作具有多行和多列的表格

如何制作具有多行和多列的表格

我想要制作下表: 在此处输入图片描述

这是我尝试执行的代码,但它已经不起作用了,而且我很难弄清楚如何将这些多列与多行结合起来

\begin{landscape}
\begin{table}[ht]
\centering
 \begin{small}
  \begin{tabular}{|l|l|l|l|l|l|}
 \hline
& \multicolumn{8} {c|}{} & {\bfseries  Age} &{\bfseries Gender}  & {\bfseries Education}\\
\cline{2-4}
 & Mean & SD& Male &Female & SD & Male&High school &Undergraduate& Master or higher&Other\\
\hline
\end{tabular}
\end{table}
\end{landscape}

有人可以帮忙吗?

答案1

要更改字体大小,您可以使用\tiny\small其他大小。这里不需要使用环境,因为 -environmenttable会将字体大小仅分组到该表,而不会影响文档的其余部分。其他字体大小以及有关它们的一些信息可以在帖子中找到\Large 等字体大小是多少点(pt)?

当创建相同类型的多个列时,写成*{11}{l}而不是更简单lllllllllll,而且读起来也容易得多。当然,你可以组合这些方法,写成 `c*{4}{l}rr。

请注意,我没有输入图像中所代表的数字,我只是复制了第一行。

我建议不要这样使用表格。我会尝试缩小表格宽度,这样就不会有太多空白,并且可以在纵向模式下排版,删除垂直线,可能将数据拆分为多个表格。Mico 还建议使用不同的字体大小,并减少列之间的间距,我同意。我已将这些建议作为示例。当然可以进一步改进。

输出

在此处输入图片描述

建议输出

在此处输入图片描述

没有建议的代码

\documentclass[11pt]{article}
\usepackage{lscape}
\usepackage{multirow}
\begin{document}
\begin{landscape}
\begin{table}[ht]
\centering
\tiny
\begin{tabular}{*{11}{|l}|}
\hline
\multicolumn{3}{|c|}{} & \multicolumn{2}{c|}{\bfseries  Age} &\multicolumn{2}{c|}{\bfseries  Gender}  & \multicolumn{4}{|c|}{\bfseries  Education}\\
\cline{4-11}
\multicolumn{3}{|c|}{}& Mean & SD & Male & Female & High school & Undergraduate & Master or higher & Other\\
\cline{6-11}
\multicolumn{3}{|c|}{}&& & Count & Count & Count & Count & Count & Count\\
\hline
1st party & High information& Noticable & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
cookies & density & Non-noticable & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\cline{2-11}
    & \multirow{2}{*}{Low information density}& Noticable & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
&& Non-noticable & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\hline
1st/3rd party& High information & Noticable & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
cookies & density & Non-noticable & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\cline{2-11}
    & \multirow{2}{*}{Low information density}& Noticable & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
&& Non-noticable & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\hline
\end{tabular}
\end{table}
\end{landscape}
\end{document}

建议代码

\documentclass[11pt]{article}
\usepackage{lscape}
\usepackage{multirow}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{threeparttable}


\newcommand{\minitab}[2][l]{\begin{tabular}{#1}#2\end{tabular}}

\newcommand{\tableHeader}[1]{{\bfseries #1}}
\begin{document}
\begin{table}[ht]
\centering
\setlength{\tabcolsep}{3pt}
\scriptsize

\caption{Number of students enjoying cookies}

\begin{tablenotes}
    \item Abbreviations: HS: Highschool, U: Undergratuate, M+: Master degree or higher
\end{tablenotes}

\begin{tabular}{*{3}{l}*{8}{c}}
\addlinespace
\toprule
\multicolumn{3}{c}{} & \multicolumn{2}{c}{\tableHeader{Age}} &\multicolumn{2}{c}{\tableHeader{Gender}}  & \multicolumn{4}{l}{\tableHeader{Education}}\\
\cmidrule{4-11}
& && & & M & F & HS & U & M+ & O\\
\cmidrule{6-11}
\tableHeader{Cookies} & \parbox[b][1ex]{2cm}{\tableHeader{Information Density}} & \tableHeader{Noticable} & \tableHeader{Mean} & \tableHeader{SD} & \multicolumn{5}{l}{\tableHeader{Number of students}} \\
\midrule
\multirow{4}{*}{\bfseries 1st party} & High & Yes & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
& & No & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\addlinespace
    & Low & Yes & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
&& No & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\hline
\multirow{4}{*}{\bfseries 1st/3rd party} & High & Yes & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
&  & No & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\addlinespace
    & Low & Yes & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
&  & No & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\bottomrule
\end{tabular}
\begin{tablenotes}
    \item *Records may not be correct as it was reported that many students thought the survey was regarding consumable cookies, and not internet-cookies
\end{tablenotes}
\end{table}
\end{document}

答案2

我会重新组织表格,使单元格包含更少的重复信息,并将这些信息放在表格的标题中。我还会重新排列标题材料以减少列的宽度;这反过来又允许使用更大的字体大小,这将受到读者的赞赏。顺便说一句,如果标题设计得当,就没有必要使用大胆的以引起对某些标题单元格的注意。最后,我让表格看起来更加开放(通过省略所有垂直条和大多数水平条)。

在此处输入图片描述

\documentclass[11pt]{article}
\usepackage{rotating,booktabs}
\begin{document}
\begin{sidewaystable}[t!]
\centering
\small % no need for \tiny or \scripsize
\begin{tabular}{@{}l *{10}{c}@{}}
\toprule
Cookies & Information density & Noticeable? % ?
& \multicolumn{2}{c}{Age} 
& \multicolumn{2}{c}{Gender (Count)}  
& \multicolumn{4}{c@{}}{Education (Count)}\\
\cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(l){8-11}
&& & Mean & SD & Male & Female 
   & High  & Under- & Master's  & Other\\
   &&&&&&& school & graduate & or higher \\
\midrule
1st party 
& High & Yes & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
&      & No  & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\addlinespace
& Low  & Yes & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
&      & No  & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\addlinespace
1st/3rd party
& High & Yes & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
&      & No  & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
\addlinespace
& Low  & Yes & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\
&      & No  & 35 & 12 & 12 & 17 & 9 & 11 & 9 & 0\\ 
\bottomrule
\end{tabular}
\end{sidewaystable}
\end{document}

答案3

另一种变体,带有一些命令作为快捷方式和makecell包。字体大小更易读\footnotesize

        \documentclass[11pt]{article}
        \usepackage[showframe]{geometry} %
        \usepackage{multirow, array, rotating, makecell, cellspace}
        \setlength\cellspacetoplimit{4pt}
        \setlength\cellspacebottomlimit{4pt}


            \newcommand\HighInf{\makecell[lc]{High information\\ density}}
            \newcommand\LowInf{\makecell[lc]{Low information\\ density}}
            \newcommand\NonNot{\ensuremath{\biggl[\begin{tabular}{l@{}}Noticeable \\[0.5ex] Non-noticeable\end{tabular}}}

        \begin{document}

        \begin{sidewaystable}[!ht]
        \centering
        \setlength\tabcolsep{3.5pt}
        \footnotesize
        \begin{tabular}{|lcc*{8}{|Sc}|}
        \hline
        \multicolumn{3}{|c|}{} & \multicolumn{2}{Sc|}{\bfseries Age} &\multicolumn{2}{c|}{\bfseries Gender} & \multicolumn{4}{c|}{\bfseries Education}\\
        \cline{4-11}
        \multicolumn{3}{|c|}{}& Mean & SD & Male & Female & High school & \makecell{Undergraduate\\ level} & \makecell{Master degree\\ or higher} & Other\\
        \cline{6-11}
        \multicolumn{3}{|c|}{}&& & Count & Count & Count & Count & Count & Count\\
        \hline
        \makecell{1st party\\ cookies} & \HighInf & \NonNot & \makecell{35\\35} & \makecell{12\\12} & \makecell{12\\12} & \makecell{17\\17} & \makecell{9\\9} & \makecell{11\\11} & \makecell{9\\9} & \makecell{0\\0} \\[2ex]
            & \LowInf & \NonNot & \makecell{35\\35} & \makecell{12\\12} & \makecell{12\\12} & \makecell{17\\17} & \makecell{9\\9} & \makecell{11\\11} & \makecell{9\\9} & \makecell{0\\0} \\%
             & & & & & & & & & & \\[-2ex]
        \hline & & & & & & & & & & \\[-2ex]
        \makecell{1st/3rd party\\ cookies}& \HighInf & \NonNot & \makecell{35\\35} & \makecell{12\\12} & \makecell{12\\12} & \makecell{17\\17} & \makecell{9\\9} & \makecell{11\\11} & \makecell{9\\9} & \makecell{0\\0} \\
            & \LowInf & \NonNot & \makecell{35\\35} & \makecell{12\\12} & \makecell{12\\12} & \makecell{17\\17} & \makecell{9\\9} & \makecell{11\\11} & \makecell{9\\9} & \makecell{0\\0} \\
        \hline
        \end{tabular}
        \end{sidewaystable}

        \end{document} 

在此处输入图片描述

答案4

\documentclass{article}
\usepackage{multirow}
\usepackage{lscape}
\textheight=in
\begin{document}
\begin{landscape}
%11 columns
\begin{tabular}{|c|c|c|c|c|c|c|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}\hline
a & b & c & d & e &  f & g & h & i & j & k\\\hline
\multicolumn{3}{|c|}{\multirow{3}{*}{}}&\multicolumn{2}{|c|}{Age}& \multicolumn{2}{|c|}{Gender}&\multicolumn{4}{|c|}{Education}\\\cline{4-11}
 \multicolumn{3}{|c|}{}& Mean & SD &Male&Female&High School&Under graduate level&Master's degree or Higher&other\\\cline{6-11}
\multicolumn{3}{|c| }{}&  &  & count &
count
& count & count &count & count\\\hline


\multirow{4}{*}{1st Party cookies}&\multirow{2}{*}{High Performance Density}&Noticeable&35&12&12&17&9&11&9&0\\\cline{5-11}

& &Non Noticeable&35&11&3&14&4&10&2&1\\\cline{2-11}
&\multirow{2}{*}{Low performance density}&Noticeable&35&10&10&17&6&20&0&1\\\cline{3-11}
& & Non noticeable&36&14&10&16&4&7&6&3\\\hline
\multirow{4}{*}{1st/3rd Party cookies}&\multirow{2}{*}{High Performance Density}&Noticeable&32&8&7&12&8&5&6&0\\\cline{3-11}

& &Non Noticeable&37&12&11&11&7&7&7&1\\\cline{2-11}
&\multirow{2}{*}{Low performance density}&Noticeable&34&11&9&14&8&11&4&0\\\cline{3-11}
& & Non noticeable&34&8&10&10&5&10&2&1\\\hline
\end{tabular}
\end{landscape}
\end{document}

% 我已经这样做了。你可以按照自己想要的方式进行修改。

相关内容