6

My code is a disaster. I would really appreciate help with getting a table with a title, three columns, five rows, and the following specifications.

Title, horizontally centered and on two lines:

Pathogen Occurrence in Honey Bee Colonies with and

   `without Colony Collapse Disorder`

First row: nothing occupies first column, and text spans second and third columns in two lines.

(blank) | Percent of colonies affected by

(blank) | ..........pathogen............

Second row: Text in each column; the text in second and third columns are typeset on three lines and horizontally centered on each line.

.............. | ..Colonies with.. | Colonies without

Pathogen | colony collapse | colony collapse

.............. | ....disorder.... | ....disorder....

(The dots are only for the post to horizontally center the text.)

In the remaining rows, I would like the % aligned. I would also like a darker vertical line separating the pathogens in the first column from the percentages in the second and third columns. I think using V(3) as an option of the tabular environment.

\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}
  • 2
    instead lengthy, not very clear description what you like that someone do for you, if will be better and more easy understand, if you add a (hand drawn) sketch, what you like to have. probably is good idea, if you explain in which sense the received answer is not adequate – Zarko Nov 4 '17 at 19:23
10

i would design your table like this:

addendum:

as response to edited question and comments below. it is based on guessing, what yo like to have:

enter image description here

for table environment is used threeparttable, for multi line cells are used makecells:

\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}

edit:

after last edit of question, it seems that you like to have the following looks of table (with consideration my taste what is good looking table):

enter image description here

(red lines indicate page layout).

note:

  • demand, that can be used only tabular table environments is the very same as required to drill holes with square drill bit ...
  • so, i suggest to use packages, which can make your life more relaxing and help you to design professional looks of table.
  • differences between above table and previous propositions are minimal.

\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}
  • if you like to have table with vertical lines -- what i strongly dissuade -- than just add | in column specification, where you like to have them, remove package booktabs from preamble and replace \toprule, \midrule and \bottomrule with \hline and after some tweaks obtain:

enter image description here

\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}
  • I corrected the code in my post. You are missing the second row. It has "Pathogens" in the first column, for example. – user74973 Nov 2 '17 at 2:19
  • I am trying to mimic a table. The table that you provide is close to what I want, except for the missing second row. – user74973 Nov 2 '17 at 2:27
  • is this a problem to add it yourself? i don't understand what you like to change. number of rows? content of rows? – Zarko Nov 2 '17 at 2:28
  • I do not want "Table 1." in the title, and I do not want a line under "Virus" or "Fungi." I do want a double bar surrounding the table. – user74973 Nov 2 '17 at 2:29
  • 3
    than remove \caption and add your vertical lines as you wish. but with vertical lines don't use rules from booktabs (which is intended to design professional looks of tables) but ordinary \hlines. sorry, in this i cant help you. – Zarko Nov 2 '17 at 2:33
3
+25

Those are my suggestions (and if you don't like them... well, I have others, as Groucho would have said):

mwe

It is not clear if you are against the ordinary numbered \caption{} in a table float but usually there are little reasons to do not in this way.

Use the caption package to change the default caption format.

You can use \centering instead of center environment to avoid vertical empty spaces.

As you are not in two column mode, there are no reason to use only three columns forcing two more rows.

I strongly advise against vertical rules in tables. Elegant journals never use Excel-like tables.

Also against irrelevant headers. With a caption about of the "Pathogen Occurrence in Honey Bee Colonies" and one column of pathogens and two columns of percentages with the % symbol in each cell, Two header to explain where are the "Pathogens" and where the "Percentages of colonies" is rather superfluous. Always consider simply your table as far as possible. Easier to construct, easier to read and easier to understand.

To align percentages without r columns you can use the siunitx package.

Off-topic: Microsporidia have been considered inside Fungi for more than two decades, but now are (again) within Protozoa (see Ruggiero et al., 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}
  • I am mimicking a table in a book. – user74973 Nov 11 '17 at 1:08
  • The column headings that you give should not be abbreviated. – user74973 Nov 11 '17 at 1:11
2

Based on your description it seems you want a table like the first one below. However, as Zarko mentioned I think reformatting it to perhaps something like the second one below would be a good idea.

The code for the centered fixed length columns comes from lockstep's answer to How to create fixed width table columns with text raggedright/centered/raggedleft?

Code:

\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}

Which yields:

enter image description here

EDIT:

Code:

\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}

Yields:

enter image description here

  • The second table is very close to what I want. – user74973 Nov 11 '17 at 1:02
  • May you make the following edits? The whole table should be surrounded by a box; horizontal lines should span the width of it. Please add the double line that you have under Pathogen to be under the title of the table, and replace the double line under Pathogen with a thick line. Also, add a horizontal line before Fungi. And a single vertical line between the columns listing percentages of affected colonies - from the line under the title to the bottom of the table. – user74973 Nov 11 '17 at 1:06
  • I would appreciate it. – user74973 Nov 11 '17 at 1:07
  • @user74973 See edits. I think this is what you were asking for... – Dan Nov 11 '17 at 1:25
  • @Dan With edits like centering the percentages and adding the options | to the tabular environment and the \multicolumn commands, the table is almost what I want. (For example, I encoded \begin{tabular}{|l||c|c|}.) – Adelyn Nov 24 '17 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.