Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Tabular content spilling over right column margin. What's going on here? How can I fix it?

enter image description here

\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[colorlinks=true,linkcolor=Blue4,citecolor=blue]{hyperref}
\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.


\usepackage{blindtext}




\begin{document}

\begin{multicols}{2}

\subsection*{Results}

{\small
\begin{tabularx}{\columnwidth}{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{tabularx}
}

\blindtext

\end{multicols}

\end{document}

Updated version demonstrating shrinkage issues:

\documentclass[a4paper,12pt]{article}

\usepackage{booktabs} %for top, middle and bottomline
\usepackage{multirow} %multi column and row spanning
\usepackage{multicol}
\usepackage{graphicx}

\begin{document}

\begin{multicols}{2}

\subsection*{Results}


{\noindent
\resizebox{\columnwidth}{!}{%
\begin{tabular}{@{} l c c @{}}
\toprule
Characteristic & \multicolumn{2}{c}{Result}\\
 \cmidrule{2-3}
 & Seaweed isolate & Coral isolate \\
 \midrule
Cell shape & Rod & Rod\\
Gram stain & $-$ & $-$\\
Oxidase & $+$ & $-$\\
Catalase & $+$ & $-$\\
Anaerobic & Growth (weak) & No growth\\
Motility & & \\
Indole production & & \\
Hugh \& Leifsons & & \\
MSA & Growth & No growth\\
Growth in absence of salt & & \\
Colony pigmentation & White & White \\
\bottomrule
\end{tabular}
}
}



\end{multicols}

\end{document}

enter image description here

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

I already showed you in the other examples what to do ...

\documentclass[a4paper,12pt]{article}
\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[colorlinks=true,linkcolor=Blue4,citecolor=blue]{hyperref}
\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.
\usepackage{blindtext}
\begin{document}

\begin{multicols}{2}

\subsection*{Results}

\noindent
\resizebox{\columnwidth}{!}{%
\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}%
}

\bigskip
\blindtext

\end{multicols}

\end{document}

enter image description here

it is also possible to fiddle with a surrounding tabularx or a parshape to get "unbalanced" columns: enter image description here

share|improve this answer
2  
Would resizing the table to the column width not be the last resort, due to the resulting odd font size? (Ok, I often do this by myself, but thought it is a bad habit) –  Martin Scharrer May 12 '11 at 16:10
    
My table text became tiny as I added new rows to it. Resizebox was great until it became so small I could barely make out the content...is there another way to achieve the same effect without resizebox shrinking my font? A little bit of shrinking is ok, but anything less than size 8pt becomes non-legible... –  ptrcao May 13 '11 at 11:07
    
@ptrcao: It maybe a good idea if you could provide a complete example of your table, then we do not need to show you solutions which cannot work ... –  Herbert May 13 '11 at 11:52
    
Of course - see OP under the heading "Updated version demonstrating shrinkage issues". This is where I'm at now, and as you can see, resizebox is great until a certain point when things become a bit difficult to read due to smallness of the font... –  ptrcao May 13 '11 at 13:29
    
@ptrcao: if you can split the text into paragraphs then you can use two multiols or a tabularx for the table and text, see image in the edited answer –  Herbert May 13 '11 at 13:58
show 4 more comments

The tabularx environment can only adjust the widths of table columns with the X specifier. To allow it to adjust a centred column you need to replace the column specifier c with

>{\centering\arraybackslash}X

For a left aligned column, use

>{\raggedright\arraybackslash}X 

So, a simple example would look like this.

\documentclass{article}
\usepackage{tabularx}
\begin{document}
%
\begin{tabularx}{0.8\textwidth}
{ | l | >{\raggedright\arraybackslash} X | >{\centering\arraybackslash} X | }
Leave this column alone. & Left justify and adjust this column. &
Centre and adjust this column. \\ 
\end{tabularx}
%
\end{document}

Have a look at section 4.2 of the tabularx package documentation for more details.

share|improve this answer
1  
In your case you can get there by adjusting the first column only to an "X" column, and specifying hyphenation for "Characteristic". But it looks pretty terrible, because there end up being odd word breaks. You can only squeeze so much into narrow columns, so it's crucial prune the text itself as far as possible! –  Paul Stanley May 12 '11 at 13:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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