使用表格时行之间的文本重叠

使用表格时行之间的文本重叠

我有一张使用 tabulary 制作的表格。如果没有多行/列,输出看起来不错。但是,如果包含多行,输出会很糟糕。有人能帮帮我吗?

\documentclass[9pt,twocolumn]{article}

\usepackage{amsmath,amsfonts,amssymb,balance,tabulary,graphicx,caption,fancyhdr}
\usepackage[utf8]{inputenc}
\usepackage[numbers,super,sort&compress]{natbib}
\usepackage{url,multirow,morefloats,floatflt,cancel,tfrupee}
\usepackage{colortbl}
\usepackage{xcolor}
\makeatletter

%%%For Table column width calculation.
\def\mcWidth#1{\csname TY@F#1\endcsname+\tabcolsep}

%%Hacking center and right align for table
\def\cAlignHack{\rightskip\@flushglue\leftskip\@flushglue\parindent\z@\parfillskip\z@skip}
\def\rAlignHack{\rightskip\z@skip\leftskip\@flushglue \parindent\z@\parfillskip\z@skip}




\definecolor{titlecolor}{RGB}{43, 116, 183}
\definecolor{numbercolor}{RGB}{0, 62, 136}
\definecolor{tableheadrcolor}{RGB}{229, 229, 229}
\definecolor{unitednationsblue}{RGB}{231, 236, 247}






\begin{document}


\title{Table issue}


\begin{table*}[!htbp]
\caption{{} }
\label{table-wrap-50e8bb32765343db8fd393ec8c403ec6}{%
\fontsize{8pt}{10pt}\selectfont 
\def\arraystretch{1.5} 
\ignorespaces 
\centering 
\begin{tabulary}{\linewidth}{LLLLLLLLL}
\hline %\rowcolor{tableheadrcolor}
\multicolumn{5}{p{\dimexpr(\mcWidth{1}+\mcWidth{2}+\mcWidth{3}+\mcWidth{4}+\mcWidth{5})}}{\textbf{Table} \textbf{ 1. Zone of inhibition of }t\textbf{ ested microbe}s } &
   &
   &
   &
  \\%\rowcolor{unitednationsblue}
\multicolumn{1}{p{\dimexpr(\mcWidth{1})}}{\multirow{3}{\linewidth}{\textbf{S. No.}}} &
  \multicolumn{1}{p{\dimexpr(\mcWidth{2})}}{\multirow{3}{\linewidth}{\textbf{Tested Microbes}}} &
  \multicolumn{7}{p{\dimexpr(\mcWidth{3}+\mcWidth{4}+\mcWidth{5}+\mcWidth{6}+\mcWidth{7}+\mcWidth{8}+\mcWidth{9})}}{\textbf{Zone of inhibition (diameter in mm)}}\\%\rowcolor{unitednationsblue}
 &
   &
  \multicolumn{1}{p{\dimexpr(\mcWidth{3})}}{\multirow{2}{\linewidth}{\textbf{Control}}} &
  \multicolumn{1}{p{\dimexpr(\mcWidth{4})}}{\multirow{2}{\linewidth}{\textbf{Plant}}} &
  \multicolumn{1}{p{\dimexpr(\mcWidth{5})}}{\multirow{2}{\linewidth}{\textbf{Concentration of} \textbf{ SeNP}s\textbf{ 50 m}M}} &
  \multicolumn{4}{p{\dimexpr(\mcWidth{6}+\mcWidth{7}+\mcWidth{8}+\mcWidth{9})}}{\textbf{Minimum} \textbf{ Inhibitor}y\textbf{ Concentration (MIC})}\\%\rowcolor{unitednationsblue}
 &
   &
   &
   &
   &
  \textbf{10} \textbf{ \ensuremath{\mu }}l &
  \textbf{20} \textbf{ \ensuremath{\mu }}l &
  \textbf{30} \textbf{ \ensuremath{\mu }}l &
  \textbf{40} \textbf{ \ensuremath{\mu }}l\\%\rowcolor{unitednationsblue}
 1 &
  \textit{Staphylococcus} \textit{ aureu}s &
   20 &
   - &
   18 &
   5 &
   9 &
   11 &
   13\\%\rowcolor{unitednationsblue}
 2 &
  \textit{Bacillus} \textit{ subtili}s &
   27 &
   - &
   16 &
   3 &
   7 &
   10 &
   11\\%\rowcolor{unitednationsblue}
 6 &
  \textit{Aspergillus\textit{}} \textit{ nige}r\textit{} &
   - &
   - &
   20 &
   7 &
   13 &
   15 &
   17\\%\rowcolor{unitednationsblue}
\multicolumn{5}{p{\dimexpr(\mcWidth{1}+\mcWidth{2}+\mcWidth{3}+\mcWidth{4}+\mcWidth{5})}}{\multirow{2}{\linewidth}{ Control* - Gentamycin (1 mg/ml) Positive Control for Bacterial strains Fluconazole (1 mg/ml) Positive Control for Fungal strains}} &
   &
   &
   &
  \\%\rowcolor{unitednationsblue}
 &
   &
   &
   &
   &
   &
   &
   &
  \\
\hline 
\end{tabulary}\par 
}
\end{table*}


\end{document}

答案1

记住,保持简单...

姆韦

\documentclass{article}
\usepackage{geometry}
\usepackage{tabulary,booktabs,multirow,lipsum}
\begin{document}
\lipsum[4][1-10]
\begin{table}[h]
\belowcaptionskip10pt
\extrarowheight1ex 
\caption{Xxxxxxx xxxxxx xxxxx xxxxxxxx.}
\begin{tabulary}{\linewidth}{clcCCCCCC}\toprule
\multirow{3}{*}{No.} 
& \multirow{3}{*}{Tested Microbes} 
& \multicolumn{3}{c}{\parbox{10em}{\centering Zone de inhibition (diameter in mm)}} 
& \multicolumn{4}{c}{\parbox{10em}{\centering Minimum Inibitory Concentration (MCI)}} \\
\cmidrule(rl){3-5}\cmidrule(rl){6-9}
&  
& Control 
& Plan  
& \parbox{8em}{\centering Concentration of SeNPs 50 mM } 
& 10\,µl & 20\,µl & 30\,µl & 40\,µl \\
\midrule
1 & \emph{Staphilococus aureus} & 13 & 14 & 15 & 16 & 17 & 18 & 19\\
2 & \emph{Bacillus subtilis} & ... & ... \\
... & \\\bottomrule
\end{tabulary}
\end{table}
\lipsum[3][1-6]
\end{document}

答案2

我尝试了一些方法,但如果不知道输出应该是什么样子,就很难确保输出正确。实际上,手动设置multicolumn' 的宽度可以完成大部分工作。您可以考虑为像这样的复杂表格编写自己的代码。使用最后的代码,输出表如下所示。

我希望它能有所帮助,它肯定比以前更好了。我还在siunitx包装上添加了“µl”符号,其中µ应该是直立的。

\documentclass[9pt,twocolumn]{article}

\usepackage{amsmath,amsfonts,amssymb,balance,tabulary,graphicx,caption,fancyhdr}
\usepackage[utf8]{inputenc}
\usepackage[numbers,super,sort&compress]{natbib}
\usepackage{url,multirow,morefloats,floatflt,cancel,tfrupee}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{siunitx}

\definecolor{titlecolor}{RGB}{43, 116, 183}
\definecolor{numbercolor}{RGB}{0, 62, 136}
\definecolor{tableheadrcolor}{RGB}{229, 229, 229}
\definecolor{unitednationsblue}{RGB}{231, 236, 247}


\begin{document}

\title{Table issue}

\begin{table*}[!htbp]
\caption{{} }
\label{table-wrap-50e8bb32765343db8fd393ec8c403ec6}{%
\fontsize{8pt}{10pt}\selectfont 
\def\arraystretch{1.5} 
\ignorespaces 
\centering 
\begin{tabulary}{\linewidth}{LLLLLLLLL}
\hline %\rowcolor{tableheadrcolor}
\multicolumn{9}{p{9cm}}{\textbf{Table 1. Zone of inhibition of tested microbes}}
  \\%\rowcolor{unitednationsblue}
\multicolumn{1}{p{1cm}}{
    \multirow{3}{\linewidth}{\textbf{S. No.}}
  } 
  & \multicolumn{1}{p{3cm}}{
      \multirow{3}{\linewidth}{\textbf{Tested Microbes}}
    }
  & \multicolumn{7}{p{5.4cm}}{
      \textbf{Zone of inhibition (diameter in mm)}
    }
  \\%\rowcolor{unitednationsblue}
  & 
  & \multicolumn{1}{p{1cm}}{
      \multirow{2}{\linewidth}{\textbf{Control}}
    } 
  & \multicolumn{1}{p{1cm}}{
      \multirow{2}{\linewidth}{\textbf{Plant}}
    } 
  & \multicolumn{1}{p{2.6cm}}{
      \multirow{2}{\linewidth}{\textbf{Concentration of SeNPs 50 mM}}
    } 
  & \multicolumn{4}{p{3.2cm}}{
      \textbf{Minimum Inhibitory Concentration (MIC})
    }
  \\%\rowcolor{unitednationsblue}
 & & & & 
  & \textbf{\SI[detect-weight]{10}{\micro\litre}} 
  & \textbf{\SI[detect-weight]{20}{\micro\litre}} 
  & \textbf{\SI[detect-weight]{30}{\micro\litre}} 
  & \textbf{\SI[detect-weight]{40}{\micro\litre}}
  \\%\rowcolor{unitednationsblue}
 1 
  & \textit{Staphylococcus aureus} 
  & 20 & -- & 18 & 5 & 9 & 11 & 13
  \\%\rowcolor{unitednationsblue}
 2 
  & \textit{Bacillus subtilis} 
  & 27 & -- & 16 & 3 & 7 & 10 & 11
  \\%\rowcolor{unitednationsblue}
 6 
  & \textit{Aspergillus niger} 
  & -- & -- & 20 & 7 & 13 & 15 & 17
  \\%\rowcolor{unitednationsblue}
\multicolumn{9}{p{10cm}}{
    \multirow{2}{\linewidth}{Control* -- Gentamycin (1 mg/ml) Positive Control for Bacterial strains Fluconazole (1 mg/ml) Positive Control for Fungal strains}
  }
  \\%\rowcolor{unitednationsblue}
 & & & & & & & &
  \\
\hline 
\end{tabulary}\par 
}
\end{table*}


\end{document}

答案3

桌子设计总是取决于个人喜好或一些严格/死板的要求。让我们假设,最后一种情况不是你的情况 :-)

在您的表格设计中考虑以下几点是明智的:

  • 对于单位使用siunitx
  • 对于化学表达式使用mhchem
  • 供表格注释使用threeparttable
  • \multicolum只在真正需要的地方使用
  • 对于具有多行文本的单元格,使用makecell同名的包及其宏(这需要手动拆分文本)

完整的 MWE 是:

\documentclass[9pt,twocolumn]{article}
\usepackage{booktabs,           % new
            makecell,           % new
            multirow, 
            tabularx,           % instead of tabulary
            threeparttable}     % new
\usepackage[skip=1ex, font=bf, singlelinecheck=off]{caption}
\usepackage{siunitx}            % new
\usepackage[version=4]{mhchem}  % new

\begin{document}
    \begin{table*}
    \begin{threeparttable}
\caption{Zone of inhibition of tested microbes}
    \label{table-wrap-50e8bb32765343db8fd393ec8c403ec6}
    \centering
    \sisetup{table-column-width=2.5em, table-format=2.0}
\begin{tabularx}{\linewidth}{@{} c >{\itshape}l cc>{\centering}X SSSS}
    \toprule
\multirow{3.4}{*}{\makecell{S.\\ No.}} 
\multirow{3.4}{*}{\makecell{S.\\ No.}}
    &   \multirow{3.4}{*}{\textup{Tested Microbes}}
    &   \multicolumn{3}{c}{\makecell{Zone de inhibition\\ (diameter in mm)}}
        &   \multicolumn{4}{c}{\makecell{Minimum Inibitory\\ Concentration (MCI)}}    \\
    \cmidrule(r){3-5}\cmidrule{6-9}
    &   &   Control\tnote{*}
            &   Plan
                &   \makecell{Concentration\\ of \ce{SeNP} \SI{50}{mM}}
                    &   \SI{10}{\micro\litre}
                        &   {\SI{20}{\micro\litre}}
                            &   {\SI{30}{\micro\litre}}
                                &   {\SI{40}{\micro\litre}}         \\
    \midrule
 1  & Staphylococcus aureus     & 20 & -- & 18 & 5  & 9 & 11 & 13   \\
 2  & Bacillus subtilis         & 27 & -- & 16 & 3  & 7 & 10 & 11   \\
 6  & Aspergillus niger         & -- & -- & 20 & 7 & 13 & 15 & 17   \\
    \midrule[\heavyrulewidth]
\end{tabularx}
\begin{tablenotes}[para,raggedright]\footnotesize
\item[*] Gentamycin (\SI{1}{mg/ml}) Positive Control for Bacterial strains, 
         Fluconazole (\SI{1}{mg/ml}) Positive Control for Fungal strains
\end{tablenotes}
    \end{threeparttable}
    \end{table*}
\end{document}

在此处输入图片描述

附录: 如果tabulary必须使用,则makecell不得使用。相反,应该使用\parbox,类似于弗兰他的回答

\documentclass[9pt,twocolumn]{article}
\usepackage{booktabs,           % new
            multirow,
            tabulary,           %
            threeparttable}     % new
\usepackage[skip=1ex, font=bf, singlelinecheck=off]{caption}
\usepackage{siunitx}            % new
\usepackage[version=4]{mhchem}  % new

\begin{document}
    \begin{table*}
    \begin{threeparttable}
\caption{Zone of inhibition of tested microbes}
    \label{table-wrap-50e8bb32765343db8fd393ec8c403ec6}
    \sisetup{table-column-width=2.5em, table-format=2.0}
\begin{tabulary}{\linewidth}{ C >{\itshape}L CC C SSSS}
    \toprule
\multirow{3}{2em}{\centering S.\\No.}
    &   \multirow{3}{*}{\textup{Tested Microbes}}
        &   \multicolumn{3}{c}{Zone de inhibition (diameter in mm)}
                        &   \multicolumn{4}{c}{\parbox{10em}{\centering
                                                             Minimum Inhibitory Concentration (MCI)}} \\
    \cmidrule(r){3-5}\cmidrule(l){6-9}
    &   &   Control\tnote{*}
            &   Plan
                &   \parbox{8em}{\centering Concentration of SeNPs \SI{50}{mM}\strut}
                    &   \SI{10}{\micro\litre}
                        &   \SI{20}{\micro\litre}
                            &   \SI{30}{\micro\litre}
                                &   \SI{40}{\micro\litre}     \\
    \midrule
 1  & Staphylococcus aureus     & 20 & -- & 18 & 5  & 9 & 11 & 13   \\
 2  & Bacillus subtilis         & 27 & -- & 16 & 3  & 7 & 10 & 11   \\
 6  & Aspergillus niger         & -- & -- & 20 & 7 & 13 & 15 & 17   \\
    \midrule[\heavyrulewidth]
\end{tabulary}
\begin{tablenotes}[para,raggedright]\footnotesize
\item[*] Gentamycin (\SI{1}{mg/ml}) Positive Control for Bacterial strains,
         Fluconazole (\SI{1}{mg/ml}) Positive Control for Fungal strains
\end{tablenotes}
    \end{threeparttable}
    \end{table*}
\end{document}

在此处输入图片描述

相关内容