在同一页上旋转带标题的表格

在同一页上旋转带标题的表格

我想旋转一张桌子,因为它太宽了。我被迫使用\documentclass[11pt,a4paper]{article},所以改变它不是一个解决方案。许多包会旋转整个页面,但我只想旋转表格。

我有一个表格的设计样本,我必须使用它。在我的 tex 代码中,这是我的第一个表格。 在此处输入图片描述

第二个片段是关于如何旋转表格的。但我缺少表格上必需的标题。 在此处输入图片描述

第三个片段是我真正想要的,但我得到了一个LaTeX Error: Not in outer par mode。我发现了一个类似的问题旋转表格,标题为:“不处于外部模式。\begin{table}[h]”但是答案提供了一个使用 sidewaystable 的解决方案,而这在我看来非常丑陋,因为旋转后的表格本身就占据了整个页面。

\documentclass[11pt,a4paper]{article}
\usepackage[graphicx]{realboxes}
\usepackage{verbatim}
\begin{document}
\begin{table}[htb]
\begin{center}
\begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}
\hline
\bf Some text & \rotatebox{90}{column 1  } &  \rotatebox{90}{column 2} & \rotatebox{90}{column 3  } & \rotatebox{90}{column 4 } & \rotatebox{90}{column 5 }  & \rotatebox{90}{column 6  } &  \rotatebox{90}{column 7} & \rotatebox{90}{column 8 } & \rotatebox{90}{column 9 } & \rotatebox{90}{column 10 } & \rotatebox{90}{column 11 } &  \rotatebox{90}{column 12} & \rotatebox{90}{column 13 } & \rotatebox{90}{column 14  } & \rotatebox{90}{column 15 }\\
\hline \hline
first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\
\hline
\end{tabular}
\end{center}
 \caption{My caption lorem ipsum}\label{tab_aaa}
\end{table}


%rotated
\rotatebox{90}{
\begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}
\hline
\bf Some text & \rotatebox{90}{column 1  } &  \rotatebox{90}{column 2} & \rotatebox{90}{column 3  } & \rotatebox{90}{column 4 } & \rotatebox{90}{column 5 }  & \rotatebox{90}{column 6  } &  \rotatebox{90}{column 7} & \rotatebox{90}{column 8 } & \rotatebox{90}{column 9 } & \rotatebox{90}{column 10 } & \rotatebox{90}{column 11 } &  \rotatebox{90}{column 12} & \rotatebox{90}{column 13 } & \rotatebox{90}{column 14  } & \rotatebox{90}{column 15 }\\
\hline \hline
first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\
\hline
\end{tabular}
}

\begin{comment}
%% what i want
\rotatebox{90}{
\begin{table}[htb]
\begin{center}
\begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}
\hline
\bf Some text & \rotatebox{90}{column 1  } &  \rotatebox{90}{column 2} & \rotatebox{90}{column 3  } & \rotatebox{90}{column 4 } & \rotatebox{90}{column 5 }  & \rotatebox{90}{column 6  } &  \rotatebox{90}{column 7} & \rotatebox{90}{column 8 } & \rotatebox{90}{column 9 } & \rotatebox{90}{column 10 } & \rotatebox{90}{column 11 } &  \rotatebox{90}{column 12} & \rotatebox{90}{column 13 } & \rotatebox{90}{column 14  } & \rotatebox{90}{column 15 }\\
\hline \hline
first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\
\hline
\end{tabular}
\end{center}
 \caption{My caption lorem ipsum}\label{tab_b}
\end{table}
}
\end{comment}
\end{document}

如何为第二个片段添加标题?

答案1

您的表格非常大,而且无论如何都会占用一页,因此 sidewaystable 可能是最佳解决方案。但您也可以将表格和标题放在 minipage 或 varwidth 框中,然后旋转:

\documentclass[11pt,a4paper]{article}
\usepackage[graphicx]{realboxes}
\usepackage{varwidth}
\begin{document}
%% what i want
\begin{table}[htb]
\centering
 \rotatebox{90}{%
   \begin{varwidth}{\textheight}
      \begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}
       \hline
        \bfseries Some text & \rotatebox{90}{column 1  } &  \rotatebox{90}{column 2} & \rotatebox{90}{column 3  } & \rotatebox{90}{column 4 } & \rotatebox{90}{column 5 }  & \rotatebox{90}{column 6  } &  \rotatebox{90}{column 7} & \rotatebox{90}{column 8 } & \rotatebox{90}{column 9 } & \rotatebox{90}{column 10 } & \rotatebox{90}{column 11 } &  \rotatebox{90}{column 12} & \rotatebox{90}{column 13 } & \rotatebox{90}{column 14  } & \rotatebox{90}{column 15 }\\
         \hline \hline
        first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\            \hline
       \end{tabular}
        \caption{My caption lorem ipsum}\label{tab_b}
    \end{varwidth}}
\end{table}


For the table see \ref{tab_b}

\end{document}

注意:不要使用 \bf,而应使用 \bfseries。

答案2

\documentclass[11pt,a4paper]{article}
\usepackage{hvfloat}
\def\RB#1{\rotatebox{90}{#1}}
\begin{document}

\hvFloat[%
     floatPos=!htb,
     capWidth=h,% of \columnwidth
     capPos=r,
     objectAngle=90,
     capAngle=90,
     objectPos=l % l c r
]{table}{%
\begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}\hline
\bf Some text & \RB{column 1  } &  \RB{column 2} & \RB{column 3  } & \RB{column 4 } & \RB{column 5 }  & \RB{column 6  } &  \RB{column 7} & \RB{column 8 } & \RB{column 9 } & \RB{column 10 } & \RB{column 11 } &  \RB{column 12} & \RB{column 13 } & \RB{column 14  } & \RB{column 15 }\\
\hline \hline
first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\
\hline
\end{tabular}
}%
[Centered Caption beside Object] % TOC entry
{Caption vertically centered right beside the float with a caption
           width of \texttt{0.5\textbackslash columnwidth} and \texttt{%
           floatcapsep=5pt} (the default)}
{fig:2}% label

\end{document}

答案3

我发现使用这个包是最容易的。虽然不适用于本示例,但roatfloat它也适用于。sidewaystable

    \documentclass[11pt,a4paper]{article}
    \usepackage{rotfloat}
    \usepackage{varwidth}

    \begin{document}
       For the table see \ref{tab_a}
        \begin{table}[H]
             \centering
             \rotatebox{90}{%
                \begin{varwidth}{\textheight}
                  \begin{tabular}{|l|c|c|c|c|c||c|c|c|c|c||c|c|c|c|c|}
                  \hline
                  \bfseries Some text & \rotatebox{90}{column 1  } &  \rotatebox{90}{column 2} & \rotatebox{90}{column 3  } & \rotatebox{90}{column 4 } & \rotatebox{90}{column 5 }  & \rotatebox{90}{column 6  } &  \rotatebox{90}{column 7} & \rotatebox{90}{column 8 } & \rotatebox{90}{column 9 } & \rotatebox{90}{column 10 } & \rotatebox{90}{column 11 } &  \rotatebox{90}{column 12} & \rotatebox{90}{column 13 } & \rotatebox{90}{column 14  } & \rotatebox{90}{column 15 }\\
                  \hline \hline
                  first row lorem ipsum & 692 & 535 & 85 & 48 & 24 & 692 & 535 & 85 & 48 & 24 & 2 & 3 & 3 & 4 & 5 \\            \hline
                  \end{tabular}
                \caption{My caption lorem ipsum}\label{tab_a}
               \end{varwidth}}
        \end{table}

     Another reference see \ref{tab_a}
   \end{document}

相关内容