使用表格時行之間的文字重疊

使用表格時行之間的文字重疊

我有一個表格,是使用表格完成的。如果沒有多行/列,輸出看起來不錯。但是,如果它包含多行,輸出會非常糟糕。誰能幫我嗎?

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

在此輸入影像描述

相關內容