Threeparttable 对齐包含括号的脚注

Threeparttable 对齐包含括号的脚注

我用threeparttable它来格式化我的表格。我还使用括号来引用脚注。如下图所示,脚注的第二行[a]没有对齐。以 开头的行0.0从最左边开始。

在此处输入图片描述

我该如何纠正这个问题?

谨致问候,wewa00

PS:这是重现此问题的示例 LaTeX 代码。

% Preview source code

%% LyX 2.3.6 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[12pt,english]{article}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=3cm,rmargin=2.5cm}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{array}
\usepackage{setspace}
\onehalfspacing

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
% --------- change figure and table caption size -----------
\usepackage{caption} % to change font size of image caption
\captionsetup[figure]{font=footnotesize,labelfont=footnotesize} % available values are scriptsize, footnotesize, small, normalsize, large, and Large.
\captionsetup[table]{font=footnotesize,labelfont=footnotesize} % available values are scriptsize, footnotesize, small, normalsize, large, and Large.
% -----------------------------------------------
\usepackage{threeparttable}
\usepackage{booktabs} % booktabs: to support centering of table
\usepackage{etoolbox} % to support footnotesize within table
\appto\TPTnoteSettings{\footnotesize} % footnote font size within table
\def\tnote#1{\protect\TPToverlap{\textsuperscript{[\TPTtagStyle{#1}]}}} % brackets in table footnotes

\makeatother

\usepackage{babel}
\begin{document}
\begin{table}
\caption{}

\centering
\begin{threeparttable}

\begin{tabular}{>{\centering}m{1.2cm}>{\centering}m{4cm}>{\centering}m{3cm}>{\centering}m{1.8cm}>{\centering}m{1.9cm}}
\hline 
\noalign{\vskip\doublerulesep}
1 & 2 & 3 & 4 & 5\tabularnewline[\doublerulesep]
\hline 
\noalign{\vskip\doublerulesep}
\end{tabular}

\begin{tablenotes}
\item [a] Loremips umdolor sit ahmet 0.00 lore mipsum, 00 lor\% ipsumlor emi 0.00 lore ipsumlor ip 0.0 lo remipsu mlo 00 l lo remi psumloremip.
\item [b] Loremipsum lor emipsu LORE.
\item [c] Loremipsum dol ORE.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

答案1

以下解决方案可实现您的格式化目标。请注意,执行 不是一个好主意\def\TPTnoteSettings{\setlength\labelwidth{1em}},因为这样做会破坏宏的默认设置。这就是为什么下面的代码包含指令

\apptocmd{\TPTnoteSettings}{\setlength\labelwidth{1em}}{}{}

在此处输入图片描述

在下面的代码中,我还清理并简化了您的前言代码。顺便说一句,该booktabs包与“支持表格居中”完全无关。相反,它提供了宏(例如\toprule\bottomrule)来绘制间距合适的水平线。还请注意,\begin{threeparttable}指令应该位于\caption语句之前,而不是之后。

\documentclass[12pt,english]{article}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % "latin9" -- are you serious ?!
\usepackage[verbose,vmargin=2.5cm,lmargin=3cm,rmargin=2.5cm]{geometry}

\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}

\usepackage{array} % for '\newcolumntype' macro
\newcolumntype{M}[1]{>{\centering}m{#1}}

\usepackage{setspace}
\onehalfspacing

\providecommand\tabularnewline{\\} % just in case it isn't already defined

\usepackage{caption} 
\captionsetup{skip=0.333\baselineskip,
              font=footnotesize % really?
             }
             
\usepackage{booktabs} % booktabs: to support centering of table
    %% No!! 'booktabs' is utterly unrelated to centering a table.
    %% Who on earth gave you this erroneous piece of information?
    
\usepackage{etoolbox} % for '\AtBeginEnvironment' macro and '\apptocmd' macro
\usepackage{threeparttable}
\AtBeginEnvironment{tablenotes}{\footnotesize\smallskip} 
\def\tnote#1{\protect\TPToverlap{\textsuperscript{[\TPTtagStyle{#1}]}}} % cf. https://tex.stackexchange.com/a/578489
\apptocmd{\TPTnoteSettings}{\setlength\labelwidth{1em}}{}{} % <-- new


\begin{document}
\begin{table}
\centering
\begin{threeparttable} % <-- should come _before_ '\caption'
\caption{}

\begin{tabular}{@{} M{1.2cm} M{4cm} M{3cm} M{1.8cm} M{1.9cm} @{}}
\toprule
1\tnote{a} & 2\tnote{b} & 3 & 4 & 5\tnote{c} \tabularnewline 
\bottomrule
\end{tabular}

\begin{tablenotes}
\item[a] Loremips umdolor sit ahmet 0.00 lore mipsum, 00 lor\% ipsumlor emi
         0.00 lore ipsumlor ip Lo lo remipsu mlo 00 l lo remi psumloremip.
\item[b] Loremipsum lor emipsu LORE.
\item[c] Loremipsum dol ORE.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

相关内容