4

Here is what I want:

enter image description here

And I created simple table as below:

\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}

Can someone please help me understand how can I put labels on first row and first column like show in image? Any help, links or resources would be appreciated.

  • 1
    Welcome to TeX.SE. Please, complete your code snipped to small documment, which can be compiled. Also what you mean with "labels"? Frames around some cells? – Zarko Jul 4 '16 at 2:58
  • For the upper text (Learning rate) try adding the line ` & & & & Learning rate & & & \\ ` as a first line inside the tabular environment. – SAM Jul 4 '16 at 3:14
  • @Zarko he meant by label the side and upper text from what i understand, since his code doesn't containt the two texts. – SAM Jul 4 '16 at 3:35
  • Can you tell is you are using a special document class rather than the usual class like article? and maybe also what font size? – SAM Jul 4 '16 at 3:37
  • @SAM I'm just using article class. – Shivam Jul 4 '16 at 4:05
4

In my experience, readers strongly dislike to have to crane their necks to read a column header that's been rotated 90 degrees, especially if there's just a single such column header. I therefore recommend you place the string "Number of Neurons in Hidden Layer" above the first column, while providing one line break in the string. Separately, I would also recommend that you dispense with all vertical lines in the table.

enter image description here

\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

I used \multicolumn from the package multirow to merge the first tow columns together and the remaning columns of the first row together (where "Learning Rate" is contained). The other text must be rotated for that i used the command \rotatebox from the package rotating, and lay out on 9 rows (\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}

Output output

0

Here is what I get by rotating in the last row by 90 degrees around the bottom left corner a box containing the label for the rows; as I wished to keep the label for the rows as a one-liner that does not stick over the horizontal line, I decided to have TeX do some \dimexpr-calculations for spreading the \hbox with a negative value in case the line is too long under normal circumstances; the \struts at the beginning and at the end of the label are there for ensuring that the box has enough depth which is important as rotation goes around a bottom corner:

enter image description here

\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}

(By the way: I used \smashfor ensuring that height and depth of the rotated box won't affect the height of the table-row where the rotated box occurred.)

In case you wish a linebreak, I suggest omitting the spreading-calculations and letting the surrounding \parbox do its job while probably inserting some linebreak-commands oneself:

enter image description here

\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}
-1
\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}

rottbl

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.