表格标题修复

表格标题修复

我正在尝试以一种美观的方式显示表格。我尽力了,但我无法修复标题。你能帮助我吗:

  1. 如图所示修复标题。
  2. 放大文本“2016”以填充空间
  3. 在单元格中垂直对齐文本。

归根结底,我想以一种好的方式显示数据。任何建议都将不胜感激。边框并不重要。您可以帮助我以好的方式显示表格,只需忽略我上面的请求即可。

在此处输入图片描述

我的代码在这里:

\documentclass[11pt]{report}
\usepackage{graphicx}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=3cm,headsep=1.6cm,landscape]{geometry}
\usepackage{fancyhdr}
\usepackage{multirow}
\usepackage{array}
\usepackage{epstopdf}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}

\begin{document}
\def\hgt{4pt}
\begin{tabular}{M{1cm}|M{1cm}|M{1cm}|M{1.8cm}|M{1.8cm}|M{1.99cm}|M{1.8cm}|}

& & & Title 1 & Title 2  & Title 3 & Title 4\\ 

\hline

\multicolumn{1}{|c|}{\multirow{12}{*}{\rotatebox[origin=c]{90}{\huge{2016}}}}&      & Jan & 0 & 0 & 3 & 10\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &   1\textsuperscript{st} Q.    & Feb & 0 & 0 & 0 & 10\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &                               & Mar & 0 & 0 & 0 & 10\\ [\hgt] \cline{2-7} 
\multicolumn{1}{|c|}{}  &                               & Apr & 0 & 0 & 1 & 10\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &   2\textsuperscript{nd} Q.    & May & 0 & 0 & 0 & 10\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &                               & Jun & 1 & 1 & 0 & 8\\ [\hgt]  \cline{2-7}
\multicolumn{1}{|c|}{}  &                               & Jul & 1 & 1 & 0 & 7\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  & 3\textsuperscript{rd} Q.      & Aug & 2 & 2 & 0 & 5\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &                               & Sep & 1 & 1 & 0 & 4\\ [\hgt] \cline{2-7}
\multicolumn{1}{|c|}{}  &                               & Oct & 2 & 2 & 2 & 2\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  & 4\textsuperscript{th} Q.      & Nov & 1 & 1 & 4 & 0\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &                               & Dec & 1 & 1 & 5 & 0\\ [\hgt] \hline
\end{tabular}
\end{document}

答案1

我知道这不是你的问题的答案,但是这是我排版表格的方式;我提供了三种选择:可能我会选择第一种方式,不固定列宽,所以是 1 和 3 的混合,但最终决定取决于实际的表格材料。

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{booktabs,array}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}

\begin{document}

\begin{tabular}{c M{1cm}M{1.8cm}M{1.8cm}M{1.99cm}M{1.8cm}}
\toprule

\multicolumn{2}{c}{2016} & Title 1 & Title 2  & Title 3 & Title 4\\ 
\cmidrule(r){1-2} \cmidrule(l){3-6}

1st Q. & Jan & 0 & 0 & 3 & 10 \\
       & Feb & 0 & 0 & 0 & 10 \\
       & Mar & 0 & 0 & 0 & 10 \\
\midrule
2nd Q. & Apr & 0 & 0 & 1 & 10 \\
       & May & 0 & 0 & 0 & 10 \\
       & Jun & 1 & 1 & 0 &  8 \\
\midrule
3rd Q. & Jul & 1 & 1 & 0 &  7 \\
       & Aug & 2 & 2 & 0 &  5 \\
       & Sep & 1 & 1 & 0 &  4 \\
\midrule
4th Q. & Oct & 2 & 2 & 2 &  2 \\
       & Nov & 1 & 1 & 4 &  0 \\
       & Dec & 1 & 1 & 5 &  0 \\
\bottomrule
\end{tabular}

\bigskip

\begin{tabular}{ l c M{1cm}M{1.8cm}M{1.8cm}M{1.99cm}M{1.8cm}}
\toprule

& & & Title 1 & Title 2  & Title 3 & Title 4\\ 
\midrule
2016
& 1st Q. & Jan & 0 & 0 & 3 & 10 \\
&        & Feb & 0 & 0 & 0 & 10 \\
&        & Mar & 0 & 0 & 0 & 10 \\
\cmidrule{2-7}
& 2nd Q. & Apr & 0 & 0 & 1 & 10 \\
&        & May & 0 & 0 & 0 & 10 \\
&        & Jun & 1 & 1 & 0 &  8 \\
\cmidrule{2-7}
& 3rd Q. & Jul & 1 & 1 & 0 &  7 \\
&        & Aug & 2 & 2 & 0 &  5 \\
&        & Sep & 1 & 1 & 0 &  4 \\
\cmidrule{2-7}
& 4th Q. & Oct & 2 & 2 & 2 &  2 \\
&        & Nov & 1 & 1 & 4 &  0 \\
&        & Dec & 1 & 1 & 5 &  0 \\
\bottomrule
\end{tabular}

\bigskip

\begin{tabular}{ l c c c c c c }
\toprule

& & & Title 1 & Title 2  & Title 3 & Title 4\\ 
\midrule
2016
& 1st Q. & Jan & 0 & 0 & 3 & 10 \\
&        & Feb & 0 & 0 & 0 & 10 \\
&        & Mar & 0 & 0 & 0 & 10 \\
\cmidrule{2-7}
& 2nd Q. & Apr & 0 & 0 & 1 & 10 \\
&        & May & 0 & 0 & 0 & 10 \\
&        & Jun & 1 & 1 & 0 &  8 \\
\cmidrule{2-7}
& 3rd Q. & Jul & 1 & 1 & 0 &  7 \\
&        & Aug & 2 & 2 & 0 &  5 \\
&        & Sep & 1 & 1 & 0 &  4 \\
\cmidrule{2-7}
& 4th Q. & Oct & 2 & 2 & 2 &  2 \\
&        & Nov & 1 & 1 & 4 &  0 \\
&        & Dec & 1 & 1 & 5 &  0 \\
\bottomrule
\end{tabular}


\end{document}

在此处输入图片描述

答案2

这里 :

\documentclass[11pt]{report}
\usepackage{graphicx}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=3cm,headsep=1.6cm,landscape]{geometry}
\usepackage{fancyhdr}
\usepackage{multirow}
\usepackage{array}
\usepackage{epstopdf}
\usepackage{adjustbox}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}

\begin{document}
\def\hgt{4pt}
\begin{tabular}{M{1cm}|M{1cm}|M{1cm}|M{1.8cm}|M{1.8cm}|M{1.99cm}|M{1.8cm}|}

\cline{4-7}
\multicolumn{3}{c|}{} & Title 1 & Title 2  & Title 3 & Title 4\\ 

\hline

\multicolumn{1}{|c|}{\multirow{12}{*}{\rotatebox[origin=c]{90}{\adjustbox{scale={4}{1}}{\huge{2016}}}}
  }
                      &      & Jan & 0 & 0 & 3 & 10\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &   1\textsuperscript{st} Q.    & Feb & 0 & 0 & 0 & 10\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &                               & Mar & 0 & 0 & 0 & 10\\ [\hgt] \cline{2-7} 
\multicolumn{1}{|c|}{}  &                               & Apr & 0 & 0 & 1 & 10\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &   2\textsuperscript{nd} Q.    & May & 0 & 0 & 0 & 10\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &                               & Jun & 1 & 1 & 0 & 8\\ [\hgt]  \cline{2-7}
\multicolumn{1}{|c|}{}  &                               & Jul & 1 & 1 & 0 & 7\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  & 3\textsuperscript{rd} Q.      & Aug & 2 & 2 & 0 & 5\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &                               & Sep & 1 & 1 & 0 & 4\\ [\hgt] \cline{2-7}
\multicolumn{1}{|c|}{}  &                               & Oct & 2 & 2 & 2 & 2\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  & 4\textsuperscript{th} Q.      & Nov & 1 & 1 & 4 & 0\\ [\hgt] \cline{3-7}
\multicolumn{1}{|c|}{}  &                               & Dec & 1 & 1 & 5 & 0\\ [\hgt] \hline
\end{tabular}
\end{document}

在此处输入图片描述

答案3

像这样:

在此处输入图片描述

删除多余的宏并添加\cline到表格顶部后,您的 MWE 变为:

\documentclass[11pt]{report}
\usepackage{graphicx}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=3cm,headsep=1.6cm,landscape]{geometry}
\usepackage{fancyhdr}
\usepackage{array,multirow}
\usepackage{soul}% <-- added for more spacing between numbers in 2016
\usepackage{epstopdf}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}
    \renewcommand{\arraystretch}{1.3}%1.2
\begin{tabular}{|M{1cm}|M{1cm}|M{1cm}|M{1.8cm}|M{1.8cm}|M{1.99cm}|M{1.8cm}|}
    \cline{4-7}
\multicolumn{3}{c|}{}
        & Title 1 & Title 2  & Title 3 & Title 4\\
\hline
\multirow{12}*[-1ex]{\rotatebox[origin=b]{90}{\huge{\so{2016}}}}
    &   \multirow{3}*{1\textsuperscript{st} Q.}
        &   Jan & 0 & 0 & 3 & 10\\ \cline{3-7}
    &   &   Feb & 0 & 0 & 0 & 10\\ \cline{3-7}
    &   &   Mar & 0 & 0 & 0 & 10\\ \cline{2-7}
    &   \multirow{3}*{2\textsuperscript{nd} Q.}                         
        &   Apr & 0 & 0 & 1 & 10\\ \cline{3-7}
    &   &   May & 0 & 0 & 0 & 10\\ \cline{3-7}
    &   &   Jun & 1 & 1 & 0 & 8\\ \cline{2-7}
    &   \multirow{3}*{3\textsuperscript{nd} Q.}
        &   Jul & 1 & 1 & 0 & 7\\ \cline{3-7}
    &   &   Aug & 2 & 2 & 0 & 5\\ \cline{3-7}
    &   &   Sep & 1 & 1 & 0 & 4\\ \cline{2-7}
    &   \multirow{3}*{4\textsuperscript{nd} Q.}
        &   Oct & 2 & 2 & 2 & 2\\ \cline{3-7}
    &   &   Nov & 1 & 1 & 4 & 0\\ \cline{3-7}
    &   &   Dec & 1 & 1 & 5 & 0\\ \hline
\end{tabular}
\end{document}

升级:似乎对许多人来说,更喜欢延长年份(2016)比清晰、简单和简洁的 MWE 代码更重要……所以我又添加了一种可能性,如何将年份数字延伸到所有行:

  • 删除包soul
  • \scaleboxgraphicx包中使用
  • 而不是代码行

\multirow{12}*[-1ex]{\rotatebox[origin=b]{90}{\huge{\so{2016}}}}

使用

\multirow{12}*[-1ex]{\rotatebox[origin=b]{90}{\scalebox{5}{\tiny{2\quad0\quad1\quad6}}}}

经过这些更改后,表格如下所示:

在此处输入图片描述

相关内容