1

I have several wide table which I think using word would be difficult to standardized and display the table clearly. So I try to learn latex to make this table but have encounter quite a lot of problems.

Q1 The plus-minus sign didn't center aligned with the column header (Wet or Dry).

Q2 The column header Mean \pm SD\textsubscript{n} cannot be displayed correctly with some error warning and also with wrong alignment with the data below

Q3 How can I have all the S column with the same column width even if that column doesn't have any data like Site F, Season Dry in this example

\documentclass{article}

\usepackage{array}
\usepackage{tabularx}
\usepackage[singlelinecheck=false]{caption}
\usepackage{changepage}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage[a4paper,top=0.05cm,bottom=0.05cm,left=0.1cm,right=0.1cm,marginparwidth=0.1cm, landscape, total ={210mm,297mm}]{geometry}
\usepackage{rotating}
\usepackage{caption}
\usepackage{array}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage[separate-uncertainty=true]{siunitx}

\sisetup{
    table-number-alignment=center,
    separate-uncertainty=true,
    table-figures-integer = 2,
    table-figures-decimal = 2}

\begin{document}
    \begin{landscape}
        \begin{sidewaystable}
            \centering
            \caption{Test}
            \tiny
            \begin{tabular}{lc*{12}{S[separate-uncertainty,
                        table-figures-uncertainty=1]@{\hspace{1cm}}}}
                    \toprule
                    & Site  & \multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} & \multicolumn{2}{c}{C} & \multicolumn{2}{c}{D} & \multicolumn{2}{c}{E} & \multicolumn{2}{c}{F} \\
                    \multicolumn{1}{c}{Species}      & Season &\multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry}   & \multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry}   & \multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry}   & \multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry}   & \multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry}   & \multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry} \\
                    \midrule
                    & Tracer & Mean \pm SD\textsubscript{n}
                    & & & & & & & & & & & \\
                    \midrule
                    \multirow{2}{*}{\shortstack{\textit{Genus A}\\ \textit{\indent{Species A}}}} & N     &       &       &       &       &       & 81.82\pm0.36\textsubscript{(4)} &       &       &93.83\pm0.99\textsubscript{(8)} &14.25\pm0.49\textsubscript{(2)} &54.6\pm0.23\textsubscript{(4)} &  \\
                    & C     &       &       &       &       &       & -19.73\pm0.29\textsubscript{(4)} &       &       &-26.62\pm0.27\textsubscript{(8)} &-57.3\pm0.14\textsubscript{(2)} &-36.65\pm0.31\textsubscript{(4)} &  \\

                    \multirow{2}{*}{\shortstack{\textit{Genus B}\\ \textit{\indent{Species B}}}}& N     &15.14\pm1.21\textsubscript{(16)} &13.1\pm1.2\textsubscript{(18)} &13.7\pm0.85\textsubscript{(16)} &12.55\pm0.84\textsubscript{(16)} & 12.32\pm0.64\textsubscript{(15)} & 12.27\pm0.47\textsubscript{(16)} & 12.28\pm0.59\textsubscript{(16)} & 12.61\pm0.29\textsubscript{(10)} &23.43\pm0.4\textsubscript{(16)} &14.06\pm0.28\textsubscript{(15)} &14\pm0.82\textsubscript{(5)} &  \\
                    & C     &-18.38\pm0.64\textsubscript{(16)} &-17.25\pm0.44\textsubscript{(18)} &-16.66\pm0.39\textsubscript{(16)} &-16.67\pm0.59\textsubscript{(16)} & -16.77\pm0.3\textsubscript{(15)} & -15.98\pm0.37\textsubscript{(16)} & -16.59\pm0.38\textsubscript{(16)} & -16.05\pm0.22\textsubscript{(10)} &-16.6\pm0.3\textsubscript{(16)} &-16.06\pm0.36\textsubscript{(15)} &-15.72\pm0.45\textsubscript{(5)} &  \\
                            \end{tabular}
                \end{sidewaystable}
            \end{landscape}
    \end{document}

I have been searching for quite a long time to fix the problem but still without success. Any help would be highly appreciated. Thank you in advance!!

  • 1
    Welcome to TeX SX! Your table cannot really fit on an A4 landscape format, even with the \tiny size (which makes it almost unreadable. You should split your table in two more rows, with a larger font size. – Bernard Jul 24 '18 at 0:07
  • Bernard, Thanks for your prompt reply. May i know what do you mean by splitting the table in two more rows? – Jason Yau Jul 24 '18 at 4:29
  • I meant a first series of rows up to the columns with a C head then asecond series, with the first two columns repeated, and the columns with heads from D to F. Alternatively, you can swap rows and columns, but the feasability depends on your real table: it can be useful if you have many columns and not too many rows. – Bernard Jul 24 '18 at 8:28
  • That would be a good idea for a short table. Unfortunately, my table contains full pages of row. May I know if the table fit the A4 landscape, how can I solve my encountered problems? – Jason Yau Jul 24 '18 at 11:14
  • It can hardly fit with the font size and margins you specifiede (\tiny), but no one will read a table with such a small font size. May I ask why you want to add 1cm between the S columns? The normal spacing is 2× 6pt ~ 4mm. Also, I don't understand what the \textsubscript{16} and the like denote. – Bernard Jul 24 '18 at 11:39
1

Here are two possibilities: you can fit your table on a landscape a4 paper with the minimalistic margins you chose, if you play with the value of \tabcolsep in \footnotesize , which makes it more readable than \tiny. I also used the simpler syntax of siunitx for the uncertainty.

However, I suggest a second solution, with the sample sizes on a separate line. With this layout, we can have a larger tabcolsep and the \small font size. Below, you can compare the results.

\documentclass{article}

\usepackage{array}
\usepackage{tabularx}
\usepackage[singlelinecheck=false]{caption}
\usepackage{changepage}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage[a4paper, vmargin=0.05cm, hmargin=0.1cm, marginparwidth=0.1cm,total={210mm,297mm}, showframe]{geometry}
\usepackage{rotating}
\usepackage{caption}
\usepackage{array}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{multirow, makecell, xcolor}
\usepackage[separate-uncertainty=true]{siunitx}

\begin{document}

  %\begin{landscape}
    \begin{sidewaystable}
    % \begin{table}
            \centering
            \sisetup{
    table-number-alignment=center,
    separate-uncertainty=true,%
    table-format =-2.2,
    separate-uncertainty,
    table-figures-uncertainty=1, table-space-text-post=(16)}
            \caption{Test}
            \footnotesize
    \setlength{\tabcolsep}{2.3pt}
            \begin{tabular}{>{\itshape}l@{}c*{12}{S}@{}}%
                    \toprule
                    & \multirowcell{2}{Site\\ Season} & \multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} & \multicolumn{2}{c}{C} & \multicolumn{2}{c}{D} & \multicolumn{2}{c}{E} & \multicolumn{2}{c}{F} \\
                    \multicolumn{1}{c}{\textrm{Species}} & & {Wet} &{Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} \\
                    \midrule
                    & Tracer & {Mean $ ±$ SD\textsubscript{n}}
                    & & & & & & & & & & & \\
                    \midrule
                    \multirowcell{2}{Genus A \\ Species A} & N & & & & & & 81.82 (36)\textsubscript{(4)} & & &93.83(99)\textsubscript{(8)} &14.25\pm0.49\textsubscript{(2)} &54.6\pm0.23\textsubscript{(4)} & \\
                    & C & & & & & & -19.73(29)\textsubscript{(4)} & & &-26.62(27)\textsubscript{(8)} &-57.3(14)\textsubscript{(2)} &-36.65(31)\textsubscript{(4)} & \\
                    \addlinespace
                    \multirowcell{2}{Genus B \\ Species B}& N &15.14\pm1.21\textsubscript{(16)} &13.1\pm1.2\textsubscript{(18)} &13.70 (85)\textsubscript{(16)} &12.55(84)\textsubscript{(16)} & 12.32 (64)\textsubscript{(15)} & 12.27\pm0.47\textsubscript{(16)} & 12.28\pm0.59\textsubscript{(16)} & 12.61\pm0.29\textsubscript{(10)} &23.43(40)\textsubscript{(16)} &14.0 (28)\textsubscript{(15)} &14.00(82)\textsubscript{(5)} & \\
                    & C &-18.38 (64)\textsubscript{(16)} &-17.25 (44)\textsubscript{(18)} &-16.66 (39)\textsubscript{(16)} &-16.6 (59)\textsubscript{(16)} & -16.77 (30)\textsubscript{(15)} & -15.98 (37)\textsubscript{(16)} & -16.59 (38)\textsubscript{(16)} & -16.05 (22)\textsubscript{(10)} &-16.6 (3)\textsubscript{(16)} &-16.06 (36)\textsubscript{(15)} &-15.72 (45)\textsubscript{(5)} & \\
                            \end{tabular}
       %\end{table}
       \end{sidewaystable}
    % \end{landscape}

    \begin{sidewaystable}
    % \begin{table}
            \centering
            \sisetup{
    table-number-alignment=center,
    separate-uncertainty=true,%
    table-format =-2.2,
    separate-uncertainty,
    table-figures-uncertainty=1}
            \caption{Test}
            \small
    \setlength{\tabcolsep}{4pt}
            \begin{tabular}{>{\itshape}l@{}c*{12}{S}@{}}%
                    \toprule
                    & \multirowcell{2}{Site\\ Season} & \multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} & \multicolumn{2}{c}{C} & \multicolumn{2}{c}{D} & \multicolumn{2}{c}{E} & \multicolumn{2}{c}{F} \\
                    \multicolumn{1}{c}{\textrm{Species}} & & {Wet} &{Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} \\
                    \midrule
                    & Tracer & {Mean $ ±$ SD\textsubscript{n}}
                    & & & & & & & & & & & \\
                    \midrule
                    \multirowcell{3}{Genus A \\ \\Species A} & N & & & & & & 81.82 (36) & & &93.83(99) &14.25\pm0.49 &54.6\pm0.23 & \\
     & & & & & & &{ {(4)}} & & &{ (8)} & {(2)} & { {(4)}} \\
                        & C & & & & & & -19.73(29) & & &-26.62(27) &-57.3(14) &-36.65(31) & \\
     & & & & & & & { (4)} & & &{ (8)} & {(2)} & { {(4)}}\\
                        \addlinespace[2ex]
                        \multirowcell{3}{Genus B \\ \\Species B}& N &15.14\pm1.21 &13.1\pm1.2 &13.70 (85) &12.55(84) & 12.32 (64) & 12.27\pm0.47 & 12.28\pm0.59 & 12.61\pm0.29 & 23.43(40) &14.0 (28) &14.00(82) & \\
     & & {(16)} & {(18)} & {(16)} & {(16)} & {(15)} & {(16)} & {(16)} & {(10)} & {(16)} & {(15)} & {(5)} \\
    \ & C &-18.38 (64) & -17.25 (44)\ &-16.66 (39) &-16.6 (59) & -16.77 (30) & -15.98 (37) & -16.59 (38) & -16.05 (22) & -16.6 (3) & -16.06 (36) &-15.72 (45) & \\
     & & {(16)} & { (18)} & {(16)} & {(16)} &{(15)} & {(16)} & {(16)} & {(10)} & {(16)} &{(15)} & {(5)} \\
                                \end{tabular}
       %\end{table}
       \end{sidewaystable}

    \end{document}

enter image description here

enter image description here

  • Thank you. The second solution do look better. I would try to see how it looks with my real data with far more species. Hopefully, it won't be too bulky or extend to several pages. Before that, I have noticed that in Site F, the "Wet" and "Dry" season is not centre aligned under the Site F. Any idea of why it happens? Maybe because of insufficient space? – Jason Yau Jul 25 '18 at 9:41
  • There's enough space in the second solution. It's simply because the last column is empty except the column head, which is not as wide as the cells with numbers. If this column should have no numbers, just add this in your preamble: \newlength{\mylength} \settowidth{\mylength}{$-55.55\pm0.55$}, and replace {Dry} in the last column with {\makebox[\mylength]{Dry}} (the simplest would have been with \hphantom{...}, unfortunately it doesn't work well with the S column type.) – Bernard Jul 25 '18 at 10:41
  • Thank you for your answer. It did exactly what I want. After trying both of your solutions, I prefer to use a modified first solution with font size between scriptsize and tiny and a further down of the column separation although the font size maybe a little bit hard to read without zooming in. I didn't choose the second solution as the actual table will cover too many pages due to the extra two rows. Plus the (n) is not quite align to the plus and minus sign. Big thanks to your help! – Jason Yau Jul 26 '18 at 10:28
1

You should do two tables:

\documentclass{article}

\usepackage{array}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{changepage}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage[a4paper,top=0.05cm,bottom=0.05cm,left=0.1cm,right=0.1cm,marginparwidth=0.1cm, landscape, total ={210mm,297mm}]{geometry}
\usepackage{rotating}
\usepackage{caption}
\usepackage{array}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage[separate-uncertainty=true]{siunitx}

\newcommand{\ts}[1]{\textsubscript{#1}}

\begin{document}
\begin{table}
\caption{Test}
\centering
\begin{tabular}{
  lc*{6}{S[table-format=-2.2(2),table-space-text-post=\ts{(00)}]}
}
\toprule
& Site  & \multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} & \multicolumn{2}{c}{C} \\
\cmidrule(lr){3-4} \cmidrule(lr){5-6} \cmidrule(lr){7-8}
\multicolumn{1}{c}{Species} & Season & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} \\
\midrule
& Tracer & {Mean $\pm$ SD$_n$} \\
\midrule
\textit{Genus A}   & N &       &       &       &       &       & 81.82\pm0.36\ts{(4)} \\
\textit{Species A} & C &       &       &       &       &       & -19.73\pm0.29\ts{(4)} \\
\textit{Genus B}   & N &  15.14\pm1.21\ts{(16)} &  13.1 \pm1.2\ts{(18)} &13.7\pm0.85\ts{(16)} &12.55\pm0.84\ts{(16)} & 12.32\pm0.64\ts{(15)} & 12.27\pm0.47\ts{(16)} \\
\textit{Species B} & C & -18.38\pm0.64\ts{(16)} & -17.25\pm0.44\ts{(18)} &-16.66\pm0.39\ts{(16)} &-16.67\pm0.59\ts{(16)} & -16.77\pm0.3\ts{(15)} & -15.98\pm0.37\ts{(16)} \\
\midrule[\heavyrulewidth]
\end{tabular}
\begin{tabular}{
  lc*{6}{S[table-format=-2.2(2),table-space-text-post=\ts{(00)}]}
}
& Site  & \multicolumn{2}{c}{D} & \multicolumn{2}{c}{E} & \multicolumn{2}{c}{F} \\
\cmidrule(lr){3-4} \cmidrule(lr){5-6} \cmidrule(lr){7-8}
\multicolumn{1}{c}{Species} & Season & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} \\
\midrule
& Tracer & {Mean $\pm$ SD$_n$} \\
\midrule
\textit{Genus A}   & N &       &       &93.83\pm0.99\ts{(8)} &14.25\pm0.49\ts{(2)} &54.6\pm0.23\ts{(4)} &  \\
\textit{Species A} & C &       &       &-26.62\pm0.27\ts{(8)} &-57.3\pm0.14\ts{(2)} &-36.65\pm0.31\ts{(4)} &  \\
\textit{Genus B}   & N & 12.28\pm0.59\ts{(16)} & 12.61\pm0.29\ts{(10)} &23.43\pm0.4\ts{(16)} &14.06\pm0.28\ts{(15)} &14\pm0.82\ts{(5)} &  \\
\textit{Species B} & C & -16.05\pm0.22\ts{(10)} &-16.6\pm0.3\ts{(16)} &-16.06\pm0.36\ts{(15)} &-15.72\pm0.45\ts{(5)} &  & -00.00\pm0.00\ts{(00)} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

  • Thank you for your answer, the table looks great after splitting into two rows, unfortunately my real data have far more species. This separation would then seems to be difficult for people to compare the same species in different site. I have noticed that you make the empty data in site F Dry season to make it the same width as others. Is that anyway to hide this data but remain that width? – Jason Yau Jul 25 '18 at 9:44

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.