将标题的宽度调整为表格的宽度

将标题的宽度调整为表格的宽度

可能还有很多类似我提到的问题 网址 1 网址 2

但事实证明,它对我的​​情况不起作用,我读过浮行文档和\FBwidth命令引起了我的注意,但我不知道如何使用它。下面我给出一个例子,目标是表 1 与表 2 的标题相同“适合表格宽度并在中心对齐”

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[left=3cm,top=2.5cm,bottom=2.5cm, right=2.5cm,headheight=1cm,showframe=false]{geometry}
\usepackage{bookmark, amsmath}
\usepackage{multicol,multirow,booktabs, array}
\usepackage{threeparttable, longtable}
\usepackage{floatrow}
\floatsetup[longtable]{LTcapwidth=table}
\floatsetup[table]{position=top}
\usepackage[labelfont=bf,justification=raggedright,singlelinecheck=false]{caption}

\DeclareCaptionLabelSeparator*{spaced}{\\[2ex]}
\captionsetup[figure]{name=Fig. ,labelsep=newline, parskip=1.5cm}
\captionsetup[table]{labelsep=newline,font=normalsize,textfont=it, labelfont={bf}, parskip=2ex,justification=raggedright, singlelinecheck=false}

\begin{document}
\section{An table}

\begin{table}[ht]
\centering
\begin{threeparttable}
\caption{Cronbach alpha}
\label{tb:fiabilidad}
\begin{tabular}{lcc}\toprule
    \bfseries Scale & \bfseries Ítems &  $\pmb{\alpha}$\; \bfseries Cronbach \\ \midrule
    RPA &  20 & 0.8531 \\
    PCP* & 17 & 0.7645 \\ \bottomrule
    \multicolumn{3}{l}{\textbf{*}Items 11, 15 and 16 . } \\
\end{tabular}
\end{threeparttable}
\end{table}

\section{Another table}
\begin{longtable}[c]{lcc}
    \caption[Alpha Cronbach's]{Cronbach Alpha} \\ \toprule
\bfseries Scale &\bfseries Ítems & $\pmb{\alpha}$\; \bfseries Cronbach \\ \midrule \endfirsthead
\caption[]{(Continue)} \\ \toprule
\bfseries Variable &\bfseries N &\bfseries Frecuencia \\ \midrule \endhead \bottomrule
\endfoot \endlastfoot
Cronbach \\ \midrule
    RPA &  20 & 0.8531 \\
    PCP* & 17 & 0.7645 \\ \bottomrule
    \multicolumn{3}{l}{\textbf{*}Items 11, 15 and 16 . } \\
\end{longtable}
\end{document}

目标标题对齐宽度

答案1

以下是如何使用 floatrow\ttabbox可以使用可选参数来控制标题宽度。默认情况下,它设置为\FBwidth,但您可以选择该值的倍数。

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[left=3cm,top=2.5cm,bottom=2.5cm, right=2.5cm,headheight=1cm,showframe=false]{geometry}
\usepackage{bookmark, amsmath}
\usepackage{multicol,multirow,booktabs, array}
\usepackage{threeparttable, longtable}
\usepackage{floatrow}
\floatsetup[longtable]{LTcapwidth=table}
\floatsetup[table]{position=top}
\usepackage[labelfont=bf,justification=raggedright,singlelinecheck=false]{caption}

\DeclareCaptionLabelSeparator*{spaced}{\\[2ex]}
\captionsetup[figure]{name=Fig. , labelsep=newline, parskip=1.5cm}
\captionsetup[table]{labelsep=newline,font=normalsize,textfont=it, labelfont={bf}, parskip=2ex,justification=raggedright, singlelinecheck=false}

\begin{document}

\begin{table}
\centering
    \ttabbox{\caption[Alpha Cronbach's]{Some rather long caption, with a nice lengthy addendum. }}
{\begin{tabular}{lcc}
    \toprule
\bfseries Scale &\bfseries Ítems & $\pmb{\alpha}$\; \bfseries Cronbach \\ \midrule
Cronbach \\ \midrule
    RPA & 20 & 0.8531 \\
    PCP* & 17 & 0.7645 \\ \bottomrule\addlinespace
    \multicolumn{3}{l}{\textbf{*}Items 11, 15 and 16 . }
\end{tabular}}
\end{table}

\end{document} 

在此处输入图片描述

答案2

我不知道我是否理解了你的问题。试试这个代码:

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[left=3cm,top=2.5cm,bottom=2.5cm, right=2.5cm,headheight=1cm,showframe=false]{geometry}
\usepackage{bookmark, amsmath}
\usepackage{multicol,multirow,booktabs, array}
\usepackage{threeparttable, longtable}
\usepackage{floatrow}
\floatsetup[longtable]{LTcapwidth=table}
\floatsetup[table]{position=top}
\usepackage[labelfont=bf,justification=raggedright,singlelinecheck=false]{caption}

\DeclareCaptionLabelSeparator*{spaced}{\\[2ex]}
\captionsetup[figure]{name=Fig. ,labelsep=newline, parskip=1.5cm}
\captionsetup[table]{labelsep=newline,font=normalsize,textfont=it, labelfont={bf}, parskip=2ex,justification=raggedright, singlelinecheck=false}

\begin{document}
    \section{A table}
    \begin{longtable}[c]{lcc}
            \caption[Alpha Cronbach's]{Cronbach Alpha} \\ 
            \begin{tabular}{lcc}\toprule
                \bfseries Scale & \bfseries Ítems &  $\pmb{\alpha}$\; \bfseries Cronbach \\ \midrule
                RPA &  20 & 0.8531 \\
                PCP* & 17 & 0.7645 \\ \bottomrule
                \multicolumn{3}{l}{\textbf{*}Items 11, 15 and 16 . } \\
            \end{tabular}
            \label{tb:fiabilidad}
    \end{longtable}
    
    \section{Another table}
    \begin{longtable}[c]{lcc}
        \caption[Alpha Cronbach's]{Cronbach Alpha} \\ \toprule
        \bfseries Scale &\bfseries Ítems & $\pmb{\alpha}$\; \bfseries Cronbach \\ \midrule \endfirsthead
        \caption[]{(Continue)} \\ \toprule
        \bfseries Variable &\bfseries N &\bfseries Frecuencia \\ \midrule \endhead \bottomrule
        \endfoot \endlastfoot
        Cronbach \\ \midrule
        RPA &  20 & 0.8531 \\
        PCP* & 17 & 0.7645 \\ \bottomrule
        \multicolumn{3}{l}{\textbf{*}Items 11, 15 and 16 . } \\
    \end{longtable}
\end{document}

输出:

在此处输入图片描述

相关内容