節標題和旋轉表位於同一頁上

節標題和旋轉表位於同一頁上

我有一張桌子,根據其大小必須旋轉。此外,在我的文件中,它是附錄中的第一個表,因此必須遵循節標題。 Sidewaystable 不允許在同一頁上同時包含節標題和旋轉表格。因此,我嘗試了 hvfloat 包以及 rotfloat / varwidth 包,但兩者都沒有帶來完美的解決方案:

\documentclass[12pt,a4paper]{article}

\usepackage{hvfloat}
\usepackage{rotfloat}
\usepackage{varwidth}
    
\begin{document}

\section{Test Section 1}
\begin{center}
\hvFloat[nonFloat=true, capPos=t, rotAngle=90, objectPos=c]%
{table}%
{\begin{tabular}{lll}
column 1a & column 2a & column 3a \\
column 1b & column 2b & column 3b \\
column 1c & column 2c & column 3c \\
\end{tabular}}
{A rotated table}
{tab:test1}
\end{center}

\newpage
\section{Test Section 2}       
\begin{table}[H]
\begin{center}
\rotatebox{90}{%
\begin{varwidth}{\textheight}
\caption{Another rotated table}\label{tab:test2}
\begin{tabular}{lll}
column 1a & column 2a & column 3a \\
column 1b & column 2b & column 3b \\
column 1c & column 2c & column 3c \\
\end{tabular}
\captionsetup{font=footnotesize}  
\caption*{This table is just a test.}
\end{varwidth}}
\end{center}
\end{table}

\end{document}

在這兩種情況下,我都發現表格與節標題位於同一頁上,但是:

對於 hvfloat,(1) 儘管使用了該選項,capPos=t標題仍然始終位於表格的左側。我已閱讀文檔,但我不知道我在這裡做錯了什麼。 (2) 我找不到添加表格註釋的選項(在我使用的表格環境中,\caption*{Table Notes}但這在這裡不起作用)。桌子本身是垂直和水平放置的,就像我想要的那樣。

在旋轉框的情況下,我設法將標題放在表格頂部,將表格註釋放在表格下方,但無論我做什麼,表格仍然位於頁面底部(雖然它應該水平居中並垂直跟隨節標題) )。

任何提示將不勝感激。謝謝。

答案1

使用capPos=top代替會capPos=t產生以下輸出:

在此輸入影像描述

\documentclass[12pt,a4paper]{article}

\usepackage{hvfloat}
\usepackage{rotfloat}
\usepackage{varwidth}
    
\begin{document}

\section{Test Section 1}
\begin{center}
\hvFloat[nonFloat=true, capPos=top, rotAngle=90, objectPos=c]%
{table}%
{\begin{tabular}{lll}
column 1a & column 2a & column 3a \\
column 1b & column 2b & column 3b \\
column 1c & column 2c & column 3c \\
\end{tabular}}
{A rotated table}
{tab:test1}
\end{center}
\end{document}

其中tabular*和 a\multicolumn代表表 ntes:

在此輸入影像描述

\documentclass[12pt,a4paper]{article}

\usepackage{hvfloat}
\usepackage{booktabs}

\begin{document}

\section{Test Section 1}
\begin{center}
\hvFloat[nonFloat=true, capPos=top, rotAngle=90, objectPos=c]%
{table}%
{\begin{tabular*}{7cm}{@{\extracolsep{\fill}}lll@{}}
\toprule
column 1a & column 2a & column 3a \\
column 1b & column 2b & column 3b \\
column 1c & column 2c & column 3c \\
\bottomrule
\multicolumn{3}{@{}p{7cm}@{}}{these are some table notes these are some table notes these are some table notes these are some table notes these are some table notes}\\
\end{tabular*}}
{A rotated table}
{tab:test1}

\end{center}
\end{document}

答案2

添加標題的主要問題\section是它減少了剩餘空間(旋轉前的寬度)。而且,讓小型頁面像表格一樣(請參閱 參考資料\setcaptype)比使表格像小型頁面一樣容易。

請注意,\centering影響垂直位置(旋轉後),而迷你頁的第三個可選參數會影響水平位置(旋轉後)。

\documentclass[12pt,a4paper]{article}

\usepackage{adjustbox}
\usepackage{threeparttable}
\usepackage{showframe}% MWE only

\newsavebox{\tempbox}

\newcommand{\setcaptype}[1]% #1 = figure or table
  {\expandafter\def\csname @captype\endcsname{#1}\ignorespaces}
    
\begin{document}

\setbox\tempbox=\vbox{\section{Test Section 2}}% measure size of section title
\usebox\tempbox

\rotatebox{90}{\begin{minipage}[c][\textwidth][c]{\dimexpr \textheight-\ht\tempbox-\dp\tempbox-\baselineskip-\parskip}
\setcaptype{table}\centering
\begin{threeparttable}
\caption{Another rotated table}\label{tab:test2}
\begin{tabular}{lll}
column 1a & column 2a & column 3a \\
column 1b & column 2b & column 3b \\
column 1c & column 2c & column 3c \\
\end{tabular}
\begin{tablenotes}
\item The first note.
\end{tablenotes}
\end{threeparttable}
\end{minipage}}

\end{document}

相關內容