floatrow
我正在尝试使用下面的代码和包创建一个图像和两个相邻的表格
\begin{figure}
\begin{floatrow}
\ffigbox{%
\rule{3cm}{3cm}%
}{%
\caption{A figure}%
}
\capbtabbox{%
\begin{tabular}{cc} \hline
Author & Title \\ \hline
Knuth & The \TeX book \\
Lamport & \LaTeX \\ \hline
\end{tabular}
\begin{tabular}{cc} \hline
Author & Title \\ \hline
Knuth & The \TeX book \\
Lamport & \LaTeX \\ \hline
\end{tabular}
}{}
\end{floatrow}
\end{figure}
但我只能得到这个布局
您能否告诉我是否有一个简单的解决方法,可以将表格一个接一个地摆放,而不是并排摆放。谢谢。
答案1
使用这个(非专业)代码:
\documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx,lipsum}
\usepackage{caption}[2007/04/11]
\begin{document}
\lipsum[1]\\
\begin{figure}[h!]
% \vspace{1cm}
\rule{3cm}{4cm}%
\end{figure}
\vspace{-5.3cm} % <<<< TRIALS AND ERRORS
\qquad \qquad
\begin{table}[htp]
\centering
\caption{First table}
\begin{tabular}{lll}
\hline
1 & 2 & $\sin x$\\
3 & 4 & $\cos x$\\
5 & 6 & $\tan x$\\
\hline
\end{tabular}
\caption{First table}
\begin{tabular}{lll}
\hline
1 & 2 & $\sin x$\\
3 & 4 & $\cos x$\\
5 & 6 & $\tan x$\\
\hline
\end{tabular}
\end{table}\\
\noindent\lipsum[1-2]
\end{document}
答案2
我把它弄得比实际更复杂,但这样它就可以处理各种宽度。
\documentclass{article}
\usepackage{caption}
\begin{document}
\begin{figure}
\hrule% MWE only
\centering
\sbox0{\rule{3cm}{3cm}}% measure width
\begin{minipage}[c]{\wd0}
\usebox0
\caption{A figure}%
\end{minipage}\hfil
\sbox1{\begin{tabular}{cc} \hline
Author & Title \\ \hline
Knuth & The \TeX book \\
Lamport & \LaTeX \\ \hline
\end{tabular}}%
\sbox2{\begin{tabular}{cc} \hline
Author & Title \\ \hline
Knuth & The \TeX book \\
Lamport & \LaTeX \\ \hline
\end{tabular}}%
\ifdim\wd1>\wd2 \dimen0=wd1 \else \dimen0=\wd2 \fi
\begin{minipage}[c]{\dimen0}
\captionof{table}{A table}
\centering
\usebox1
\usebox2
\end{minipage}
\hrule% MWE only
\end{figure}
\end{document}