旋轉表格並在同一頁上新增標題

旋轉表格並在同一頁上新增標題

我想旋轉桌子,因為它太寬了。我被迫使用\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}

相關內容