旋转表格侧面的文字?

旋转表格侧面的文字?

在下面的代码中,我想将文本“Probability”旋转 90 度,并将其放在表格左侧的一列中。我还想在顶行“Probability”的两侧添加垂直条。如您所见,我还没有实现这一点,下面是我的代码 -

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

编辑:这也不起作用!

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

答案1

您想要的就是这样的东西吗?我过去常常\cline避免在第一列中使用水平线,而是在第一行中使用{|c|}垂直multicolumn线,并将旋转后的文本作为元素放置在其中一行的第一列中。

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

在此处输入图片描述

答案2

你可以使用multirow包裹

截屏

以下是完整代码,重点部分是:

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

请注意,这里很多人都会推荐booktabssiunitx此类表的包装:

截屏

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

相关内容