我的代码简直是一团糟。如果能帮我弄一个有标题、三列、五行且符合以下规格的表格,我将不胜感激。
标题,水平居中,分两行:
Pathogen Occurrence in Honey Bee Colonies with and
`without Colony Collapse Disorder`
第一行:第一列没有任何内容,文本横跨第二列和第三列两行。
(blank)
|
Percent of colonies affected by
(blank)
|
.......... pathogen
..........
第二行:每列文字;第二列和第三列的文字排版在三行上,每行水平居中。
.............. |
Colonies with
|
Colonies without
Pathogen
|
colony collapse
|
colony collapse
.............. |
.... disorder
.... |
.... disorder
....
(这些点仅用于使帖子的文本水平居中。)
在剩余的行中,我希望对齐%
。我还希望使用较暗的垂直线将第一列中的病原体与第二列和第三列中的百分比分开。我认为将其用作环境V(3)
的一个选项tabular
。
\documentclass{amsart}
\usepackage{makecell}
\usepackage{boldline}
\setcellgapes{3pt}
\begin{document}
\begin{center}
\begin{tabular}{|| l | c | c||} \hline
%\multicolumn{3}{|| c ||}{\textbf{Pathogen Occurence in Honey Bee Colonies with and}}
% without Colony Collapse Disorder}} \\ \hline
%& \multicolumn{2}{ c ||}{%
% \begin{tabular}{@{}c@{}}
% Percentage of colonies affected by\\
% pathogen
% \end{tabular}%
% } \\ \cline{2-3}
Viruses & & \\
\hspace*{1em}IAPV & 83\% & 5\% \\
\hspace*{1em}KBV & 100\% & 76\% \\ \hline
Fungi & & \\ \hline
\hspace*{1em}{\em Nosema apis} & 90\% & 48\% \\
\hspace*{1em}{\em Nosema ceranae} & 100\% & 81\% \\ \hline
All Four Pathogens & 83\% & 0\% \\ \hline
\end{tabular}
\end{center}
\end{document}
答案1
我会像这样设计你的桌子:
附录:
作为对以下编辑的问题和评论的回应。它基于猜测,你喜欢什么:
对于表格环境使用threeparttable
,对于多行单元格使用makecell
:
\documentclass{amsart}
\usepackage{booktabs, makecell, threeparttable}
\renewcommand\theadfont{\normalsize}
\renewcommand\theadgape{}
\newcommand\mcm[1]{\multicolumn{1}{c}{\makecell[tl]{#1}}}
\newcommand\mcl[1]{\multicolumn{2}{l}{#1}}
\usepackage{siunitx}
\begin{document}
\begin{threeparttable}
\centering
{Pathogen Occurrence in Honey Bee Colonies with and
without Colony Collapse Disorder}
\medskip
\begin{tabular}{l l *{2}{S[table-format=2.0,
table-space-text-post={\;\%},
table-column-width=24mm]<{\,\%}} }
\toprule
& & \mcl{\thead{Percentage of colonies\\
affected by pathogen}} \\
\midrule
\mcl{Viruses} & \mcl{} \\
& IAPV & 83 & 5 \cr
& KBV & 100 & 76 \cr
\midrule
\mcl{Pathogen} & \mcm{Colonies with \\
colony collapse\\
disorder}
& \mcm{Colonies without\\
colony collapse \\
disorder} \\
\midrule
\mcl{Fungi} & \mcl{} \\
& \textit{Nosema apis} & 90 & 48 \cr
& \textit{Nosema ceranae} & 100 & 81 \cr
\midrule
\mcl{All Four Pathogens} & 83 & 0 \cr
\bottomrule
\end{tabular}
\end{threeparttable}
\end{document}
编辑:
在最后一次编辑问题之后,似乎您喜欢以下表格外观(考虑到我的品味,什么是好看的表格):
(红线表示页面布局)。
笔记:
- 需求,只能用于
tabular
桌面环境,与使用方形钻头钻孔所需的需求完全相同…… - 因此,我建议使用包,它可以让你的生活更轻松,并帮助你设计专业的表格外观。
- 上表与先前的命题之间的差异很小。
\documentclass{amsart}
\usepackage{caption}
\usepackage{booktabs, makecell, threeparttable}
\renewcommand\theadfont{\small}
\renewcommand\theadgape{}
\newcommand\mcm[1]{\multicolumn{1}{c}{\thead[tl]{#1}}}
\newcommand\mcl[1]{\multicolumn{2}{l}{\textbf{#1}}}
\usepackage{siunitx}
%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{center}
\begin{threeparttable}
\captionsetup{skip=1ex, margin=11mm, justification=centering}
\caption*{Pathogen Occurrence in Honey Bee Colonies with and
without Colony Collapse Disorder}
\begin{tabular}{l l *{2}{S[table-format=2.0,
table-space-text-post={\;\%},
table-column-width=24mm]<{\,\%}} }
\toprule
\mcl{Pathogen} & \mcm{Percentage affected in \\
colonies with colony \\
collapse disorder}
& \mcm{Percentage affected in \\
colonies without colony\\
collapse disorder} \\
\midrule
\mcl{Viruses} & \mcl{} \\
& IAPV & 83 & 5 \cr
& KBV & 100 & 76 \cr
\midrule
\mcl{Fungi} & \mcl{} \\
& \textit{Nosema apis} & 90 & 48 \cr
& \textit{Nosema ceranae} & 100 & 81 \cr
\midrule
\mcl{All Four Pathogens} & 83 & 0 \cr
\bottomrule
\end{tabular}
\end{threeparttable}
\end{center}
\end{document}
- 如果您喜欢在表格中使用垂直线(我强烈反对),那么只需
|
在您想要的位置添加列规范,booktabs
从序言中删除包并替换\toprule
,\midrule
然后\bottomrule
进行\hline
一些调整后获得:
\documentclass{amsart}
\usepackage{caption}
\usepackage{threeparttable}
\newcommand\mcl[1]{\multicolumn{2}{l|}{\textbf{#1}}}
\usepackage{siunitx}
%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{center}
\begin{threeparttable}
\captionsetup{skip=1ex, margin=11mm, justification=centering}
\sisetup{table-format=2.0,
table-space-text-post={\;\%},
table-column-width=24mm
}
\renewcommand\arraystretch{1.2}
\caption*{Pathogen Occurrence in Honey Bee Colonies with and
without Colony Collapse Disorder}
\begin{tabular}{l l | S<{\,\%} | S<{\,\%} }
\hline
\mcl{Pathogen} & \multicolumn{1}{p{33mm}|}{\centering
Percentage affected in
colonies with colony
collapse disorder}
& \multicolumn{1}{p{33mm}}{\centering
Percentage affected in
colonies without colony
collapse disorder} \\
\hline
\mcl{Viruses} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c}{} \\
& IAPV & 83 & 5 \cr
& KBV & 100 & 76 \cr
\hline
\mcl{Fungi} & \multicolumn{1}{c|}{}
& \multicolumn{1}{c}{} \\
& \textit{Nosema apis} & 90 & 48 \cr
& \textit{Nosema ceranae} & 100 & 81 \cr
\hline
\mcl{All Four Pathogens} & 83 & 0 \cr
\end{tabular}
\end{threeparttable}
\end{center}
\end{document}
答案2
这些是我的建议(如果你不喜欢它们……好吧,我还有其他的,就像格劳乔会说的那样):
目前尚不清楚您是否反对 \caption{}
在table
浮点数中进行普通编号,但通常没有理由不这样做。
使用该caption
包来更改默认的字幕格式。
您可以使用\centering
而不是中心环境来避免垂直空白。
由于您不是处于双列模式,因此没有理由只使用三列来强制增加两行。
我强烈建议不要在表格中使用垂直线。优雅的期刊绝不使用类似 Excel 的表格。
还要反对不相关的标题。标题为“蜜蜂群落中的病原体发生率”,一列病原体和两列百分比,每个单元格中都有 % 符号,两个标题来解释“病原体”在哪里以及“蜂群百分比”在哪里是多余的。始终尽可能简单地考虑您的表格。更易于构建,更易于阅读和理解。
要对齐没有 r 列的百分比,您可以使用该siunitx
包。
题外话:二十多年来,人们一直认为微孢子虫属于真菌,但现在(再次)被归入原生动物(见 Ruggiero等人.,2015年)。
\documentclass{amsart}
\usepackage{booktabs,tabulary,siunitx,caption}
\captionsetup{justification=centering}
\begin{document}
\begin{table}
\centering
\caption{Pathogen Occurrence in Honey Bee Colonies with
and without Colony Collapse Disorder (CCD).}
\begin{tabular}{
llS[table-format = 2.0]<{{\si{ \percent} }}
S[table-format = 2.0]<{{\si{ \percent} }}}
\toprule
& & \multicolumn{1}{c}{With CCD} & \multicolumn{1}{c}{Without CCD} \\
\midrule
Viruses & IAPV & 83 & 5 \cr
& KBV & 100 & 76 \cr
\addlinespace[1ex]
Protozoa & {\em Nosema apis} & 90 & 48 \cr
& {\em Nosema ceranae} & 100 & 81 \cr
\midrule
\multicolumn{2}{l}{All Four Pathogens} & 83 & 0 \cr
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
根据您的描述,您似乎想要一个类似下面第一个表格。但是,正如 Zarko 所说,我认为将其重新格式化为下面第二个表格可能是一个好主意。
居中固定长度列的代码来自 lockstep 对如何创建带有文本“raggedright/centered/raggedleft”的固定宽度表格列?
代码:
\documentclass{amsart}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{center}
\begin{tabular}{l||c|c}
\multicolumn{3}{c}{Pathogen Occurrence in Honey Bee Colonies with and}\\
\multicolumn{3}{c}{without Colony Collapse Disorder}\\
&\multicolumn{2}{c}{Percent of colonies affected by}\\
&\multicolumn{2}{c}{pathogen}\\
&Colonies with&Colonies without\\
Pathogen&colony collapse&colony collapse\\
&disorder&disorder\\
Viruses & & \\
\hspace*{1em}IAPV & 83\% & 5\% \\
\hspace*{1em}KBV & 100\% & 76\% \\ \hline
Fungi & & \\ \hline
\hspace*{1em}{\em Nosema apis} & 90\% & 48\% \\
\hspace*{1em}{\em Nosema ceranae} & 100\% & 81\% \\ \hline
All Four Pathogens & 83\% & 0\% \\ \hline
\end{tabular}
%%%%%%%%%%%
\vskip .5 in
%%%%%%%%%%%
\begin{tabular}{l||rr}
\multicolumn{3}{c}{\textbf{Pathogen Occurrence in Honey Bee Colonies with and}}\\
\multicolumn{3}{c}{\textbf{without Colony Collapse Disorder}}\\
\multicolumn{3}{c}{}\\
\textbf{Pathogen}&\multicolumn{1}{C{1.5in}}{\textbf{\% affected in colonies with colony collapse disorder}}&\multicolumn{1}{C{1.75in}}{\textbf{\% affected in colonies without colony collapse disorder}}\\\hline\hline
\textbf{Viruses} & & \\
\hspace*{1em}IAPV & 83\% & 5\% \\
\hspace*{1em}KBV & 100\% & 76\% \\
\textbf{Fungi} & & \\
\hspace*{1em}{\em Nosema apis} & 90\% & 48\% \\
\hspace*{1em}{\em Nosema ceranae} & 100\% & 81\% \\ \hline
\textbf{All Four Pathogens} & \textbf{83\%} & \textbf{0\%} \\
\end{tabular}
\end{center}
\end{document}
得出的结果是:
编辑:
代码:
\documentclass{amsart}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{center}
\begin{tabular}{l||r|r}
\hline
\multicolumn{3}{c}{\textbf{Pathogen Occurrence in Honey Bee Colonies with and}}\\
\multicolumn{3}{c}{\textbf{without Colony Collapse Disorder}}\\\hline\hline
\textbf{Pathogen}&\multicolumn{1}{C{1.5in}|}{\textbf{\% affected in colonies with colony collapse disorder}}&\multicolumn{1}{C{1.75in}}{\textbf{\% affected in colonies without colony collapse disorder}}\\\hline
\textbf{Viruses} & & \\
\hspace*{1em}IAPV & 83\% & 5\% \\
\hspace*{1em}KBV & 100\% & 76\% \\ \hline
\textbf{Fungi} & & \\
\hspace*{1em}{\em Nosema apis} & 90\% & 48\% \\
\hspace*{1em}{\em Nosema ceranae} & 100\% & 81\% \\ \hline
\textbf{All Four Pathogens} & \textbf{83\%} & \textbf{0\%} \\
\hline
\end{tabular}
\end{center}
\end{document}
产量: