4

The following LaTeX code generates a table, but it's not centralized with the paper:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[portuguese]{babel}
\usepackage{geometry}
\usepackage{makecell}
\begin{document}
\section{Results}
\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\thead{Identificador\\ de contig}
    &   \thead{Tamanho do\\ contig (bp)}
        &   \thead{Melhor hit\\ (organismo)}
            &    \thead{e-value}
                &   \thead{Identidade\\ (\%)}
                    &   \thead{Tamanho do\\ alinhamento (bp)\\ (\% do tamanho do contig)}
                        &   \thead{Algoritmo\\ usado}\\
    \hline
ctg1    
    &  13425
        &   \thead{\textit{Friedmanniella}\\\textit{sagamiharensis} \\ strain DSM 21743} 
            & 4e-10 
                & 69 
                    & 269 (2)
                        & BLASTn \\ 
    \hline
ctg2   
    &  11567
        &   \thead{\textit{Kineococcus} \\\textit{radiotolerans} \\ SRS30216}  
            & 0.0 
                & 71 
                    & 3933 (34)
                        & BLASTn \\ 
    \hline
ctg3    
    &  12900
        &   \thead{\textit{Pseudomonas} \\ \textit{fluorescens } \\ strain NEP1 genome} 
            & 0.0 
                & 69 
                    & 2193 (17)
                        & BLASTn \\ 
    \hline
ctg4    
    &  17737
        &   \thead{\textit{Herminiimonas } \\ \textit{arsenicoxydans}}   
            & 0.0 
                & 69 
                    & 4257 (24)
                        & BLASTn \\ 
    \hline
ctg5    
    & 13319
        &   \thead{\textit{Nonomuraea sp. } \\ ATCC 55076\\} 
            & 0.0
                & 66
                    & 7192 (54)
                        & BLASTn \\ 
    \hline
ctg6    
    & 10398
        &   \thead{\textit{Marichromatium } \\ \textit{purpuratum } \\ 984}   
            & 0.0 
                & 72 
                    & 5719 (55)
                        & BLASTn \\ 
    \hline
ctg7    
    &  16623
        &   \thead{\textit{Bacillus cereus} \\ AH820}  
            & 4e-36 
                & 67
                    & 1330 (8)
                        & BLASTn \\ 
    \hline
ctg8    
    &  20951
        &   \thead{\textit{Limnohabitans sp.} \\ 63ED37-2}   
            & 0.0 
                & 80 
                    & 15923 (76)
                        & BLASTn \\ 
    \hline
ctg9    
    &  13925
        &   \thead{\textit{Pontibacter } \\ \textit{actiniarum} \\ DSM 19842}   
            &  4e-143
                & 74 
                    & 1114 (8)
                        & BLASTn \\ 
    \hline
ctg10    
    & 10484
        &   \thead{\textit{Candidatus} \\ \textit{Nanopelagicus} \\ \textit{limnes}}   
            & 0.0
                & 80
                    & 9331 (89)
                        & BLASTn \\ 
    \hline
\end{tabular}
\end{center}
\end{table}
\end{document}

I've tried using begin{center} and \centering... but it doesn't work. How can I solve this problem?

  • 1
    Your tabular is too wide. If you want it centered anyway, use \makebox[\textwidth]{...} – John Kormylo Sep 30 '18 at 15:35
  • Note that you can format non-inline code by clicking the "{}" button or pressing ctrl-K (while the code is selected). More information on formatting can be found here here. – Circumscribe Sep 30 '18 at 20:13
5

Here is a solution and some improvements, playing with the value of \tabcolsep and adding lines in a column head:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[portuguese]{babel}
\usepackage[showframe]{geometry}
\usepackage{makecell}

\begin{document}

\section{Results}
\begin{table}[h]
\centering\setlength{\tabcolsep}{3pt}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\thead{Identificador\\ de contig}
    & \thead{Tamanho do \\ contig (bp)}
        & \thead{Melhor hit\\ (organismo)}
            & \thead{e-value}
                & \thead{Identidade\\ (\%)}
                    & \thead{Tamanho do\\ alinhamento (bp)\\ (\% do tamanho\\ do contig)}
                        & \thead{Algoritmo\\ usado}\\
    \hline
ctg1
    & 13425
        & \thead{\textit{Friedmanniella}\\\textit{sagamiharensis} \\ strain DSM 21743}
            & $ 4\,\mathrm{e}{-10} $
                & 69
                    & 269 (2)
                        & BLASTn \\
    \hline
ctg2
    & 11567
        & \thead{\textit{Kineococcus} \\\textit{radiotolerans} \\ SRS30216}
            & 0.0
                & 71
                    & 3933 (34)
                        & BLASTn \\
    \hline
ctg3
    & 12900
        & \thead{\textit{Pseudomonas} \\ \textit{fluorescens } \\ strain NEP1 genome}
            & 0.0
                & 69
                    & 2193 (17)
                        & BLASTn \\
    \hline
ctg4
    & 17737
        & \thead{\textit{Herminiimonas } \\ \textit{arsenicoxydans}}
            & 0.0
                & 69
                    & 4257 (24)
                        & BLASTn \\
    \hline
ctg5
    & 13319
        & \thead{\textit{Nonomuraea sp. } \\ ATCC 55076\\}
            & 0.0
                & 66
                    & 7192 (54)
                        & BLASTn \\
    \hline
ctg6
    & 10398
        & \thead{\textit{Marichromatium } \\ \textit{purpuratum } \\ 984}
            & 0.0
                & 72
                    & 5719 (55)
                        & BLASTn \\
    \hline
ctg7
    & 16623
        & \thead{\textit{Bacillus cereus} \\ AH820}
            & $ 4\,\mathrm{e}{-36} $
                & 67
                    & 1330 (8)
                        & BLASTn \\
    \hline
ctg8
    & 20951
        & \thead{\textit{Limnohabitans sp.} \\ 63ED37-2}
            & 0.0
                & 80
                    & 15923 (76)
                        & BLASTn \\
    \hline
ctg9
    & 13925
        & \thead{\textit{Pontibacter } \\ \textit{actiniarum} \\ DSM 19842}
            & $ 4\,\mathrm{e}{-143} $
                & 74
                    & 1114 (8)
                        & BLASTn \\
    \hline
ctg10
    & 10484
        & \thead{\textit{Candidatus} \\ \textit{Nanopelagicus} \\ \textit{limnes}}

            & 0.0
                & 80
                    & 9331 (89)
                        & BLASTn \\
    \hline
\end{tabular}
\end{table}

\end{document} 

enter image description here

5

Here's a solution that (a) switches over to a tabularx environment and (b) uses centered versions of the p and X column types to allow for line breaks automatically. The solution also gets rid of all vertical lines and of most horizontal lines to give the table a more "open" look.

enter image description here

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[portuguese]{babel}
\usepackage{geometry}
\usepackage{tabularx,booktabs,ragged2e}
\newcolumntype{Y}{%
   >{\Centering\arraybackslash\hspace{0pt}}X}
\newcolumntype{C}[1]{%
   >{\Centering\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{L}[1]{%
   >{\RaggedRight\arraybackslash\hspace{0pt}}p{#1}}

\newlength\lena  \settowidth\lena{Identific}
\newlength\lenb  \settowidth\lenb{Tamanho}
\newlength\lenc  \settowidth\lenc{Identid}
\newlength\lend  \settowidth\lend{Tamanho do}
\newlength\lene  \settowidth\lene{Algoritmo}

\hyphenation{nano-pe-la-gi-cus}
\begin{document}
\section{Results}

\begin{table}[h!]
\setlength\tabcolsep{4pt}
\begin{tabularx}{\textwidth}{@{}
   L{\lena} C{\lenb} Y c C{\lenc} C{\lend} C{\lene} @{}}
\toprule
Identificador de contig &   
Tamanho do contig (bp) &   
Melhor hit \newline (organismo) & 
e-value &   
Identidade (\%) &   
Tamanho do alinhamento (bp) (\% do tamanho do contig) &   
Algoritmo usado\\
\midrule
ctg1 &  13425 & \textit{Friedmanniella} \textit{sagamiharensis} strain DSM 21743 & 4e-10  & 69  & 269 (2) & BLASTn \\ 
\addlinespace
ctg2 &  11567 & \textit{Kineococcus radiotolerans} SRS30216 & 0.0 & 71 & 3933 (34) & BLASTn \\ 
\addlinespace
ctg3 & 12900 & \textit{Pseudomonas fluorescens} strain NEP1 genome & 0.0 & 69  & 2193 (17) & BLASTn \\ 
\addlinespace
ctg4 & 17737 & \textit{Herminiimonas arsenicoxydans} & 0.0 & 69 & 4257 (24) & BLASTn \\ 
\addlinespace
ctg5 & 13319 & \textit{Nonomuraea sp.} ATCC 55076  & 0.0 & 66 & 7192 (54) & BLASTn \\ 
\addlinespace
ctg6 & 10398 & \textit{Marichromatium purpuratum} 984 & 0.0 & 72 & 5719 (55) & BLASTn \\ 
\addlinespace
ctg7 & 16623 & \textit{Bacillus cereus} AH820 & 4e-36 & 67 & 1330 (8) & BLASTn \\ 
\addlinespace
ctg8 & 20951 & \textit{Limnohabitans sp.} 63ED37-2 & 0.0 & 80 & 15923 (76) & BLASTn \\ 
\addlinespace
ctg9 & 13925 & \textit{Pontibacter actiniarum} DSM 19842 &  4e-143 & 74 & 1114 (8) & BLASTn \\ 
\addlinespace
ctg10 & 10484 & \textit{Candidatus Nanopelagicus limnes} & 0.0 & 80 & 9331 (89) & BLASTn \\ 
\bottomrule
\end{tabularx}
\end{table}
\end{document}

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.