这个问题是自动将浮动标题的第一句加粗longtable
。我可以自动将普通表格中的标题第一句加粗,但使用(与一起使用)时代码似乎不起作用threeparttablex
。显然,我希望所有表格看起来都一样,无论它们的构造方法如何。有人有解决方案吗?
\documentclass[a4paper,12pt]{scrreprt}
\usepackage[greek, english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage[labelfont=bf, font=small ]{caption}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage{longtable}
\usepackage{adjustbox}
\usepackage{xstring}
\usepackage{etoolbox}
\usepackage[a4paper, bindingoffset=0.5cm, tmargin=2.4cm, bmargin=3.4cm, lmargin=3.5cm, rmargin=2.5cm, footskip=2.4cm]{geometry}
% ---------------------------------------------------------------------------------------------------------------------
% Make first sentence of figure and table captions bold
\makeatletter
\newcommand\formatlabel[1]{%
\noexpandarg
\IfSubStr{#1}{.}{%
\StrBefore{#1}{.}[\firstcaption]%
\StrBehind{#1}{.}[\secondcaption]%
\textbf{\firstcaption.} \secondcaption}{%
#1}%
}
\patchcmd{\@caption}{#3}{\formatlabel{#3}}
\makeatother
% ---------------------------------------------------------------------------------------------------------------------
\AtBeginEnvironment{longtable}{\small}
\begin{document}
\begin{table}
\centering
\caption[Table 1]{The first table. Note that the first sentence is in \textbf{bold}.}
\label{tab:Table1}
\begin{adjustbox}{max width=\textwidth}
\begin{threeparttable}
\begin{tabular}{*8{c}}
\toprule
A & B & C & D & E & F & G & H \\
\midrule
Item 1\tnote{a} & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 2 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 3 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
\item[a] Item 1 is only available from June to August..
\end{tablenotes}
\end{threeparttable}
\end{adjustbox}
\end{table}
\begin{ThreePartTable}
\begin{TableNotes}
\small
\item[a] Item 1 is only available from June to August.
\end{TableNotes}
\begin{longtable}{*8{c}}
\caption[Table 2]{The second table. Note that the first sentence is \textbf{not} in bold.}
\label{tab:Table2} \\
\toprule
A & B & C & D & E & F & G & H \\
\midrule
\endfirsthead
\caption[Table 2]{The second table (continued).} \\
\toprule
A & B & C & D & E & F & G & H \\
\midrule
\endhead
\midrule
\multicolumn{8}{r}{\textit{Continued \ldots}}
\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
Item 1\tnote{a} & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 2 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 3 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 4 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 5 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 6 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 7 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 8 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 9 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
\end{longtable}
\end{ThreePartTable}
\end{document}
答案1
也许您应该能够使用 caption 包钩子,但既然您正在修补,\@caption
那么也可以修补 LT 版本:
\documentclass[a4paper,12pt]{scrreprt}
\usepackage[greek, english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage[labelfont=bf, font=small ]{caption}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage{longtable}
\usepackage{adjustbox}
\usepackage{xstring}
\usepackage{etoolbox}
\usepackage[a4paper, bindingoffset=0.5cm, tmargin=2.4cm, bmargin=3.4cm, lmargin=3.5cm, rmargin=2.5cm, footskip=2.4cm]{geometry}
% ---------------------------------------------------------------------------------------------------------------------
% Make first sentence of figure and table captions bold
\makeatletter
\newcommand\formatlabel[1]{%
\noexpandarg
\IfSubStr{#1}{.}{%
\StrBefore{#1}{.}[\firstcaption]%
\StrBehind{#1}{.}[\secondcaption]%
\textbf{\firstcaption.} \secondcaption}{%
#1}%
}
\patchcmd{\@caption}{#3}{\formatlabel{#3}}{}{}
\AtBeginDocument{\long\def\LT@c@ption#1[#2]#3{%
\LT@makecaption#1{\csname fnum@\LTcaptype\endcsname}{\formatlabel{#3}}%
\LT@captionlistentry {#2}}}
\makeatother
% ---------------------------------------------------------------------------------------------------------------------
\AtBeginEnvironment{longtable}{\small}
\begin{document}
\begin{table}
\centering
\caption[Table 1]{The first table. Note that the first sentence is in \textbf{bold}.}
\label{tab:Table1}
\begin{adjustbox}{max width=\textwidth}
\begin{threeparttable}
\begin{tabular}{*8{c}}
\toprule
A & B & C & D & E & F & G & H \\
\midrule
Item 1\tnote{a} & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 2 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 3 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
\item[a] Item 1 is only available from June to August..
\end{tablenotes}
\end{threeparttable}
\end{adjustbox}
\end{table}
\begin{ThreePartTable}
\begin{TableNotes}
\small
\item[a] Item 1 is only available from June to August.
\end{TableNotes}
\begin{longtable}{*8{c}}
\caption[Table 2]{The second table. Note that the first sentence is \textbf{not} in bold.}
\label{tab:Table2} \\
\toprule
A & B & C & D & E & F & G & H \\
\midrule
\endfirsthead
\caption[Table 2]{The second table (continued).} \\
\toprule
A & B & C & D & E & F & G & H \\
\midrule
\endhead
\midrule
\multicolumn{8}{r}{\textit{Continued \ldots}}
\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
Item 1\tnote{a} & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 2 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 3 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 4 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 5 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 6 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 7 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 8 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
Item 9 & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX & XXXX \\
\end{longtable}
\end{ThreePartTable}
\end{document}