1

I have a table, which is done using tabulary. The output are looking good, if there is no multi-row/column. But, the output is very bad, if it contains multi row. Can anyone help me out?.

\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
    Is that an auto-generated table from some sort of conversion software? No offense, but the code is such a mess... (Example: \textbf{Minimum} \textbf{ Inhibitor}y\textbf{ Concentration (MIC})}) – Disenchanted Lurker Dec 5 '19 at 13:54
  • Yes. You are right!. – Samjith Dec 5 '19 at 13:55
2
+50

Remember, keep it simple ...

mwe

\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}
  • Is there any solution, by not giving width by manually?. – Samjith Dec 6 '19 at 7:53
  • @TVMBoy tabulary is just to fit huge tables to the maximum desired width (in my example, I guessed it would be the text width) but LaTeX cannot guess your thoughts (i.e., what maximal width do you want?) If your problem is only have to write {\linewidth} each time, you can always write a macro. Or in case that the final width doesn't matter (i.e,, in narrow tables) use tabular with only r, l, c and p{<width>} columns, where only the p column allow cell line breaks (is equivalent to use a \parbox{<width>}{...} inside each cell in a l column). – Fran Dec 6 '19 at 10:54
  • make sense. Could you update your answer with condition, both multirow and multicolumn came combined. ie) the last 2 rows in my example (Control* - Gentamycin....). – Samjith Dec 6 '19 at 12:11
  • @TVMBoy Why? As this table take the all the text width, after \end{tabulary} write just what you want. That is, some like \par\medskip * Bla bla bla ... and that is all. In case of a smaller table, to fit the note to the table width, after the \bottomrule make again a \multicolumn{9}{l}{* ... } where ... could a \parbox if the note is too large, and that is all again. In any case you will need combine it with a \multirow command. – Fran Dec 6 '19 at 15:19
  • I just wanna to know that, how to code multirow with multicolumn. – Samjith Dec 9 '19 at 13:04
0

I tried something, but it's pretty hard to make sure the output is correct without knowing what it should look like. Actually, setting manually the widths of the multicolumn's did most of the job. You might consider writing your own code for complicated tables like this one. With the code at the end, the output table looks like this.

I hope it helps a little, it is surely better than it was. I also added to siunitx package to write the "µl" symbol, where the µ should be upright.

\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}
  • Sorry. This is not what i am expecting. I cannot give width by manualy. 😞 – Samjith Dec 6 '19 at 7:50
0

The table design always depends on personal preferences how table should like or on some strict/rigid requirements. Lets suppose, that the last is not your case :-)

In your table design is sensible to consider the following:

  • for units use siunitx package
  • for chemistry expressions use mhchem package
  • for notes in table use threeparttable
  • using \multicolum only where is really necessary
  • for cells with multi line text use makecell package and its macro with the same name (this require manual breaking of text)

Complete MWE is:

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

enter image description here

Addendum: In case that use of tabulary is mandatory, than makecell may not be used. Instead it should be used \parbox, similarly as do Fran do in his answer:

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

enter image description here

  • Could you edit your post by using tabulary. – Samjith Dec 6 '19 at 7:51
  • @TVMBoy, unfortunately makecell (and any nested table environments) doesn't work with tabulary. Therefore instead it in proposed solution is used tabularx. If tabulary is an imperativ, than you instead makecell need to use solution proposed by @fran: \parbox{<width>}{<cwll's content>} where you need to manual set its width. I will add this option asap. – Zarko Dec 6 '19 at 10:39
  • @TVMBoy, see addendum, where is solution with tabulary. – Zarko Dec 6 '19 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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