5

In the following code I want to rotate the text 'Probability' 90 degrees and have it in a column to itself at the left hand side of the table. I would also like vertical bars either side of the top row 'Probability'. As you can see, I haven't been able to achieve this, here is my code -

\begin{document}
\begin{figure}[h]
\centering
    \scalebox{0.7}{
    $\begin{tabular}{|c | c | c | c | c | c | c | c | c | c | c | c |}
    \hline
    \multicolumn{12}{c}{Position}  \\ \hline
     & -5 & -4 & -3 & -2 & -1 & 0 & 1 & 2 & 3 & 4 & 5  \\ \hline
     & 0          & 0         & 0         & 0         & 0         & 1     & 0         & 0         & 0         & 0         & 0         \\ \hline
     & 0          & 0         & 0         & 0         & 0.5       & 0     & 0.5       & 0         & 0         & 0         & 0         \\ \hline
     & 0          & 0         & 0         & 0.25      & 0         & 0.5   & 0         & 0.25      & 0         & 0         & 0         \\ \hline
     & 0          & 0         & 0.125     & 0         & 0.375     & 0     & 0.375     & 0         & 0.125     & 0         & 0         \\ \hline
     & 0          & 0.0625    & 0         & 0.25      & 0         & 0.375 & 0         & 0.25      & 0         & 0.0625    & 0         \\ \hline
     & 0.03125    & 0         & 0.15625   & 0         & 0.3125    & 0     & 0.3125    & 0         & 0.15625   & 0         & 0.03125   \\ \hline
     \rot{\rlap{~Probability}} \\
    \end{tabular}$
    }
\caption{Probabilities for the first $5$ steps of a classical random walk.}
\label{cw_first_5_steps}
\end{figure}
\end{document}

Edit: This doesn't work either!

\begin{figure}[h]
\centering
    \scalebox{0.8}{
    $\begin{tabular}{|c | c | c | c | c | c | c | c | c | c | c | c |}
    \hline
    \multicolumn{12}{c}{Position}  \\ \hline
     & -5           & -4        & -3        & -2        & -1        & 0     & 1         & 2         & 3         & 4         & 5         \\ \hline
     \multirow{6}{*}{\rotatebox[origin=c]{90}{Probability}}&
     & 0            & 0         & 0         & 0         & 0         & 1     & 0         & 0         & 0         & 0         & 0         \\ \hline
     & 0            & 0         & 0         & 0         & 0.5       & 0     & 0.5       & 0         & 0         & 0         & 0         \\ \hline
     & 0            & 0         & 0         & 0.25      & 0         & 0.5   & 0         & 0.25      & 0         & 0         & 0         \\ \hline
     & 0            & 0         & 0.125     & 0         & 0.625     & 0     & 0.125     & 0         & 0.125     & 0         & 0         \\ \hline
     & 0            & 0.0625    & 0         & 0.625     & 0         & 0.125 & 0         & 0.125     & 0         & 0.0625    & 0         \\ \hline
     & 0.03125      & 0         & 0.53125   & 0         & 0.125     & 0     & 0.125     & 0         & 0.15625   & 0         & 0.03125   \\ \hline
    \end{tabular}$
    }
\caption{Probabilities for the first $5$ steps of a classical random walk.}
\label{cw_first_5_steps}
\end{figure}
sonicboom
  • 579

2 Answers2

4

Is something like this what you seek? I used \cline to avoid the horizontal lines in column 1, I used {|c|} in the multicolumn to get vertical lines on row 1, and I placed the rotated text as an element in column one of one of the rows itself.

\documentclass{article}
\usepackage{graphicx}
\def\rot#1{\rotatebox{90}{#1}}
\begin{document}
\begin{figure}[h]
\centering
    \scalebox{0.7}{
    $\begin{tabular}{|c | c | c | c | c | c | c | c | c | c | c | c |}
    \hline
    \multicolumn{12}{|c|}{Position}  \\ \hline
     & -5 & -4 & -3 & -2 & -1 & 0 & 1 & 2 & 3 & 4 & 5  \\ \cline{2-12}
     & 0          & 0         & 0         & 0         & 0         & 1     & 0         & 0         & 0         & 0         & 0         \\ \cline{2-12}
     & 0          & 0         & 0         & 0         & 0.5       & 0     & 0.5       & 0         & 0         & 0         & 0         \\ \cline{2-12}
     & 0          & 0         & 0         & 0.25      & 0         & 0.5   & 0         & 0.25      & 0         & 0         & 0         \\ \cline{2-12}
     & 0          & 0         & 0.125     & 0         & 0.375     & 0     & 0.375     & 0         & 0.125     & 0         & 0         \\ \cline{2-12}
  \rot{\rlap{~Probability}}     & 0          & 0.0625    & 0         & 0.25      & 0         & 0.375 & 0         & 0.25      & 0         & 0.0625    & 0         \\\cline{2-12}
   & 0.03125    & 0         & 0.15625   & 0         & 0.3125    & 0     & 0.3125    & 0         & 0.15625   & 0         & 0.03125   \\ \hline
    \end{tabular}$
    }
\caption{Probabilities for the first $5$ steps of a classical random walk.}
\label{cw_first_5_steps}
\end{figure}
\end{document}

enter image description here

3

You can get the result you wish by using the multirow package

screenshot

Here's the complete code, the important part is:

% arara: pdflatex
\documentclass{article}
\usepackage{graphicx}
\usepackage{multirow}
\begin{document}
\begin{figure}[h]
\centering
    \scalebox{0.7}{
    $\begin{tabular}{|c | c | c | c | c | c | c | c | c | c | c | c |}
    \hline
    \multicolumn{12}{c}{Position}  \\ \hline
     \multirow{7}{*}{\rotatebox[origin=c]{90}{~Probability}} & -5 & -4 & -3 & -2 & -1 & 0 & 1 & 2 & 3 & 4 & 5  \\ \cline{2-12}
     & 0          & 0         & 0         & 0         & 0         & 1     & 0         & 0         & 0         & 0         & 0         \\ \cline{2-12}
     & 0          & 0         & 0         & 0         & 0.5       & 0     & 0.5       & 0         & 0         & 0         & 0         \\ \cline{2-12}
     & 0          & 0         & 0         & 0.25      & 0         & 0.5   & 0         & 0.25      & 0         & 0         & 0         \\ \cline{2-12}
     & 0          & 0         & 0.125     & 0         & 0.375     & 0     & 0.375     & 0         & 0.125     & 0         & 0         \\ \cline{2-12}
     & 0          & 0.0625    & 0         & 0.25      & 0         & 0.375 & 0         & 0.25      & 0         & 0.0625    & 0         \\ \cline{2-12}
     & 0.03125    & 0         & 0.15625   & 0         & 0.3125    & 0     & 0.3125    & 0         & 0.15625   & 0         & 0.03125   \\ \hline
    \end{tabular}$
    }
\caption{Probabilities for the first $5$ steps of a classical random walk.}
\label{cw_first_5_steps}
\end{figure}
\end{document}

Note that you a lot of folks here would recommend the booktabs and siunitx package for this type of table:

screenshot

% arara: pdflatex
\documentclass{article}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{figure}[h]
\centering
    \begin{tabular}{c |S[table-format=1.6] S[table-format=1.4] S[table-format=1.5] S[table-format=1.2]S[table-format=1.4]S[table-format=1.3]S[table-format=1.4]S[table-format=1.2]S[table-format=1.5]S[table-format=1.4]S[table-format=1.5]}
      \toprule
    \multicolumn{12}{c}{Position}  \\ 
    \midrule
     \multirow{7}{*}{\rotatebox[origin=c]{90}{~Probability}} & -5 & -4 & -3 & -2 & -1 & 0 & 1 & 2 & 3 & 4 & 5  \\ 
     & 0          & 0         & 0         & 0         & 0         & 1     & 0         & 0         & 0         & 0         & 0         \\ 
     & 0          & 0         & 0         & 0         & 0.5       & 0     & 0.5       & 0         & 0         & 0         & 0         \\ 
     & 0          & 0         & 0         & 0.25      & 0         & 0.5   & 0         & 0.25      & 0         & 0         & 0         \\
     & 0          & 0         & 0.125     & 0         & 0.375     & 0     & 0.375     & 0         & 0.125     & 0         & 0         \\
     & 0          & 0.0625    & 0         & 0.25      & 0         & 0.375 & 0         & 0.25      & 0         & 0.0625    & 0         \\
     & 0.03125    & 0         & 0.15625   & 0         & 0.3125    & 0     & 0.3125    & 0         & 0.15625   & 0         & 0.03125   \\
     \bottomrule
    \end{tabular}
\caption{Probabilities for the first $5$ steps of a classical random walk.}
\label{cw_first_5_steps}
\end{figure}
\end{document}
cmhughes
  • 100,947