在文本块内拟合包含 9x9 相关矩阵的表格

在文本块内拟合包含 9x9 相关矩阵的表格

我想将图片中的表格放置在正中央。现在,它向右突出,看起来很丑。这是我的代码:

\scalebox{0.75}{
\begin{center}
 \centering
 \begin{tabular}{||c c c c c c c c c c||} 
 \hline
  & SHSZ300 & RGUSHS & SPTRHLTH & MVGDXJTR & SX6R & GDLECFEF & NDELCHF & 
SXXR & SPTRINFT \\ [0.5ex] 
 \hline\hline
SHSZ300&1.0000&0.1256&0.1231&0.1806&0.1800&0.4097&0.5796&0.2387&0.2593\\ 
 \hline
RGUSHS&0.1256&1.0000&0.7845&0.1667&0.3758&0.5186&0.3488&0.5881&0.5926\\
 \hline
SPTRHLTH&0.1231&0.7845&1.0000&0.1229&0.5322&0.6021&0.4604&0.6867&0.6586\\
 \hline
MVGDXJTR&0.1806&0.1667&0.1229&1.0000&0.0734&0.1163&0.3502&0.1841&0.1900\\
 \hline
SX6R&0.1800&0.3758&0.5322&0.0734&1.0000&0.5312&0.3054&0.7212&0.5611\\
 \hline
GDLECFEF&0.4097&0.5186&0.6021&0.1163&0.5312&1.0000&0.7493&0.7267&0.6943\\
 \hline
NDELCHF&0.5796&0.3488&0.4604&0.3502&0.3054&0.7493&1.0000&0.5453&0.5386\\
 \hline
SXXR&0.2387&0.5881&0.6867&0.1841&0.7212&0.7267&0.5453&1.0000&0.7182\\
 \hline
SPTRINFT&0.2593&0.5926&0.6586&0.1900&0.5611&0.6943&0.5386&0.7182&1.0000\\
\end{tabular}
\end{center}}

在此处输入图片描述

我如何修改代码以使表格完全居中?

答案1

我将按照以下方式重新设计您的表格:

  • 利用行标题和列标题相同的事实
  • 用于tabular*表格环境
  • 设置tabsep为占用列之间的可用空间
  • 不要使用垂直线
  • 不使用\scalebox
  • 对于水平线使用booktabs

在此处输入图片描述

(红线表示文字边框)

\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
    \begin{table}%[htb]
    \setlength\tabcolsep{0pt}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
                                l
                           *{9}{c}
                            }
    \toprule
                & (1)   & (2)   & (3) & (4) & (5) & (6) & (7) & (8) & (9) \\
    \midrule
(1): SHSZ300    &1.0000 &0.1256 &0.1231&0.1806&0.1800&0.4097&0.5796&0.2387&0.2593\\
(2): RGUSHS     &0.1256 &1.0000 &0.7845&0.1667&0.3758&0.5186&0.3488&0.5881&0.5926\\
(3): SPTRHLTH   &0.1231 &0.7845 &1.0000&0.1229&0.5322&0.6021&0.4604&0.6867&0.6586\\
    \addlinespace
(4): MVGDXJTR   &0.1806 &0.1667 &0.1229&1.0000&0.0734&0.1163&0.3502&0.1841&0.1900\\
(5): SX6R       &0.1800 &0.3758 &0.5322&0.0734&1.0000&0.5312&0.3054&0.7212&0.5611\\
(6): GDLECFEF   &0.4097 &0.5186 &0.6021&0.1163&0.5312&1.0000&0.7493&0.7267&0.6943\\
    \addlinespace
(7): NDELCHF    &0.5796 &0.3488 &0.4604&0.3502&0.3054&0.7493&1.0000&0.5453&0.5386\\
(8): SXXR       &0.2387 &0.5881 &0.6867&0.1841&0.7212&0.7267&0.5453&1.0000&0.7182\\
(9): SPTRINFT   &0.2593 &0.5926 &0.6586&0.1900&0.5611&0.6943&0.5386&0.7182&1.0000\\
    \bottomrule
\end{tabular*}
    \end{table}
\end{document}

笔记:由于不知道文档的页面布局,我假设页面带有A4边框,这是由geometry包默认确定的。如果文本宽度较小,则可能需要将字体大小减小到\smallfootnotesize

答案2

以下是@Zarko 的回答(并且这个答案) 进一步减少了视觉混乱:它使用该siunitx包仅显示所有相关性的 3 个有效数字。我认为通过应用这种简化,您将为读者带来很大的帮助。

在此处输入图片描述

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

\begin{document}
\begin{table}[htb]
\sisetup{round-mode      = places,
         round-precision = 3,
         table-format    = 1.3}
\setlength\tabcolsep{0pt}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l *{9}{S} }
\toprule
& {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} & {(7)} & {(8)} & {(9)} \\
\midrule
(1) SHSZ300 & 1.0000 & 0.1256 & 0.1231& 0.1806& 0.1800& 0.4097& 0.5796& 0.2387& 0.2593\\
(2) RGUSHS  & 0.1256 & 1.0000 & 0.7845& 0.1667& 0.3758& 0.5186& 0.3488& 0.5881& 0.5926\\
(3) SPTRHLTH& 0.1231 & 0.7845 & 1.0000& 0.1229& 0.5322& 0.6021& 0.4604& 0.6867& 0.6586\\
\addlinespace
(4) MVGDXJTR& 0.1806 & 0.1667 & 0.1229& 1.0000& 0.0734& 0.1163& 0.3502& 0.1841& 0.1900\\
(5) SX6R    & 0.1800 & 0.3758 & 0.5322& 0.0734& 1.0000& 0.5312& 0.3054& 0.7212& 0.5611\\
(6) GDLECFEF& 0.4097 & 0.5186 & 0.6021& 0.1163& 0.5312& 1.0000& 0.7493& 0.7267& 0.6943\\
\addlinespace
(7) NDELCHF & 0.5796 & 0.3488 & 0.4604& 0.3502& 0.3054& 0.7493& 1.0000& 0.5453& 0.5386\\
(8) SXXR    & 0.2387 & 0.5881 & 0.6867& 0.1841& 0.7212& 0.7267& 0.5453& 1.0000& 0.7182\\
(9) SPTRINFT& 0.2593 & 0.5926 & 0.6586& 0.1900& 0.5611& 0.6943& 0.5386& 0.7182& 1.0000\\
\bottomrule
\end{tabular*}
\end{table}
\end{document}

答案3

使用\small字体大小、减小值并在必要时使用或命令\tabcolsep使用多行列标题是使表格适合页面宽度的常用工具。此外,我还加载了垂直和水平规则的更整齐的交叉点:\makecell\theadhhline

    \documentclass{article}
\usepackage[showframe]{geometry}
    \usepackage[utf8]{inputenc}%
    \usepackage{makecell, hhline}

    \begin{document}

\begin{table}[!htb]
 \centering\small
 \setlength{\extrarowheight}{2pt}
 \setlength{\tabcolsep}{3pt}
 \begin{tabular}{||*{10}{c}||}
 \hline
  & SHSZ300 & RGUSHS & \makecell{SPTRH\\LTH} & \makecell{MVGDXJ\\TR} & SX6R & \makecell{GDLECF\\EF} & \makecell{NDELC\\HF} &
SXXR & \makecell{SPTRIN\\FT} \\ [0.5ex]
 \hhline{}
SHSZ300&1.0000&0.1256&0.1231&0.1806&0.1800&0.4097&0.5796&0.2387&0.2593\\
 \hhline{||*{10}{=}||}
RGUSHS&0.1256&1.0000&0.7845&0.1667&0.3758&0.5186&0.3488&0.5881&0.5926\\
 \hhline{||*{10}{=}||}
SPTRHLTH&0.1231&0.7845&1.0000&0.1229&0.5322&0.6021&0.4604&0.6867&0.6586\\
 \hhline{||*{10}{=}||}
MVGDXJTR&0.1806&0.1667&0.1229&1.0000&0.0734&0.1163&0.3502&0.1841&0.1900\\
 \hhline{||*{10}{=}||}
SX6R&0.1800&0.3758&0.5322&0.0734&1.0000&0.5312&0.3054&0.7212&0.5611\\
 \hhline{||*{10}{=}||}
GDLECFEF&0.4097&0.5186&0.6021&0.1163&0.5312&1.0000&0.7493&0.7267&0.6943\\
 \hhline{||*{10}{=}||}
NDELCHF&0.5796&0.3488&0.4604&0.3502&0.3054&0.7493&1.0000&0.5453&0.5386\\
 \hhline{||*{10}{=}||}
SXXR&0.2387&0.5881&0.6867&0.1841&0.7212&0.7267&0.5453&1.0000&0.7182\\
 \hhline{||*{10}{=}||}
SPTRINFT&0.2593&0.5926&0.6586&0.1900&0.5611&0.6943&0.5386&0.7182&1.0000\\
\end{tabular}
\end{table}

    \end{document} 

在此处输入图片描述

相关内容