无法适当调整桌子

无法适当调整桌子

以下 LaTeX 代码生成一个表格,但它超出了页面的限制:

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{table}[H]
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
Identificador de contig & Tamanho do contig (bp) & Melhor hit (organismo) & e-value & Identidade (\%) & Tamanho do alinhamento (bp) (\% do tamanho do contig) & Algoritmo usado \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
\end{tabular}
\end{table}

\end{document}

我尝试调整表格大小以使其适合页面,但表格太小了:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{adjustbox}

\begin{document}

\begin{table}[H]
\begin{adjustbox}{width=1\textwidth,center=\textwidth}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
Identificador de contig & Tamanho do contig (bp) & Melhor hit (organismo) & e-value & Identidade (\%) & Tamanho do alinhamento (bp) (\% do tamanho do contig) & Algoritmo usado \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
\end{tabular}
\end{adjustbox}
\end{table}

\end{document}

有没有简单的方法可以让我的桌子合适地摆放?

答案1

您的问题是列标题太长。它们真的需要这么长吗?一个解决方案是将标题文本分成更多行。例如如下:

在此处输入图片描述

(红线表示文字边框)

makecell为此,使用了同名包中的宏:

\documentclass{article}
\usepackage{geometry}
\usepackage{makecell}

\begin{document}
\begin{table}%[htb]
\centering
\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
    &  &  &  &  &  &  \\ \hline
    &  &  &  &  &  &  \\ \hline
    &  &  &  &  &  &  \\ \hline
    &  &  &  &  &  &  \\ \hline
    &  &  &  &  &  &  \\ \hline
    &  &  &  &  &  &  \\ \hline
    &  &  &  &  &  &  \\ \hline
    &  &  &  &  &  &  \\ \hline
    &  &  &  &  &  &  \\ \hline
    &  &  &  &  &  &  \\ \hline
\end{tabular}
\end{table}
\end{document}

答案2

我建议您将 改为tabulartabularx并使用居中版本的列类型X。这样,标题单元格中就会自动换行。

在此处输入图片描述

\documentclass{article}
\usepackage[portuguese]{babel} % is 'portuguese' correct
\usepackage{tabularx,ragged2e}
\newcolumntype{C}{>{\Centering\arraybackslash\hspace{0pt}}X}

\begin{document}

\begin{table}[ht!]
\setlength\tabcolsep{2pt} % default: 6pt
\begin{tabularx}{\textwidth}{|*{7}{C|}}
\hline
Identificador de contig & Tamanho do contig (bp) & Melhor hit (organismo) & 
e-value & Identidade (\%) & Tamanho do alinhamento (bp) (\% do tamanho do contig) & 
Algoritmo usado \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
 &  &  &  &  &  &  \\ \hline
\end{tabularx}
\end{table}
\end{document}

相关内容