我遇到了一个问题。我刚刚制作了一张非常宽的桌子,所以我决定把它分成两个较小的桌子。结果发现第二半的宽度比第一半的宽度要小一点。现在我想要这些两张桌子互相位于下方,即与左侧的距离完全相同。另外,较大的一个居中,但我不希望第二个较小的一个也居中。我希望它从左侧开始,与较大的一个位置相同。如何在 Latex 中做到这一点?以下是两个表的代码:
\documentclass[a4paper]{scrreprt}
\usepackage{setspace}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage[labelfont=bf, labelsep=newline,singlelinecheck=false]{caption}
\usepackage{floatrow}
\KOMAoption{captions}{tableheading}
\setcapindent{0em}
\pagestyle{headings}
\begin{document}
\begin{table}[htpb]
\begin{floatrow}
\ttabbox{
\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}
}
{
\caption{ABCDE table}\label{tab:ABCDE}
}
\end{floatrow}
\end{table}
\begin{table}[htpb]
\begin{floatrow}
\ttabbox{
\begin{tabular}{lccc}
\toprule
ABCDE & ABCDE & ABCDE & ABCDE & \\
ABCDE &
ABCDE & ABCDE & ABCDE & \\
ABCDE &
ABCDE & ABCDE & ABCDE & \\
\bottomrule
\end{tabular}
}
{
\caption{ABCDE table}\label{tab:ABCDE}
}
\end{floatrow}
\end{table}
\end{document}
谢谢您的提示:)
答案1
我不明白你为什么要使用floatrow
。但是,这里有一个可能性:测量第一个表,并将第二个表设置为迷你页面中的宽度。 的用法geometry
只是为了在页面周围绘制一个框架,以查看相对于边距的位置。
\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}
当您使用 设置了保存框时\sbox{\firsttabbox}
,其宽度为\wd\firsttabbox
。因此,我们可以将此宽度输入到以下内容minipage
并在第一个 中“使用”已保存的框floatrow
。
注意你的使用
\tabbox{
<material>
}
{
\caption{...}
}
添加空格,这些空格应使用%
或其他标记进行保护。因此,例如,如果您希望第二个\tabbox
带有“独立”括号,则必须执行
\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
}
%
不需要 after ,\end{tabular}
因为\end{minipage}
去掉了那个空格。
一个没有的解决方案floatrow
;我们首先排版表格以了解它们的宽度,然后进行最后的排版。
\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}
答案2
\documentclass[a4paper]{scrreprt}
\usepackage{booktabs}
\usepackage[labelfont=bf, labelsep=newline,singlelinecheck=false,]{caption}
\setcapindent{0em}
\parindent=0pt
\newsavebox\TBox
\begin{document}
\rule{\linewidth}{1pt}% only demo
\begin{table}[htb]
\centering
\savebox\TBox{% save it to get the width of the table
\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}}
\parbox{\wd\TBox}{% caption and table 1 in a \parbox
\caption{ABCDE table}\label{tab:ABCDE}
\usebox\TBox}
\bigskip
\parbox{\wd\TBox}{% caption and table 2 with width of 1
\caption{ABCDE table}\label{tab:ABCD}
\begin{tabular}{lccc}\toprule
ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE \\
ABCDE & ABCDE & ABCDE & ABCDE \\\bottomrule
\end{tabular}}
\end{table}
\end{document}