合并表格单元格或列

合并表格单元格或列

在此处输入图片描述

请帮我合并多余的单元格或列。我想去掉空列,但又不想把表格分成两部分。

\documentclass[a4paper,12p]{report}
\begin{document}
\begin{center}
    \begin{table}[h]
        \centering
        \caption{Initial conditions for HPAI infection in poultry only} 
        \small\addtolength{\tabcolsep}{-6pt}    
        \begin{tabular}{|*{12}{c|}}
            \hline 
            \multicolumn{3}{|c|}{Ghana} & \multicolumn{3}{|c|}{South Africa}  \\ 
            \multicolumn{3}{|c}{H5N1, 2007} & \multicolumn{3}{|c|}{H5N8, 2017} \\   \hline \cline{1-4}
            Initial condition &value  & reference & Initial condition &value  & reference \\ \hline
            $A_e$ & 6500 & Pelletier et al (2013) & $A_e$ & 285,000 & chikwati (2017)  \\ \hline
            $P_I$ & 11743 & OIE(2007) & $P_I$ & 24,000 & chikwati (2017)  \\ \hline
            $P_N$ & \num{2.0263e+5} & OIE(2017) & $P_N$ & 400,000 & schnirrring(2017)  \\ \hline    
            $P_s$ & 48052 & OIE(2007) & $P_s$ & 107,000 & OIE(2017) & \\ \hline
            S & 406,390 & wikipedia & S & \num{4.4442e+6} & www.gov.za  \\ \hline 
        \multicolumn{3}{|c|}{Zimbabwe} \\   
        \multicolumn{3}{|c|}{H5N8, 2017}\\  \hline
        \cline{1-3}
    Initial condition & value & reference\\ \hline
        $A_e$ & 140,000 &chikwati (2017) \\ \hline  
        $P_I$ & 7485 & pathfinder(2017)  \\ \hline
        $P_N$ & \num{2e+6} & Reuters(2017) \\ \hline    
         $P_s$ & 19172 & pathfinder(2017)\\ \hline
         S & \num{1.16706e+6} & www.Pindula.co.zw \\ \hline
        \end{tabular}
    \end{table}
\end{center}
\end{document}

答案1

首先有几点建议:

  1. 不要放在环境table中;而是在,之后center使用;\centering\begin{table}

  2. 不要使用单一[h]位置说明符,而是[htp]

  3. 三个单独的表格看起来更好。

以下是您可以这样做的方法。请注意,\multicolumn规则属于列(当然,第一列除外)。我添加了它geometry以使表格适合。

\documentclass[a4paper,12pt]{report}
\usepackage[margin=1cm]{geometry}

\usepackage{siunitx}

\begin{document}

\begin{table}[htp]
\centering

\caption{Initial conditions for HPAI infection in poultry only} 

\small\addtolength{\tabcolsep}{-6pt}    

\begin{tabular}{|*{6}{c|}}
\hline 
\multicolumn{3}{|c|}{Ghana} & \multicolumn{3}{c|}{South Africa}  \\ 
\multicolumn{3}{|c|}{H5N1, 2007} & \multicolumn{3}{c|}{H5N8, 2017} \\
\hline
Initial condition & value  & reference & Initial condition &value  & reference \\
\hline
$A_e$ & 6500 & Pelletier et al (2013) & $A_e$ & 285,000 & chikwati (2017)  \\
\hline
$P_I$ & 11743 & OIE(2007) & $P_I$ & 24,000 & chikwati (2017)  \\
\hline
$P_N$ & \num{2.0263e+5} & OIE(2017) & $P_N$ & 400,000 & schnirrring(2017)  \\
\hline
$P_s$ & 48052 & OIE(2007) & $P_s$ & 107,000 & OIE(2017) & \\
\hline
$S$ & 406,390 & wikipedia & S & \num{4.4442e+6} & www.gov.za  \\
\hline 
\multicolumn{3}{|c|}{Zimbabwe} \\   
\multicolumn{3}{|c|}{H5N8, 2017}\\
\cline{1-3}
Initial condition & value & reference\\
\cline{1-3}
$A_e$ & 140,000 &chikwati (2017) \\
\cline{1-3}
$P_I$ & 7485 & pathfinder(2017)  \\
\cline{1-3}
$P_N$ & \num{2e+6} & Reuters(2017) \\
\cline{1-3}
$P_s$ & 19172 & pathfinder(2017)\\
\cline{1-3}
$S$ & \num{1.16706e+6} & www.Pindula.co.zw \\
\cline{1-3}
\end{tabular}

\end{table}

\end{document}

在此处输入图片描述

不同的实现:

\documentclass[a4paper,12pt]{report}
\usepackage[margin=1cm]{geometry}
\usepackage{siunitx,booktabs}

\begin{document}

\begin{table}[htp]
\centering

\caption{Initial conditions for HPAI infection in poultry only} 

\small
%\addtolength{\tabcolsep}{-3pt}

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} c  c @{}}
\toprule
\begin{tabular}{@{} l c c @{}}
\multicolumn{3}{c}{Ghana, H5N1, 2007} \\
Initial condition & value  & reference \\
\midrule
$A_e$ & 6500 & Pelletier et al (2013) \\
$P_I$ & 11743 & OIE(2007) \\
$P_N$ & \num{2.0263e+5} & OIE(2017) \\
$P_s$ & 48052 & OIE(2007) \\
$S$   & 406,390 & wikipedia \\
\end{tabular}
&
\begin{tabular}{@{} l c c @{}}
\multicolumn{3}{c}{South Africa, H5N8, 2017} \\
Initial condition & value  & reference \\
\midrule
$A_e$ & 285,000 & chikwati (2017)  \\
$P_I$ & 24,000 & chikwati (2017)  \\
$P_N$ & 400,000 & schnirrring(2017)  \\
$P_s$ & 107,000 & OIE(2017) \\
$S$   & \num{4.4442e+6} & www.gov.za  \\
\end{tabular}
\\
\midrule
\begin{tabular}{@{} l c c @{}}
\multicolumn{3}{c}{Zimbabwe, H5N8, 2017}\\
Initial condition & value & reference\\
\midrule
$A_e$ & 140,000 &chikwati (2017) \\
$P_I$ & 7485 & pathfinder(2017)  \\
$P_N$ & \num{2e+6} & Reuters(2017) \\
$P_s$ & 19172 & pathfinder(2017)\\
$S$ & \num{1.16706e+6} & www.Pindula.co.zw \\
\end{tabular}
\\
\bottomrule
\end{tabular*}

\end{table}

\end{document}

在此处输入图片描述

答案2

我会按如下方式设计您的表格:

  • 删除第二和第三个表的第一列
  • 使用S列类型来siunitx表示带有数字的列
  • 做了一致的编号格式(我希望我的猜测姆韦以下是正确的)
  • 将三个表合并到一个表上
  • 使用“几何包”增加页面布局(减少边距)

在此处输入图片描述

\documentclass[a4paper,12p]{report}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{booktabs, makecell, tabularx}
\renewcommand\theadfont{\bfseries}
\usepackage{hyperref}
%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%


\begin{document}
    \begin{table}[h]
\caption{Initial conditions for HPAI infection in poultry only}
    \centering
    \small
    \setlength\tabcolsep{0pt}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
                c
           *{3}{S[table-format=7.0,
                      group-four-digits] l}
                }
    \toprule
    & \multicolumn{2}{c}{\thead{Ghana\\H5N1, 2007}}
        & \multicolumn{2}{c}{\thead{South Africa\\ H5N8, 2017}}
            & \multicolumn{2}{c}{\thead{Zimbabwe\\ H5N8, 2017}} \\
    \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}
\makecell{Initial\\ cond.}
    & {value}   & reference
        & {value}   & reference
            & {value}   & reference                             \\
    \midrule
$A_e$   & 6500  & Pelletier et al (2013)
            & 285000   & chikwati (2017)
                & 140000    & chikwati (2017)                   \\
$P_I$   & 11743   & OIE(2007)
            & 24000  & chikwati (2017)
                & 140000    & chikwati (2017)                   \\
$P_N$ & 202630  & OIE(2017)
            & 400000    & schnirrring(2017)
                & 7485      & pathfinder(2017)                  \\
$P_s$ & 48052   & OIE(2007)
            & 107000    & OIE(2017)
                & 2000000   & Reuters(2017)                     \\
S     & 406390  & wikipedia
            & 44442000 & www.gov.za
                &   1167060 & \url{www.Pindula.co.zw}           \\
    \bottomrule
\end{tabular*}
    \end{table}
\end{document}

相关内容