我搜索了很多关于将单元格居中的解决方案。但是没有一个适用于我的代码。你能帮助像我这样的新手吗?
\begin{table}[htbp]
\label{concent55}
\centering
\caption{Sorting}
\begin{tabular}{rrrrrrr}
\toprule
& & \multicolumn{5}{c}{insti after 1990} \\
\midrule
& & 1 & 2 & 3 & 4 & 5 \\
\multicolumn{1}{c}{\multirow{5}[0]{*}{concent}} & 1 & 0.06552 & 0.048739 & 0.029772 & 0.031109 & 0.027277 \\
\multicolumn{1}{c}{} & 2 & 0.011051 & 0.058263 & 0.037196 & 0.040717 & 0.040017 \\
\multicolumn{1}{c}{} & 3 & 0.106115 & 0.048928 & 0.067627 & 0.046418 & 0.046278 \\
\multicolumn{1}{c}{} & 4 & 0.214212 & 0.032606 & 0.064722 & 0.040077 & 0.04908 \\
\multicolumn{1}{c}{} & 5 & 0.068077 & 0.070491 & 0.058308 & 0.062065 & 0.051358 \\
\bottomrule
\end{tabular}%
\end{table}%
答案1
带有软件包的版本siunitx
。数据数字在小数点处对齐。浮动数据数字上方的数字 1, ..., 5 可以通过将其放入括号中来居中,然后软件包siunitx
会将此条目设置为居中,无论内容如何,尤其是条目未解析和对齐为数字:
\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{multirow}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\caption{Sorting}
\label{concent55}
\begin{tabular}{cr*{5}{S[table-format=1.6]}}
\toprule
& & \multicolumn{5}{c}{insti after 1990} \\
\midrule
& & {1} & {2} & {3} & {4} & {5} \\
\multirow{5}{*}{concent}
& 1 & 0.06552 & 0.048739 & 0.029772 & 0.031109 & 0.027277 \\
& 2 & 0.011051 & 0.058263 & 0.037196 & 0.040717 & 0.040017 \\
& 3 & 0.106115 & 0.048928 & 0.067627 & 0.046418 & 0.046278 \\
& 4 & 0.214212 & 0.032606 & 0.064722 & 0.040077 & 0.04908 \\
& 5 & 0.068077 & 0.070491 & 0.058308 & 0.062065 & 0.051358 \\
\bottomrule
\end{tabular}%
\end{table}
\end{document}
在这种情况下,\multirow
根本不需要。以下示例将放在concent
中间数据行中。此外,\midrule
被截断以仅覆盖数据列,如回答米科的。
\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\caption{Sorting}
\label{concent55}
\begin{tabular}{cr*{5}{S[table-format=1.6]}}
\toprule
& & \multicolumn{5}{c}{insti after 1990} \\
\cmidrule{3-7}
& & {1} & {2} & {3} & {4} & {5} \\
& 1 & 0.06552 & 0.048739 & 0.029772 & 0.031109 & 0.027277 \\
& 2 & 0.011051 & 0.058263 & 0.037196 & 0.040717 & 0.040017 \\
concent
& 3 & 0.106115 & 0.048928 & 0.067627 & 0.046418 & 0.046278 \\
& 4 & 0.214212 & 0.032606 & 0.064722 & 0.040077 & 0.04908 \\
& 5 & 0.068077 & 0.070491 & 0.058308 & 0.062065 & 0.051358 \\
\bottomrule
\end{tabular}%
\end{table}
\end{document}
现在对一条垂直线进行旋转的实验concent
如下:
\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\caption{Sorting}
\label{concent55}
\begin{tabular}{c|r*{5}{S[table-format=1.6]}}
\toprule
\multicolumn{1}{c}{}
& & \multicolumn{5}{c}{insti after 1990} \\
\cmidrule{3-7}
\multicolumn{1}{c}{}
& & {1} & {2} & {3} & {4} & {5} \\
& 1 & 0.06552 & 0.048739 & 0.029772 & 0.031109 & 0.027277 \\
& 2 & 0.011051 & 0.058263 & 0.037196 & 0.040717 & 0.040017 \\
\raisebox{0pt}[0pt][0pt]{\rotatebox[origin=c]{90}{concent}}
& 3 & 0.106115 & 0.048928 & 0.067627 & 0.046418 & 0.046278 \\
& 4 & 0.214212 & 0.032606 & 0.064722 & 0.040077 & 0.04908 \\
& 5 & 0.068077 & 0.070491 & 0.058308 & 0.062065 & 0.051358 \\
\bottomrule
\end{tabular}%
\end{table}
\end{document}
无垂直线:
在以下示例中,“concent”被移动到列标题的位置:
\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\caption{Sorting}
\label{concent55}
\begin{tabular}{
S[table-format=1.0]
*{5}{S[table-format=1.6]}
}
\toprule
{concent} & \multicolumn{5}{c}{insti after 1990} \\
\midrule
& {1} & {2} & {3} & {4} & {5} \\
1 & 0.06552 & 0.048739 & 0.029772 & 0.031109 & 0.027277 \\
2 & 0.011051 & 0.058263 & 0.037196 & 0.040717 & 0.040017 \\
3 & 0.106115 & 0.048928 & 0.067627 & 0.046418 & 0.046278 \\
4 & 0.214212 & 0.032606 & 0.064722 & 0.040077 & 0.04908 \\
5 & 0.068077 & 0.070491 & 0.058308 & 0.062065 & 0.051358 \\
\bottomrule
\end{tabular}%
\end{table}
\end{document}
不同位置\midrule
:
\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\caption{Sorting}
\label{concent55}
\begin{tabular}{
S[table-format=1.0]
*{5}{S[table-format=1.6]}
}
\toprule
& \multicolumn{5}{c}{insti after 1990} \\
\cmidrule{2-6}
{concent} & {1} & {2} & {3} & {4} & {5} \\
\midrule
1 & 0.06552 & 0.048739 & 0.029772 & 0.031109 & 0.027277 \\
2 & 0.011051 & 0.058263 & 0.037196 & 0.040717 & 0.040017 \\
3 & 0.106115 & 0.048928 & 0.067627 & 0.046418 & 0.046278 \\
4 & 0.214212 & 0.032606 & 0.064722 & 0.040077 & 0.04908 \\
5 & 0.068077 & 0.070491 & 0.058308 & 0.062065 & 0.051358 \\
\bottomrule
\end{tabular}%
\end{table}
\end{document}
答案2
这是一个使用dcolumn
包及其d
列类型来对齐小数标记上的数字的解决方案。
请注意,这四个\multicolumn{1}{c}{}
指令不是必需的,\multicolumn{1}{c}{\multirow{5}[0]{*}{concent}}
可以简化为\multirow{5}{*}{concent}
。另外,\label
指令必须后\caption
如果您打算在文档的其他位置交叉引用该表,则请声明。
\documentclass{article}
\usepackage{booktabs,multirow,dcolumn}
\newcolumntype{d}[1]{D..{#1}} % alignment on decimal marker
\newcommand\mc[1]{\multicolumn{1}{@{}c@{}}{#1}} % shortcut macro
\begin{document}
\begin{table}[htbp]
\centering
\caption{Sorting} \label{concent55}
\begin{tabular}{@{} ll *{5}{d{1.6}} @{}}
\toprule
& & \multicolumn{5}{c@{}}{insti after 1990} \\
\cmidrule{3-7}
& & \mc{1} & \mc{2} & \mc{3} & \mc{4} & \mc{5} \\
\multirow{5}{*}{concent}
& 1 & 0.06552 & 0.048739 & 0.029772 & 0.031109 & 0.027277 \\
& 2 & 0.011051 & 0.058263 & 0.037196 & 0.040717 & 0.040017 \\
& 3 & 0.106115 & 0.048928 & 0.067627 & 0.046418 & 0.046278 \\
& 4 & 0.214212 & 0.032606 & 0.064722 & 0.040077 & 0.04908 \\
& 5 & 0.068077 & 0.070491 & 0.058308 & 0.062065 & 0.051358 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}