表格和长表居中和标题对齐

表格和长表居中和标题对齐

我想以一种特殊的方式格式化表和长表:

1)table/longtable 应该位于页面的中心

2)表格/长表格标题应位于左右表格/长表格宽度之间;还应与对象的左边缘对齐。


在环境中使用\centering命令\table满足第一个要求(longtable 默认居中)

我找到了一种满足表格第二个要求的方法 - 使用\usepackage{floatrow}并重新格式化所有表格\ttabbox{}{}。但有两个缺点:

  • 我不知道如何将它与 longtable 一起使用

  • \usepackage{floatrow}使长表位于页面左侧

提供了最少的示例。

\documentclass[12pt, a4paper, final, oneside, titlepage]{article}
\usepackage{caption}
\usepackage{longtable}
%\usepackage{float}
%\usepackage{floatrow}

\begin{document}
Table should be positioned at the center of the page, and caption should be positioned between left and right edge of table (aligned to left edge)

\begin{table}[h!]
    \centering
    \caption{Very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long caption}
    \begin{tabular}{|c|c|p{8cm}|}
        \hline
        a & b & c \\ \hline
        1 & 2 & 3 \\ \hline
    \end{tabular}
\end{table}

Longtable  should positioned at the center of the page, and caption should be positioned between left and right edge of table (aligned to left edge)

\begin{longtable}[h!]{|p{5cm}|p{3cm}|}

    \caption{Very,  very, very, very, very, very, very, very  very, very, very, very, very, very, very long caption} \\

    \hline
    a & b \\ \hline
    \endfirsthead

    \multicolumn{2}{l}{Short caption} \\
    \hline
    a & b \\ \hline
    \endhead

    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline       
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
    Some string & c \\ \hline
\end{longtable}
\end{document}

相关内容