无法对齐/居中表格

无法对齐/居中表格

以下 LaTeX 代码生成一个表格,但它并不以论文为中心:

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

我尝试使用begin{center}\centering...但不起作用。我该如何解决这个问题?

答案1

这是一个解决方案和一些改进,使用的值\tabcolsep并在列标题中添加行:

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

在此处输入图片描述

答案2

这是一个解决方案,它 (a) 切换到环境tabularx,并且 (b) 使用居中版本的pX列类型来自动换行。该解决方案还删除了所有垂直线和大多数水平线,使表格看起来更“开放”。

在此处输入图片描述

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

相关内容