这是我想要的:
我创建了如下的简单表格:
\documentclass[11pt]{article}
\begin{document}
\begin{tabular}{c|cccccc}
& 0.1 & 0.25 & 0.40 & 0.55 & 0.7 & 0.95 \\ \hline
7 & 0.0052 & \boxed{0.0031} & 0.0070 & 0.0075 & 0.0092 & 0.0048 \\
8 & 0.0061 & 0.0075 & 0.0071 & 0.0065 & 0.0062 & 0.0078 \\
9 & 0.0078 & 0.0087 & 0.0057 & 0.0079 & 0.0094 & 0.0060 \\
10 & 0.0040 & 0.0061 & 0.0084 & 0.0062 & 0.0060 & 0.0053 \\
11 & 0.0075 & 0.0056 & 0.0056 & 0.0056 & 0.0066 & 0.0097 \\
12 & 0.0054 & \boxed{0.0030} & 0.0088 & 0.0085 & 0.0056 & 0.0091 \\
13 & 0.0077 & 0.0073 & 0.0059 & 0.0075 & 0.0049 & 0.0053 \\
14 & 0.0062 & 0.0057 & 0.0099 & 0.0068 & 0.0087 & 0.0067 \\
15 & 0.0061 & 0.0069 & 0.0101 & 0.0065 & 0.0080 & 0.0071 \\
\end{tabular}
\end{document}
有人能帮我理解如何像图片中显示的那样在第一行和第一列上放置标签吗?任何帮助、链接或资源都将不胜感激。
答案1
根据我的经验,读者非常不喜欢不得不伸长脖子才能读到旋转了 90 度的列标题,尤其是当只有一个这样的列标题时。因此,我建议您将字符串“隐藏层中的神经元数量”放在第一列上方,同时在字符串中提供一个换行符。另外,我还建议您放弃表格中的所有垂直线。
\documentclass[11pt]{article}
\usepackage{amsmath} % for \boxed and \smash[b] macros
\usepackage{booktabs}% for \midrule and \cmidrule macros
\newcommand\headercell[1]{%
\smash[b]{\begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}}
\begin{document}
\noindent
\begin{tabular}{@{} *{7}{c} @{}}
\headercell{Number of Neurons\\in Hidden Layer} & \multicolumn{6}{c@{}}{Learning Rate}\\
\cmidrule(l){2-7}
& 0.1 & 0.25 & 0.40 & 0.55 & 0.7 & 0.95 \\
\midrule
7 & 0.0052 & \boxed{0.0031} & 0.0070 & 0.0075 & 0.0092 & 0.0048 \\
8 & 0.0061 & 0.0075 & 0.0071 & 0.0065 & 0.0062 & 0.0078 \\
9 & 0.0078 & 0.0087 & 0.0057 & 0.0079 & 0.0094 & 0.0060 \\
10 & 0.0040 & 0.0061 & 0.0084 & 0.0062 & 0.0060 & 0.0053 \\
11 & 0.0075 & 0.0056 & 0.0056 & 0.0056 & 0.0066 & 0.0097 \\
12 & 0.0054 & \boxed{0.0030} & 0.0088 & 0.0085 & 0.0056 & 0.0091 \\
13 & 0.0077 & 0.0073 & 0.0059 & 0.0075 & 0.0049 & 0.0053 \\
14 & 0.0062 & 0.0057 & 0.0099 & 0.0068 & 0.0087 & 0.0067 \\
15 & 0.0061 & 0.0069 & 0.0101 & 0.0065 & 0.0080 & 0.0071 \\
\end{tabular}
\end{document}
答案2
我使用\multicolumn
包中的multirow
命令将前两列合并在一起,并将第一行的剩余列合并在一起(其中包含“学习率”)。其他文本必须旋转,为此我使用了\rotatebox
包中的命令rotating
,并将其排列在 9 行上(\multirow
)。
\documentclass{article}
\usepackage{rotating}
\usepackage{multirow}
\usepackage{amsmath}
\renewcommand{\arraystretch}{1.5}
\begin{document}
\begin{tabular}{p{5pt}c|cccccc}
\multicolumn{2}{}{} & \multicolumn{6}{c}{Learning Rate} \\
& & 0.1 & 0.25 & 0.40 & 0.55 & 0.7 & 0.95 \\ \cline{2-8}
\multirow{9}{*}{\rotatebox[origin=c]{90}{Number of Neurons in Hidden Layer}}
& 7 & 0.0052 & \boxed{0.0031} & 0.0070 & 0.0075 & 0.0092 & 0.0048 \\
& 8 & 0.0061 & 0.0075 & 0.0071 & 0.0065 & 0.0062 & 0.0078 \\
& 9 & 0.0078 & 0.0087 & 0.0057 & 0.0079 & 0.0094 & 0.0060 \\
& 10 & 0.0040 & 0.0061 & 0.0084 & 0.0062 & 0.0060 & 0.0053 \\
& 11 & 0.0075 & 0.0056 & 0.0056 & 0.0056 & 0.0066 & 0.0097 \\
& 12 & 0.0054 & \boxed{0.0030} & 0.0088 & 0.0085 & 0.0056 & 0.0091 \\
& 13 & 0.0077 & 0.0073 & 0.0059 & 0.0075 & 0.0049 & 0.0053 \\
& 14 & 0.0062 & 0.0057 & 0.0099 & 0.0068 & 0.0087 & 0.0067 \\
& 15 & 0.0061 & 0.0069 & 0.0101 & 0.0065 & 0.0080 & 0.0071 \\
\end{tabular}
\end{document}
答案3
下面是我将最后一行围绕左下角旋转 90 度得到的包含行标签的框;因为我希望将行标签保留为不超出水平线的单行,所以我决定让 TeX 做一些\dimexpr
计算,以使用负值扩展\hbox
,以防在正常情况下行太长;\strut
标签开头和结尾的 s 是为了确保框具有足够的深度,这一点很重要,因为旋转是围绕底角进行的:
\documentclass{article}
\usepackage{graphicx}
\newlength\MyScratchy
\begin{document}
\begingroup
\renewcommand{\arraystretch}{1.365}%
\settowidth\MyScratchy{0.0000}%
\newcommand*\nf[1]{{%
\advance\fboxsep\fboxrule
\fboxrule=0pt
\fbox{\hbox to\MyScratchy{\hfil\ignorespaces#1\unskip\hfil}}%
}}%
\newcommand*\ff[1]{{%
\fbox{\hbox to\MyScratchy{\hfil\ignorespaces#1\unskip\hfil}}%
}}%
\begin{tabular}{lr|*{6}{c}}%
\multicolumn{2}{c}{}&\multicolumn{6}{c}{\textsf{Learning Rate}}\\
&&0.1&0.25&0.40&0.55&0.7&0.95\\
\cline{2-8}%
&7&\nf{0.0052}&\ff{0.0031}&\nf{0.0070}&\nf{0.0075}&\nf{0.0092}&\nf{0.0048}\\
&8&\nf{0.0061}&\nf{0.0075}&\nf{0.0071}&\nf{0.0065}&\nf{0.0062}&\nf{0.0078}\\
&9&\nf{0.0078}&\nf{0.0087}&\nf{0.0057}&\nf{0.0079}&\nf{0.0094}&\nf{0.0060}\\
&10&\nf{0.0040}&\nf{0.0061}&\nf{0.0084}&\nf{0.0062}&\nf{0.0060}&\nf{0.0053}\\
&11&\nf{0.0075}&\nf{0.0056}&\nf{0.0056}&\nf{0.0056}&\nf{0.0066}&\nf{0.0097}\\
&12&\nf{0.0054}&\ff{0.0030}&\nf{0.0088}&\nf{0.0085}&\nf{0.0056}&\nf{0.0091}\\
&13&\nf{0.0077}&\nf{0.0073}&\nf{0.0059}&\nf{0.0075}&\nf{0.0049}&\nf{0.0053}\\
&14&\nf{0.0062}&\nf{0.0057}&\nf{0.0099}&\nf{0.0068}&\nf{0.0087}&\nf{0.0067}\\
\smash{%
\lower\dimexpr\dp\csname @arstrutbox\endcsname-\dp\strutbox+\arrayrulewidth\relax
\hbox{\rotatebox[origin=bl]{90}{%
\textsf{%
%\fboxsep=-\fboxrule
%\fbox{%
\parbox[b]{\dimexpr 9\dp\csname @arstrutbox\endcsname+9\ht\csname @arstrutbox\endcsname\relax}{%
\centering
\begingroup
\settowidth\MyScratchy{\hbox{Number of Neurons in Hidden Layer}}%
\ifdim\MyScratchy>\dimexpr 9\dp\csname @arstrutbox\endcsname+9\ht\csname @arstrutbox\endcsname\relax
\advance\MyScratchy-\dimexpr 9\dp\csname @arstrutbox\endcsname+9\ht\csname @arstrutbox\endcsname\relax
\strut\hbox spread-\MyScratchy{Number of Neurons in Hidden Layer}\strut
\else
\strut\hbox{Number of Neurons in Hidden Layer}\strut
\fi
\endgroup
}%
%}%
}%
}}%
}%
&15&\nf{0.0061}&\nf{0.0069}&\nf{0.0101}&\nf{0.0065}&\nf{0.0080}&\nf{0.0071}\\
\end{tabular}
\endgroup
\end{document}
(顺便说一句:我用于\smash
确保旋转框的高度和深度不会影响发生旋转框的表行的高度。)
如果你想换行,我建议省略扩展计算并让周围环境\parbox
完成其工作,同时可能自己插入一些换行命令:
\documentclass{article}
\usepackage{graphicx}
\newlength\MyScratchy
\begin{document}
\begingroup
\renewcommand{\arraystretch}{1.365}%
\settowidth\MyScratchy{0.0000}%
\newcommand*\nf[1]{{%
\advance\fboxsep\fboxrule
\fboxrule=0pt
\fbox{\hbox to\MyScratchy{\hfil\ignorespaces#1\unskip\hfil}}%
}}%
\newcommand*\ff[1]{{%
\fbox{\hbox to\MyScratchy{\hfil\ignorespaces#1\unskip\hfil}}%
}}%
\begin{tabular}{lr|*{6}{c}}%
\multicolumn{2}{c}{}&\multicolumn{6}{c}{\textsf{Learning Rate}}\\
&&0.1&0.25&0.40&0.55&0.7&0.95\\
\cline{2-8}%
&7&\nf{0.0052}&\ff{0.0031}&\nf{0.0070}&\nf{0.0075}&\nf{0.0092}&\nf{0.0048}\\
&8&\nf{0.0061}&\nf{0.0075}&\nf{0.0071}&\nf{0.0065}&\nf{0.0062}&\nf{0.0078}\\
&9&\nf{0.0078}&\nf{0.0087}&\nf{0.0057}&\nf{0.0079}&\nf{0.0094}&\nf{0.0060}\\
&10&\nf{0.0040}&\nf{0.0061}&\nf{0.0084}&\nf{0.0062}&\nf{0.0060}&\nf{0.0053}\\
&11&\nf{0.0075}&\nf{0.0056}&\nf{0.0056}&\nf{0.0056}&\nf{0.0066}&\nf{0.0097}\\
&12&\nf{0.0054}&\ff{0.0030}&\nf{0.0088}&\nf{0.0085}&\nf{0.0056}&\nf{0.0091}\\
&13&\nf{0.0077}&\nf{0.0073}&\nf{0.0059}&\nf{0.0075}&\nf{0.0049}&\nf{0.0053}\\
&14&\nf{0.0062}&\nf{0.0057}&\nf{0.0099}&\nf{0.0068}&\nf{0.0087}&\nf{0.0067}\\
\smash{%
\lower\dimexpr\dp\csname @arstrutbox\endcsname-\dp\strutbox+\arrayrulewidth\relax
\hbox{\rotatebox[origin=bl]{90}{%
\textsf{%
%\fboxsep=-\fboxrule
%\fbox{%
\parbox[b]{\dimexpr 9\dp\csname @arstrutbox\endcsname+9\ht\csname @arstrutbox\endcsname\relax}{%
\centering
\strut Number of Neurons\linebreak in Hidden Layer\strut
}%
%}%
}%
}}%
}%
&15&\nf{0.0061}&\nf{0.0069}&\nf{0.0101}&\nf{0.0065}&\nf{0.0080}&\nf{0.0071}\\
\end{tabular}
\endgroup
\end{document}
答案4
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{rotating}
\begin{document}
\begin{tabular}{lccccccc}
&& \multicolumn{6}{c}{Learning Rate}\\
&& 0.1 & 0.25 & 0.40 & 0.55 & 0.7 & 0.95 \\ \hline\\
\rotatebox{90}{\multirow{10}*{\vspace{96pt}\hspace{-150pt}Number of Neurons in Hidden Layer}} & \vspace{5pt} 7 & 0.0052 & \boxed{0.0031} & 0.0070 & 0.0075 & 0.0092 & 0.0048 \\
& \vspace{5pt}8 & 0.0061 & 0.0075 & 0.0071 & 0.0065 & 0.0062 & 0.0078 \\
&\vspace{5pt}9 & 0.0078 & 0.0087 & 0.0057 & 0.0079 & 0.0094 & 0.0060 \\
&\vspace{5pt}10 & 0.0040 & 0.0061 & 0.0084 & 0.0062 & 0.0060 & 0.0053 \\
&\vspace{5pt}11 & 0.0075 & 0.0056 & 0.0056 & 0.0056 & 0.0066 & 0.0097 \\
&\vspace{5pt}12 & 0.0054 & \boxed{0.0030} & 0.0088 & 0.0085 & 0.0056 & 0.0091 \\
&\vspace{5pt}13 & 0.0077 & 0.0073 & 0.0059 & 0.0075 & 0.0049 & 0.0053 \\
&\vspace{5pt}14 & 0.0062 & 0.0057 & 0.0099 & 0.0068 & 0.0087 & 0.0067 \\
&\vspace{5pt}15 & 0.0061 & 0.0069 & 0.0101 & 0.0065 & 0.0080 & 0.0071 \\
\end{tabular}
\end{document}