# Center-align text in columns in tabular environment in multicol environment

I need the text in the second two columns to be center-aligned.

Notice it is inside a multicolumn (2-column) environment, because the context is a scientific report.

It is complex because it involves the interaction of several packages like tabularx, multicolumn and multirow.

I tried to put it inside a table environment but this introduces float issues. I want to to be floated exactly at the location in which it takes place in the document. If need be, it should continue spill over into the next column or over the page.

\documentclass[a4paper,12pt]{article}

\author{Peter Cao}
\date{}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption} %apparently needs to come first or options clash with other packages will occur

\usepackage[x11names,dvipsnames]{xcolor} %for use in color links

\usepackage[hyphens]{url}
\usepackage[hyphenbreaks]{breakurl}
\usepackage{a4wide}
\usepackage{graphicx}

\usepackage[version=3]{mhchem}

\usepackage[T1]{fontenc} %for > and < in text mode
\usepackage{tikz}
\mhchemoptions{arrows=pgf-filled}

\usepackage{booktabs} %for top, middle and bottomline

\usepackage{multirow} %multi column and row spanning

\usepackage{amsmath}

\usepackage{cite}

\usepackage{multirow}
\usepackage{tabularx}

\usepackage{siunitx}

\usepackage{fancyhdr}
%\usepackage{fancyheadings} seems to be obsoleted by fancyhdr

\usepackage{comment}
\usepackage{multicol}

\usepackage{lastpage}

\newcommand{\ignore}[1]{} %a null macro which gobbles up comments, and thus acts as a tool for in-line commenting.

\begin{document}

\begin{multicols}{2}

\subsection*{Results}

{\small
\begin{tabularx}{\columnwidth}{X | X | X}
\toprule
Characteristic & \multicolumn{2}{c}{Result}\\
\cmidrule(l){2-3}
& Seaweed isolate & Coral isolate \\
\cmidrule(r){1-1} \cmidrule(l){2-3}
Cell shape & Rod & Rod\\
Gram stain & - & -\\
Oxidase & + & -\\
Catalase & + & -\\
MSA & Growth & No growth\\
Anaerobic & Growth (weak) & No growth\\
Motility & & \\
Indole production & & \\
Hugh \& Leifsons & & \\
\bottomrule
\end{tabularx}
}

\end{multicols}

\end{document}

Edit: In the following example, notice how the right hand margin of the table isn't being respected. How do I fix this?

-

The centering is easy -- just specify a "c" column, rather than an "X". In the solution below, I've left this as a tabularx table -- though I think it could as easily be a simple tabular. (Personally, I think a left aligned column would be better in fact: that way the column edges line up nicely and eliminate the need for vertical rules; so I think you are making a design error, but I've done it how you asked for it.)

For the rest, it's largely a matter of just cleaning up chartjunk -- the crud that is not really communicating information, but is taking up space. There's a lot of that in the original table.

• You don't need the labels "results" or "characteristics", so they go.
• The "isolate" label can go before each column (since it relates to both "coral" and "seaweed"), and that saves some space.
• Get rid of all vertical lines, and as many horizontal lines as possible. This is crucial.
• Eliminate capital letters (hardly necessary since these are not full sentences).
• Use a minus sign rather than a hyphen as the opposite of "plus". This is just a matter of being typographically correct!
• Change "Growth (weak)" to "weak growth" and save a few points ...
• Trim the cmidrule both left and right

Some of these decisions of course are a bit personal (like using all lower case) -- but space saving. Others (like eliminating vertical rules) are pretty fundamental.

\documentclass[a4paper,12pt]{article}
\usepackage{a4wide}
\usepackage[T1]{fontenc} %for > and < in text mode
\usepackage{booktabs} %for top, middle and bottomline
\usepackage{tabularx}
\usepackage{multicol}

\begin{document}

\begin{multicols}{2}

\subsection*{Results}

{\small
\begin{tabularx}{\columnwidth}{lcc}
\toprule
& \multicolumn{2}{c}{isolate} \\
& seaweed & coral \\
\cmidrule(lr){2-3}
cell shape & rod & rod\\
gram stain & $-$ & $-$\\
oxidase & + & $-$\\
catalase & + & $-$\\
\textsc{msa} & growth & no growth\\
anaerobic & weak growth & no growth\\
motility & & \\
indole production & & \\
Hugh \& Leifsons & & \\
\bottomrule
\end{tabularx}
}

\end{multicols}
\end{document}
-
I agree with all of these suggestions except for going all lower case. –  TH. May 12 '11 at 9:07
\listfiles
\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[lmargin=2cm,rmargin=1cm]{geometry}
\usepackage{booktabs} %for top, middle and bottomline
\usepackage{graphicx}
\usepackage{multicol}

\begin{document}
\begin{multicols}{2}

\subsection*{Results}

\medskip\noindent
\resizebox{\columnwidth}{!}{%
\begin{tabular}{@{} l c c @{}}\toprule
& \multicolumn{2}{c}{\emph{isolate}} \\[-\smallskipamount]
& \emph{seaweed} & \emph{coral} \\\cmidrule(lr){2-3}
cell shape   & rod      & rod\\
gram stain   & $-$      & $-$\\
oxidase      & $+$      & $-$\\
catalase     & $+$      & $-$\\
\textsc{msa} & growth   & no growth\\
anaerobic    & weak growth & no growth\\
motility     & & \\
indole production & & \\
Hugh \& Leifsons  & & \\
\bottomrule
\end{tabular}%
}

\blindtext
\end{multicols}
\end{document}

-

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

\usepackage[T1]{fontenc} %for > and < in text mode
\usepackage{booktabs}
\usepackage{multicol}

\begin{document}

\begin{multicols}{2}
\subsection*{Results}

\noindent
\resizebox{\linewidth}{!}{%
\begin{tabular}{@{}l | c | c @{}}\toprule
Characteristic & \multicolumn{2}{c}{Result}\\\cmidrule(l){2-3}
& Seaweed isolate & Coral isolate \\
\cmidrule(r){1-1} \cmidrule(l){2-3}
Cell shape & Rod & Rod\\
Gram stain & $-$ & -\\
Oxidase & $+$ & $-$\\
Catalase & $+$ & $-$\\
MSA & Growth & No growth\\
Anaerobic & Growth (weak) & No growth\\
Motility & & \\
Indole production & & \\
Hugh \& Leifsons & & \\\bottomrule
\end{tabular}
}
\end{multicols}

\end{document}

-