Sweave:浮动文本和四个表格固定在第一页的底部

Sweave:浮动文本和四个表格固定在第一页的底部

我正在尝试创建一个包含浮动文本的文档,该文本可以扩展到多页长度,并且包含四个固定在第一页底部的表格(左上表格、右上表格、左下表格、右下表格)。我尝试了下面的代码,但表格在第一页的底部没有正确对齐,而是溢出到第二页,并且一个接一个。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{caption}
\title{Floating Text and four tables anchored at bottom of the first page}
\author{}
\date{}
\begin{document}
\maketitle

Text
ttttttttttttttttttttttttttttttttttttttttttttttttt
ttttttttttttttttttttttttttttttttttttttttttttttttttttt
ttttttttttttttttttttttttttttttttttttttttttttttttttttt
tttttttttttttttttttttttttttttttttttttttttttttttttttttttt


<<echo=FALSE,results=tex>>=
myData <- matrix(c(19,89,23,23,74,44,16,39,67),ncol=3,byrow=TRUE)
colnames(myData) <- c("A","B","C")
rownames(myData) <- c("1","2","3")
myData2 <- myData * 2
@



\begin{table}[b]


\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
library("xtable")
print(xtable(myData),
  floating=FALSE,
  hline.after=NULL,
 add.to.row=list(pos=list(-1,0, nrow(myData)),
  command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The top left table}
\end{minipage}



\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
print(xtable(myData2),
  floating=FALSE,
  hline.after=NULL,
  add.to.row=list(pos=list(-1,0, nrow(myData2)),
  command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The top right table}
\end{minipage}


\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
print(xtable(myData2),
  floating=FALSE,
  hline.after=NULL,
  add.to.row=list(pos=list(-1,0, nrow(myData2)),
  command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The bottom left table}
\end{minipage}


\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
print(xtable(myData2),
  floating=FALSE,
  hline.after=NULL,
  add.to.row=list(pos=list(-1,0, nrow(myData2)),
  command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The bottom right table}
\end{minipage}



\end{table}




\end{document}

我将很感激你的帮助。

答案1

有几件事:

  • TeX 中的空行表示某种含义:段落分隔符。这就是为什么表格会一个接一个地堆叠在一起(垂直方向)。删除空行以确保内容彼此堆叠在一起(水平方向)。

  • 放置table 实际的文本,因为您希望它出现在底部第一的页面。如果您将其放置在文本并且文本溢出到第二页,您table必然会停留在第二页(或更晚)。

这是一个最小的例子,展示了您应该使用什么(而\SweaveTable不是您的 Sweave 输入):

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs,caption}
\usepackage{lipsum}% Just for this example
\title{Floating Text and four tables anchored at bottom of the first page}
\author{}
\date{}

\newcommand{\SweaveTable}{%
  \begin{tabular}{*{4}{c}}
    \toprule
    & A & B & C \\
    \midrule
    1 & 19 & 23 & 16 \\
    2 & 89 & 74 & 39 \\
    3 & 23 & 44 & 67 \\
    \bottomrule
  \end{tabular}%
}

%\renewcommand{\bottomfraction}{0.5}
\begin{document}
\maketitle

\begin{table}[!b]
  \begin{minipage}{.5\linewidth}
    \centering
    \SweaveTable
    \captionof{table}{The top left table}
  \end{minipage}%
  \begin{minipage}{.5\linewidth}
    \centering
    \SweaveTable
    \captionof{table}{The top right table}
  \end{minipage}

  \begin{minipage}{.5\linewidth}
    \centering
    \SweaveTable
    \captionof{table}{The bottom left table}
  \end{minipage}%
  \begin{minipage}{.5\linewidth}
    \centering
    \SweaveTable
    \captionof{table}{The bottom right table}
  \end{minipage}
\end{table}

\lipsum[1-7]

\end{document}

取决于table,你可能必须调整浮动参数(例如\bottomfraction)。

答案2

使用该包的另一种实现subcaption。如果不进行任何设置,标题的标签将显示为 (a)、(b)、(c) 和 (d)。因此,我们必须向包传递一些参数subcaption才能获得表格的正常外观。即,以下两个命令可实现此目的:

\renewcommand{\thesubtable}{Table \arabic{subtable}}
\captionsetup[subtable]{labelformat=simple, labelsep=colon}

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs,caption,subcaption}
\usepackage{lipsum}% Just for this example

\renewcommand{\thesubtable}{Table \arabic{subtable}}
\captionsetup[subtable]{labelformat=simple, labelsep=colon}

\title{Floating Text and four tables anchored at bottom of the first page}
\author{}
\date{}

\newcommand{\SweaveTable}{%
  \begin{tabular}{*{4}{c}}
    \toprule
    & A & B & C \\
    \midrule
    1 & 19 & 23 & 16 \\
    2 & 89 & 74 & 39 \\
    3 & 23 & 44 & 67 \\
    \bottomrule
  \end{tabular}%
}

\begin{document}
\maketitle

\begin{table}[!b]
\begin{subtable}[b]{.5\linewidth}\centering
    \captionof{table}{The top left table}
    \SweaveTable
  \end{subtable}%
\begin{subtable}[b]{.5\linewidth}\centering
    \captionof{table}{The top right table}
    \SweaveTable
  \end{subtable}%
\medskip

\begin{subtable}[b]{.5\linewidth}\centering
    \captionof{table}{The bottom left table}
    \SweaveTable
  \end{subtable}%    
\begin{subtable}[b]{.5\linewidth}\centering
    \captionof{table}{The bottom right table}
    \SweaveTable
  \end{subtable}% 
\end{table}

\lipsum[1-7]

\end{document}

编辑:

根据 OP 的评论,关闭标题中的 Table1:、Table2:、Table3:、Table4: 很容易。应该删除以下两行:

\renewcommand{\thesubtable}{Table \arabic{subtable}}
\captionsetup[subtable]{labelformat=simple, labelsep=colon}

并添加以下行:

\captionsetup[subtable]{labelformat=empty}

这样,字幕的标签就会被删除。

在此处输入图片描述

对于将表格放在某些特定页面上,该afterpage包可能会有用。目前,我没有详细信息来提供示例。

相关内容