Align position of a table exactly to another one
I don't see why you want to use floatrow
. However, here's a possibility: measure the first table and set the second one in a minipage as wide.
The usage of geometry
is just for drawing a frame around the page to see the placement with respect to the margins.
\documentclass[a4paper]{scrreprt}
\usepackage[pass,showframe]{geometry} % just for this example
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage[labelfont=bf, labelsep=newline,singlelinecheck=false]{caption}
\usepackage{floatrow}
\newbox{\firsttabbox}
\KOMAoption{captions}{tableheading}
\setcapindent{0em}
\pagestyle{headings}
\begin{document}
\begin{table}[htpb]
\sbox{\firsttabbox}{\begin{tabular}{lccccc}
\toprule
ABCDE & ABCDE & ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE & ABCDE & ABCDE \\
\bottomrule
\end{tabular}}
\begin{floatrow}
\ttabbox
{\usebox{\firsttabbox}}
{\caption{ABCDE table}\label{tab:ABCDE}}
\end{floatrow}
\bigskip
\begin{floatrow}
\ttabbox{%
\begin{minipage}{\wd\firsttabbox}
\raggedright
\begin{tabular}{lccc}
\toprule
ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE \\
\bottomrule
\end{tabular}
\end{minipage}}
{\caption{ABCDE table}\label{tab:ABCD}}
\end{floatrow}
\end{table}
\end{document}
When you have set the save box with \sbox{\firsttabbox}
, its width is available as \wd\firsttabbox
. So we can feed this width to the following minipage
and “use” the saved box in the first floatrow
.
Pay attention that your usage
\tabbox{
<material>
}
{
\caption{...}
}
adds spaces which should be protected with %
or with other tokens. So if for instance you want the second \tabbox
with “isolated” braces, you must do
\ttabbox{% <-- important
\begin{minipage}{\wd\firsttabbox}
\raggedright
\begin{tabular}{lccc}
\toprule
ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE \\
\bottomrule
\end{tabular}
\end{minipage}% <-- important
}
{% <-- important
\caption{ABCDE table}\label{tab:ABCD}% <-- important
}
A %
after \end{tabular}
is not needed, because \end{minipage}
gets rid of that space.
A solution without floatrow
; we first typeset the tables for knowing their width and then do the final typesetting.
\documentclass[a4paper]{scrreprt}
\usepackage[pass,showframe]{geometry} % just for this example
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage[labelfont=bf, labelsep=newline,singlelinecheck=false]{caption}
\usepackage{environ}
\KOMAoption{captions}{tableheading}
\setcapindent{0em}
\pagestyle{headings}
\NewEnviron{lefttables}[1][tp]{%
\global\tabwidth=0pt
\vbox{
\renewcommand\caption[2][]{}%
\renewcommand\label[1]{}%
\let\latextabular\tabular
\let\latexendtabular\endtabular
\def\tabular{\setbox8=\hbox\bgroup\latextabular}%
\def\endtabular{\latexendtabular\egroup\settabwidth}
\BODY
}
\begin{table}[#1]
\centering
\begin{minipage}{\tabwidth}\raggedright
\BODY
\end{minipage}
\end{table}
}
\newdimen\tabwidth
\newcommand{\settabwidth}{%
\ifdim\wd8>\tabwidth \global\tabwidth=\wd8 \fi
}
\begin{document}
\begin{lefttables}[htpb]
\caption{ABCDE table}\label{tab:ABCDE}
\begin{tabular}{lccccc}
\toprule
ABCDE & ABCDE & ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE & ABCDE & ABCDE \\
\bottomrule
\end{tabular}
\bigskip
\begin{tabular}{lccc}
\toprule
ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE \\
\bottomrule
\end{tabular}
\end{lefttables}
\end{document}