0

I'm trying to make it look a professional, or at least better from all the vertical lines. tables in LaTeX, as they tend to be pretty ugly and hard to maintain most of the time. Almost all examples/how-tos about tables produce results which are kind of embarrassing,

would anyone here expert to add some touches to my table please

% Initialising the document type with some formatting information
\documentclass[pdftex,12pt,a4paper]{article}

% Allow urls to be split at end of line
\PassOptionsToPackage{hyphens}{url}
% Allow tables to be read in from CSV and use centered width formatted columns
\usepackage{csvsimple,booktabs}
\usepackage{siunitx}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{tabularx,ragged2e}

% Allow tables and figures to be referenced by name
% https:,,tex.stackexchange.com,questions,397031,conflict-with-hyperref-and-titlesec
\usepackage{xr-hyper}
\usepackage[hidelinks]{hyperref}

% Allow long things to be split
\usepackage{seqsplit}

% Remove the indentation when starting new paragraphs, but still add a blank line.
\usepackage[parfill]{parskip}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

% Allow multiple line comments.
\usepackage{verbatim}

% Package for dealing with graphics - for figures.
\usepackage{graphicx}

% Allows a space to be included after inserting formatted text.
\usepackage{xspace}

% add line numbers
\usepackage{lineno}
\linenumbers

%% Allow more control over chapters and sections etc.
%\usepackage{titlesec}
%
%% Allow the paragraph tag to mark extra section depth  
%\setcounter{secnumdepth}{4}
%\titleformat{\paragraph}
%{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
%\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

% Allow single pages to be changed to landscape, including in PDF preview.
\usepackage{lscape}

% Allow figures to be rotated and included in landscape.
\usepackage{rotating}

\usepackage{adjustbox}

% Allow wrapping for landscape pages
\usepackage{afterpage}

% Allow columns to span multiple rows.
\usepackage{multirow}
\usepackage{array}

% More formatting options for lists
\usepackage{enumitem}

% Allow different colouring for individual cells in tables.
\usepackage[table]{xcolor}

% Allow more complex formatting of tables.
\usepackage{tabularx}

% Special centred and auto-widthed table
\newcolumntype{Y}{>{\centering\arraybackslash}X}

% Allow page spanning tables
\usepackage{longtable}

% Allow tables to be forced into position with [H]. - don't remember what this meant
% plaintiff should force caption to top
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}

% Parnotes package organises footnotes in tables
\usepackage[roman]{parnotes}
\makeatletter
\def\parnoteclear{%
    \gdef\PN@text{}%
    \parnotereset
} 

% To allow ticks in tables (by typing \tick)
\usepackage{pifont}
\newcommand{\tick}{\ding{52}}

% Package to allow some maths stuff (±)
\usepackage{textcomp}

% Set the margin widths
\usepackage[top=2.45cm,bottom=2.45cm,left=3.17cm,right=3.17cm,twoside]{geometry}

% Allow figures and tables to be named in different ways.
\usepackage{chngcntr}
% Count tables individually within each section.
%\counterwithin{table}{section}
%\counterwithin{figure}{section}

% Allow Harvard formatting for references - reference with \citep{key,key2,etc.}. Or \citept{key} to reference as Name et al. (2012)
% Remember that you have to run Macros -> Applescript -> Bibliography (?r) to make references appear
% The style file for this is referred to in the section at the bottom.
\usepackage{natbib}
\setlength{\bibsep}{0.0pt}
\bibpunct{(}{)}{;}{a}{,}{,}

% First line adds the reference section to the Contents page, second line renames it from 'Bibliography' to 'References'
\usepackage[nottoc,notlof,notlot]{tocbibind}
\settocbibname{References}

% This package allows a list of abbreviations to be created (make sure it is added to the contents - "intoc").
\usepackage{nomencl}
\makenomenclature

% double quotation
\usepackage{csquotes}

% Format the document with double line spacing. - should this be 1.655 or 2
%\linespread{1.7}
% Allow the gap around captions to be increased to aid legibility on tables
\usepackage{caption} 
\captionsetup[figure]{font=scriptsize,labelfont=scriptsize}
% Below is probably preferable - turns off double line spacing for figure legends and within tables (makes all tables much smaller)
\usepackage{setspace}
%\doublespacing
\onehalfspacing

% Allow text to be placed at the bottom of a page
\newenvironment{bottompar}{\par\vspace*{\fill}}{\clearpage}

% Allow double spacing in tables - usually reverted to single by setspace
\usepackage{etoolbox}
\AtBeginEnvironment{tabularx}{\doublespacing}

\newcommand*{\TitleFont}{%
\usefont{\encodingdefault}{\rmdefault}{b}{n}%
\fontsize{12}{20}%
\selectfont}

\begin{document}


    \begin{landscape}
        \begin{table}[]
        \centering

        \caption{Summary of transposable elements }
        \label{tab:Table1}
        \begin{adjustbox}{width=1.8\textwidth}
        \begin{tabular}{|cc|ccc|ccc|ccc|ccc|}
        \hline

        Class & Order & \multicolumn{3}{c}{rom }  & \multicolumn{3}{c}{act} & \multicolumn{3}{c}{erus} & \multicolumn{3}{c}{\cos} \\
         &  & Numbers & Length (bp) & \%  & Numbers & Length (bp) & \% & Numbers & Length (bp) & \% & Numbers & Length (bp) & \% \\
         \hline
          \hline
        \begin{tabular}[c]{@{}c@{}}Class I\\ \end{tabular} &  &  &   &   &  &  &   &  &  &  &  &   &   \\
         \hline

         &SINEs:               & 255687    & 30551159 & 1.52            & 257887  & 31080491  & 1.56             & 261248   &  31533761  & 1.57                    & 258371           & 30783770    &1.42 \\
         &Alu/B1               & 0 & 0     & 0.00                       & 0  & 0   & 0.00                        & 0       & 0      & 0.00                                       & 0       &0    & 0.00  \\
         &MIRs                 & 247894 & 30250569     & 1.51           & 249065  & 30760408   & 1.54            & 251376   & 31188301      & 1.55                 & 248923       &30437726    &1.40  \\
         &LINEs:               & 498627 & 207732214   & 10.37           & 501561  & 211005106  & 10.59           &516019  &220321176   &10.97                      & 543212      &226312996    &10.42  \\
         &LINE1               & 338909 & 163725095   & 8.17             & 342054  & 166954821   & 8.38           &354388  &175466399   &8.73                       &382755      &182566388     &8.40  \\
         &LINE2               & 133681  & 37311794    & 1.86            & 133693  & 37430629   &1.88             &135350   &38013575    &1.89                      &134657      &37312366      &1.72 \\
         &L3/CR1              & 16230   &3946140     & 0.20             & 16295   & 3952685  &0.20               &16386    &3999393     &0.20                      &16301         &3896521     &0.18 \\
         &RTE                 & 8327   & 2349410      & 0.12            & 8280   & 2342043   & 0.12              &8320    &2362314     &0.12                       &8391        &2315634     &0.11 \\

         \hline  
         &LTR elements:        & 2368202 & 360743057   & 18.00         &2138613 & 331038087   & 16.61           &2043931   &305371407   &15.20                     &2399880      &376465663   &17.33 \\
         \hline
         &ERVL                 & 603471 & 94653879   & 4.72            & 535533 & 89635873  &4.50               &457960   &74681407   &3.72                        &589003      &95266242     &4.39 \\
         &ERVL-MaLRs            & 936686 & 137736037  & 6.87           & 757066 & 122605363  &6.15              &683557   &105114613   &5.23                       &927914      &138867517    &6.39 \\
         &ERV\_classI            & 401868 & 69495491  &3.47            & 476978 &72572164  &3.64                &458525   &72184510   &3.59                        &442380      &80571827     & 3.71\\
         &ERV\_classII           & 179048 & 21382713  &1.07            & 143640 & 16451857  & 0.83              &146189     &18906035   &0.94                      &198036        &22430344   &1.03 \\
        \hline
        \hline
        \begin{tabular}[c]{@{}c@{}}Class II\\

           \end{tabular} &  &  &   &      &  &   &   &  &  &  &  &   &  \\
            \hline
         & DNA transposons:    & 259000 &53746062  & 2.68             & 261351 & 54598424  & 2.74                     &264855  &55556571  &2.77                   & 265748      &54859043     &2.53 \\

         \hline
         & hAT-Charlie    &153463 & 28637685  & 1.43                 & 154577 & 29132748 & 1.46                      &156022  & 29603550  &1.47                   & 156955       &29239810    &1.35  \\
         & TcMar-Tigger    &36981 & 11185164  & 0.56                  & 38120 & 11441081 &0.57                      &39444   &11766559  &   0.59                  & 38989       &11514055   &0.53 \\

          \hline
         &Rolling-circles    & 659955 & 72981412  &3.64               & 803681 & 84486255 & 4.24                      &889437   &94191508  & 4.69                 & 738026       &79989304   &3.68 \\

          \hline
         &Unclassified.      & 3128 & 509710  & 0.03                 & 3147 & 512316 & 0.03                          &3191   &518292  & 0.03                     & 3167       &510872   &0.02  \\

            \hline 
        Total &              & 0 & 00000  & 000.25                & 0 &712929637  & 35.78                         & X & 00000 & 300
        \end{tabular}
        \end{adjustbox}
        \end{table}
        \end{landscape}

\end{document}
11
  • 3
    Could you include the necessary \documentclass and \usepackage so that we can copy, paste, and compile your example? The general reference for better looking tables is the booktabs package and its documentation. Have you looked through that?
    – Teepeemm
    Mar 13, 2020 at 22:38
  • 1
    siunitx might also come in handy in order to improve the alignment of numbers.
    – leandriis
    Mar 13, 2020 at 22:39
  • 1
    Don't you get an error message from this code complaining about \cos being used outside of math mode?
    – leandriis
    Mar 13, 2020 at 22:59
  • 1
    Regarding "look professional", "tables in LaTeX [...] tend to be pretty ugly", "produce results which are kind of embarrassing", "add some touches to my table": could you please clarify what your expected output looks like? "better" might be quite subjective. Since you already mentioned vertical lines, why not start and remove them entirely?
    – leandriis
    Mar 13, 2020 at 23:03
  • 1
    I assume that you refer to the error message. Actually, your code results in such an error message that should be dealt with before touching the table to improve its look. Please never ever ignore error messages! Even if you get something that on first glance resembles a pdf file, there can still be issues with it. After an error, TeX only tries to recover enough to syntax check more of the file, it does not try to make sensible output after an error.
    – leandriis
    Mar 13, 2020 at 23:06

2 Answers 2

5

How about this? I removed all vertical lines, replaced some horizontal lines with a vertical spacing, reduced the fonntsize and the intercolumn spacing. Furthermore, the columns with numerical contents use the S columntype, from siunitx , to improve the legibility of the numbers.

\documentclass{article}
\usepackage{lscape}
\usepackage{adjustbox}
\usepackage{array, booktabs, caption, multirow}
\usepackage{siunitx}
\usepackage[table, svgnames]{xcolor}

\begin{document}

\begin{landscape}
\begin{table}[]
\centering\small
\setlength{\tabcolsep}{3pt}
\setlength{\extrarowheight}{2pt}
\caption{Summary of transposable elements }
\label{tab:Table1}
\begin{tabular}{@{}l@{\,}r*{4}{S[table-format=7.0]@{\enspace}S[table-format=9.0]@{\enspace}S[table-format=2.2,table-number-alignment=center]}@{}}
\toprule
 \multirow{2.2}{*}{Class} & \multirow{2.2}{*}{Order\qquad}& \multicolumn{3}{c}{rom } & \multicolumn{3}{c}{act} & \multicolumn{3}{c}{erus} & \multicolumn{3}{c}{$ \cos $} \\
 & & {Numbers} & {Length (bp)} & {\%} & {Numbers} & {Length (bp)} & \% & {Numbers} & {Length (bp)} & \% & {Numbers} & {Length (bp)} & \% \\
 \midrule\midrule
\multicolumn{2}{@{}l}{\textbf{Class I}} \\
 &SINEs: & 255687 & 30551159 & 1.52 & 257887 & 31080491 & 1.56 & 261248 & 31533761 & 1.57 & 258371 & 30783770 &1.42 \\
 &Alu/B1 & 0 & 0 & 0.00 & 0 & 0 & 0.00 & 0 & 0 & 0.00 & 0 &0 & 0.00 \\
 &MIRs & 247894 & 30250569 & 1.51 & 249065 & 30760408 & 1.54 & 251376 & 31188301 & 1.55 & 248923 &30437726 &1.40 \\
 &LINEs: & 498627 & 207732214 & 10.37 & 501561 & 211005106 & 10.59 &516019 &220321176 &10.97 & 543212 &226312996 &10.42 \\
 &LINE1 & 338909 & 163725095 & 8.17 & 342054 & 166954821 & 8.38 &354388 &175466399 &8.73 &382755 &182566388 &8.40 \\
 &LINE2 & 133681 & 37311794 & 1.86 & 133693 & 37430629 &1.88 &135350 &38013575 &1.89 &134657 &37312366 &1.72 \\
 &L3/CR1 & 16230 &3946140 & 0.20 & 16295 & 3952685 &0.20 &16386 &3999393 &0.20 &16301 &3896521 &0.18 \\
 &RTE & 8327 & 2349410 & 0.12 & 8280 & 2342043 & 0.12 &8320 &2362314 &0.12 &8391 &2315634 &0.11 \\
 \rowcolor{Gainsboro!40! Lavender}[4pt]& \llap{LTR elements:} & 2368202 & 360743057 & 18.00 &2138613 & 331038087 & 16.61 &2043931 &305371407 &15.20 &2399880 &376465663 &17.33 \\
 &ERVL & 603471 & 94653879 & 4.72 & 535533 & 89635873 &4.50 &457960 &74681407 &3.72 &589003 &95266242 &4.39 \\
 &\llap{ERVL-MaLRs} & 936686 & 137736037 & 6.87 & 757066 & 122605363 &6.15 &683557 &105114613 &5.23 &927914 &138867517 &6.39 \\
 &\llap{ERV\_classI} & 401868 & 69495491 &3.47 & 476978 &72572164 &3.64 &458525 &72184510 &3.59 &442380 &80571827 & 3.71\\
 &\llap{ERV\_classII} & 179048 & 21382713 &1.07 & 143640 & 16451857 & 0.83 &146189 &18906035 &0.94 &198036 &22430344 &1.03 \\
 \addlinespace
 \multicolumn{2}{@{}l}{ \textbf{Class II}}\\[0.3ex]
 & \llap{DNA transposons:} & 259000 &53746062 & 2.68 & 261351 & 54598424 & 2.74 &264855 &55556571 &2.77 & 265748 &54859043 &2.53 \\
 & \llap{hAT-Charlie} &153463 & 28637685 & 1.43 & 154577 & 29132748 & 1.46 &156022 & 29603550 &1.47 & 156955 &29239810 &1.35 \\
 & \llap{TcMar-Tigger} &36981 & 11185164 & 0.56 & 38120 & 11441081 &0.57 &39444 &11766559 & 0.59 & 38989 &11514055 &0.53 \\
 &\llap{Rolling-circles} & 659955 & 72981412 &3.64 & 803681 & 84486255 & 4.24 &889437 &94191508 & 4.69 & 738026 &79989304 &3.68 \\
 & Unclassified. & 3128 & 509710 & 0.03 & 3147 & 512316 & 0.03 &3191 &518292 & 0.03 & 3167 &510872 &0.02 \\
\midrule
 & \textbf{Total} &0 & 00000 & 000.25 & 0 &712929637 & 35.78 & X & 00000 & 300
\end{tabular}
\end{table}
\end{landscape}

\end{document} 

enter image description here

3
  • Dear thank you so much,
    – M.Bioinfo
    Mar 14, 2020 at 16:42
  • what about if I want to add the grey highlight similar to LTR element to other class?
    – M.Bioinfo
    Mar 14, 2020 at 16:42
  • Yes, why not? I cloured this row specifically because in your code, it was framed, and I think it looks nicer with coloured background. You also can alternate colured background and no background: see the \rowcolors command defined in package xcolor.
    – Bernard
    Mar 14, 2020 at 17:03
3

Some changes: first of all, siunitx for the numbers. Next I removed the first column, that takes space for nothing.

Then I reduced the font size and let TeX do the computations for the intercolumn spaces.

\documentclass{article}
\usepackage{rotating}
\usepackage{siunitx,booktabs}

\begin{document}

\begin{sidewaystable}
\centering

\caption{Summary of transposable elements }
\label{tab:Table1}

\footnotesize

\setlength{\tabcolsep}{0pt}
\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  S[table-format=7.0]
  S[table-format=9.0]
  S[table-format=2.2]
  S[table-format=7.0]
  S[table-format=9.0]
  S[table-format=2.2]
  S[table-format=7.0]
  S[table-format=9.0]
  S[table-format=2.2]
  S[table-format=7.0]
  S[table-format=9.0]
  S[table-format=2.2]
}
\toprule

Order &
  \multicolumn{3}{c}{rom} &
  \multicolumn{3}{c}{act} &
  \multicolumn{3}{c}{erus} &
  \multicolumn{3}{c}{cos} \\
\cmidrule{2-4} \cmidrule{5-7} \cmidrule{8-10} \cmidrule{11-13}
& {N} & {L (bp)} & {\%}  & {N} & {L (bp)} & {\%} & {N} & {L (bp)} & {\%} & {N} & {L (bp)} & {\%} \\
\midrule

\multicolumn{10}{@{}l}{\itshape Class I} \\
SINEs:               & 255687    & 30551159 & 1.52            & 257887  & 31080491  & 1.56             & 261248   &  31533761  & 1.57                    & 258371           & 30783770    &1.42 \\
Alu/B1               & 0 & 0     & 0.00                       & 0  & 0   & 0.00                        & 0       & 0      & 0.00                                       & 0       &0    & 0.00  \\
MIRs                 & 247894 & 30250569     & 1.51           & 249065  & 30760408   & 1.54            & 251376   & 31188301      & 1.55                 & 248923       &30437726    &1.40  \\
LINEs:               & 498627 & 207732214   & 10.37           & 501561  & 211005106  & 10.59           &516019  &220321176   &10.97                      & 543212      &226312996    &10.42  \\
LINE1               & 338909 & 163725095   & 8.17             & 342054  & 166954821   & 8.38           &354388  &175466399   &8.73                       &382755      &182566388     &8.40  \\
LINE2               & 133681  & 37311794    & 1.86            & 133693  & 37430629   &1.88             &135350   &38013575    &1.89                      &134657      &37312366      &1.72 \\
L3/CR1              & 16230   &3946140     & 0.20             & 16295   & 3952685  &0.20               &16386    &3999393     &0.20                      &16301         &3896521     &0.18 \\
RTE                 & 8327   & 2349410      & 0.12            & 8280   & 2342043   & 0.12              &8320    &2362314     &0.12                       &8391        &2315634     &0.11 \\
\midrule
LTR elements:        & 2368202 & 360743057   & 18.00         &2138613 & 331038087   & 16.61           &2043931   &305371407   &15.20                     &2399880      &376465663   &17.33 \\
\midrule
ERVL                 & 603471 & 94653879   & 4.72            & 535533 & 89635873  &4.50               &457960   &74681407   &3.72                        &589003      &95266242     &4.39 \\
ERVL-MaLRs            & 936686 & 137736037  & 6.87           & 757066 & 122605363  &6.15              &683557   &105114613   &5.23                       &927914      &138867517    &6.39 \\
ERV\_classI            & 401868 & 69495491  &3.47            & 476978 &72572164  &3.64                &458525   &72184510   &3.59                        &442380      &80571827     & 3.71\\
ERV\_classII           & 179048 & 21382713  &1.07            & 143640 & 16451857  & 0.83              &146189     &18906035   &0.94                      &198036        &22430344   &1.03 \\
\midrule[\heavyrulewidth]

\multicolumn{10}{@{}l}{\itshape Class II} \\
DNA transposons:    & 259000 &53746062  & 2.68             & 261351 & 54598424  & 2.74                     &264855  &55556571  &2.77                   & 265748      &54859043     &2.53 \\
\midrule
hAT-Charlie    &153463 & 28637685  & 1.43                 & 154577 & 29132748 & 1.46                      &156022  & 29603550  &1.47                   & 156955       &29239810    &1.35  \\
TcMar-Tigger    &36981 & 11185164  & 0.56                  & 38120 & 11441081 &0.57                      &39444   &11766559  &   0.59                  & 38989       &11514055   &0.53 \\
\midrule
Rolling-circles    & 659955 & 72981412  &3.64               & 803681 & 84486255 & 4.24                      &889437   &94191508  & 4.69                 & 738026       &79989304   &3.68 \\
\midrule
Unclassified.      & 3128 & 509710  & 0.03                 & 3147 & 512316 & 0.03                          &3191   &518292  & 0.03                     & 3167       &510872   &0.02  \\

\midrule[\heavyrulewidth]
\multicolumn{10}{@{}l}{\itshape Total} \\
& 0 & 0  & 0.00
& 0 & 0  & 0.00
& 0 & 0  & 0.00
\end{tabular*}

\end{sidewaystable}

\end{document}

enter image description here

8
  • thank you so much dear, ppl up there in the comments they been testing my knowledge in latex, I though they are speaking Chinese
    – M.Bioinfo
    Mar 13, 2020 at 23:09
  • 1
    @BioInfo - Way to go! Bravo! Insult everyone, including all Chinese speakers. Keep it up, you'll go far.
    – Mico
    Mar 13, 2020 at 23:15
  • Dear what if I want to add Whitespace before the subclass Example SINEs: Alu/B1 MIRs LINEs: LINE1 And at the end the total numbers are nor align the numbers are down how can I make them all in one line, the total and number for Example: Total 342 343 23.23% 234 3423 23.23% 234 3423 23.23%
    – M.Bioinfo
    Mar 15, 2020 at 15:24
  • @BioInfo Sorry, but I don't really understand. If you want some vertical space above “SINEs”, use \\[6pt] or similar to end the previous line. About the total, I can't understand what's the problem.
    – egreg
    Mar 15, 2020 at 15:43
  • Dear you have removed the figure i paste it only to explain my words
    – M.Bioinfo
    Mar 16, 2020 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .