表格标题:将“表格”标签置于标题上方

表格标题:将“表格”标签置于标题上方

我需要一种符合 IEEE 标准的字幕表方法,如下所示:

在此处输入图片描述

具体来说,“TABLE I”必须位于标题本身上方。

需要说明的是,我知道\documentclass{ieeetran}这将为我提供我想要的表格标题,但这还附带了一大堆其他格式,对于我的目的来说这些格式我既不想要也不需要。

以下是我的 MWE:

\documentclass[12pt]{report}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{float}
\renewcommand*\thetable{\Roman{table}}
\renewcommand*{\tablename}{TABLE}
\usepackage{cleveref}

\begin{document}

\noindent \Cref{tab:table} demonstrates my current table-captioning method.

\begin{table}[H]
    \centering
    \caption[Alphanumeric Data]{ALPHANUMERIC DATA}
    \vspace{0.2cm}
    \begin{tabularx}{\textwidth}{X X X X}
        \toprule
         & \bf x & \bf y & \bf z \\
        \midrule
        \bf A & 1 & 2 & 3 \\
        \bf B & 4 & 5 & 6 \\
        \bf C & 7 & 8 & 9 \\
        \bottomrule
    \end{tabularx}
    \label{tab:table}
\end{table}

\end{document}

在此处输入图片描述

我如何将“TABLE I”放在标题上方并删除冒号以获得第一张图片中显示的输出?

提前致谢。

答案1

caption优惠labelsep = newline,以及其他可能提供您所需内容的选项:

在此处输入图片描述

\documentclass{report}

\usepackage{caption}
\usepackage{cleveref}

\renewcommand*\thetable{\Roman{table}}

\captionsetup[table]{
  labelsep = newline, % Label and caption on separate line
  font = sc % Small caps font for caption
}  

\begin{document}

\noindent \Cref{tab:table} demonstrates my current table-captioning method.

\begin{table}
  \centering
  \caption{A table}
  \label{tab:table}
  \begin{tabular}{ *{3}{c} }
    \hline
    A & B & C \\
    \hline
  \end{tabular}
\end{table}

\end{document}

答案2

注意!我已将不支持的\bf命令替换为\bfseries。由于第一列为粗体,我使用 -command>{\bfseries}一次性将该列中的文本变为粗体。

标题的布局可以很容易地使用来自的文档类进行存档KOMA 脚本包。此外,我建议通过重新定义 KOMA-script-command 来将表格标签改为大写,而不是硬编码单词 TABLE。如果您使用英语以外的其他语言,您的解决方案将失效。为了演示灵活的 KOMA-script-command,我更改了标题中的字体。如果您无法使用 KOMA-script 的文档类之一,您可以加载包scrextend,它为您提供了许多 KOMA-script 的灵活命令。KOMA-script 有几个命令,使您可以全局和本地格式化标题。编写非浮动表格环境也很容易。

在此处输入图片描述

\documentclass[captions=tableheading, fontsize=12pt, captions=nooneline]{scrreprt}
\usepackage{tabularx, cleveref}
\usepackage{booktabs, scrhack, ragged2e}

\renewcommand*\thetable{\Roman{table}}
\usepackage{cleveref}

\renewcommand*{\tableformat}{\MakeUppercase{\tablename~\thetable\autodot}} % Instead of hard coding TABLE
\addtokomafont{caption}{\small\sffamily}
\addtokomafont{captionlabel}{\small\sffamily}
\setcaptionalignment[table]{C}
\renewcommand*{\captionformat}{}
\setcapindent*{0pt}

\begin{document}

\noindent \Cref{tab:table} demonstrates my current table-captioning method. As you will see,  \cref{tab:table} is a floating table, since it has floated above the referring text.

\Cref{tab:table-ii} demonstrates how to typeset a none-floating table in KOMA-script. As you will see, \cref{tab:table-ii} is not floating, because it is appear where I have written the table inside text. A `minipage` environment should be used to avoid page breaks between the caption and the table. In addition, you should embed the `minipage` environment in a `flushleft` environment both to achieve a pleasing separation between the surrounding text, and to avoid that the `minipage` environment is indented by the paragraph indentation (you may also use the `center` environment.

\begin{table}
    \caption[Alphanumeric Data]{ALPHANUMERIC DATA\label{tab:table}}
    \begin{tabularx}{\textwidth}{@{}>{\bfseries}X X X X@{}}
        \toprule
         &  \bfseries x & \bfseries y & \bfseries z \\
        \midrule
        A & 1 & 2 & 3 \\
        B & 4 & 5 & 6 \\
        C & 7 & 8 & 9 \\
        \bottomrule
    \end{tabularx}
\end{table}


\begin{flushleft}
\begin{minipage}{\linewidth}
\captionaboveof{table}[More Alphanumeric Data]{MORE ALPHANUMERIC DATA\label{tab:table-ii}}
\begin{tabularx}{\textwidth}{@{}>{\bfseries}X X X X@{}}
        \toprule
         &  \bfseries x & \bfseries y & \bfseries z \\
        \midrule
        A & 1 & 2 & 3 \\
        B & 4 & 5 & 6 \\
        C & 7 & 8 & 9 \\
       \bottomrule
\end{tabularx}
\end{minipage}
\end{flushleft}
\end{document}

相关内容