tabular
内容溢出右列边缘。这是怎么回事?我该如何修复?
\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}
更新版本展示了收缩问题:
\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}
答案1
我已经在其他例子中向您展示了如何做......
\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}
也可以摆弄周围环境tabularx
或\parshape
来获得“不平衡”的列:
答案2
环境tabularx
只能使用说明符调整表格列的宽度X
。要允许它调整居中的列,您需要将列说明符替换c
为
>{\centering\arraybackslash}X
对于左对齐列,使用
>{\raggedright\arraybackslash}X
一个简单的例子如下。
\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}
请参阅tabularx 包文档更多细节。