我有以下代码来呈现表格:
\chapter{Resultados}
\begin{table*}[h]
\centering
\caption{Resultados Para o Conjunto de
Dados Image}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
Índice & Algoritmo Generativo & \multicolumn{5}{|c|}{Função Consenso} \\ \hline
- & K-Means & Agglomerative & CSPA & IVC & LWEA & LGWP \\ \hline
ARI & \makecell{ari-km-5 \\ ari-km-10 \\ ari-km-15 \\ ari-km-20 \\ ari-km-30} & \makecell{ari-agm-km-5 \\ ari-agm-km-10 \\ ari-agm-km-15 \\ ari-agm-km-20 \\ ari-agm-km-30} & \makecell{ari-csp-km-5 \\ ari-csp-km-10 \\ ari-csp-km-15 \\ ari-csp-km-20 \\ ari-csp-km-30} & \makecell{ari-ivc-km-5 \\ ari-ivc-km-10 \\ ari-ivc-km-15 \\ ari-ivc-km-20 \\ ari-ivc-km-30} & \makecell{ ari-lwe-km-5 \\ ari-lwe-km-10 \\ ari-lwe-km-15 \\ ari-lwe-km-20 \\ ari-lwe-km-30} & \makecell{ari-lwg-km-5 \\ ari-lwg-km-10 \\ ari-lwg-km-15 \\ ari-lwg-km-20 \\ ari-lwg-km-30} \\ \hline
\end{tabular}
\end{table*}
但是,表格不仅没有居中,而且渲染得太靠右,内容被截断了:
我该如何解决这个问题?我还收到了警告Overfull \hbox (114pt too wide) in paragraph at lines 7-13
答案1
您没有提供关键信息:的长度\textwidth
。由于不知道,我们只能猜测。例如,如果页面边框宽度为 25 毫米,那么通过\makecell
在第二列的标题中使用,我们可以将您的表格放在页面上,就像您希望的那样:
\documentclass{book}
\usepackage[margin=25mm]{geometry}
\usepackage{makecell, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\chapter{Resultados}
\begin{table}[ht]
\centering
\caption{Resultados Para o Conjunto de Dados Image}
%\small
\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{|c|c|*{5}{C|}}
\hline
Índice & \makecell{Algoritmo\\ Generativo}
& \multicolumn{5}{c|}{Função Consenso} \\ \hline
-- & K-Means & Agglomerative & CSPA & IVC & LWEA & LGWP \\ \hline
ARI & \makecell{ari-km-5 \\ ari-km-10 \\ ari-km-15 \\ ari-km-20 \\ ari-km-30}
& \makecell{ari-agm-km-5 \\ ari-agm-km-10 \\ ari-agm-km-15 \\ ari-agm-km-20 \\ ari-agm-km-30}
& \makecell{ari-csp-km-5 \\ ari-csp-km-10 \\ ari-csp-km-15 \\ ari-csp-km-20 \\ ari-csp-km-30}
& \makecell{ari-ivc-km-5 \\ ari-ivc-km-10 \\ ari-ivc-km-15 \\ ari-ivc-km-20 \\ ari-ivc-km-30}
& \makecell{ ari-lwe-km-5 \\ ari-lwe-km-10 \\ ari-lwe-km-15 \\ ari-lwe-km-20 \\ ari-lwe-km-30}
& \makecell{ari-lwg-km-5 \\ ari-lwg-km-10 \\ ari-lwg-km-15 \\ ari-lwg-km-20 \\ ari-lwg-km-30} \\
\hline
\end{tabularx}
\end{table}
\end{document}
(红线表示文本边框)
答案2
问题并不令人惊讶,就是表格太宽(这就是收到警告的原因Overfull \hbox
)。
选项是找到一种方法来使表格变窄(除了可能使文本变小之外,似乎没有太大的希望)或使用垂直而不是水平排版表格横向稳定