1

I use threeparttable to format my tables. I also use brackets for footnote references. As you can see in the following picture, the 2nd line of footnote [a] is not aligned. The line starting with 0.0 is starting to far left.

enter image description here

How can I correct this?

Best regards, wewa00

PS: Here is the sample LaTeX code to reproduce this issue.

% 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}
5
  • Do you want the first word of the second line to align with "[a]" or with "Loremips"?
    – leandriis
    Jan 27, 2021 at 19:22
  • 1
    For the former, use flushleft (either globally as a package option of locally as an option for the tablenotes environment. For the latter, you could try \def\TPTnoteSettings{\setlength\labelwidth{1em}}.
    – leandriis
    Jan 27, 2021 at 19:31
  • @leandriis I would like to align the 2nd line with "Loremips"
    – wewa
    Jan 27, 2021 at 20:41
  • @leandriis \def\TPTnoteSettings{\setlength\labelwidth{1em}} is working as desired. Could you please write an answer?
    – wewa
    Jan 27, 2021 at 20:47
  • 1
    Running \def\TPTnoteSettings{\setlength\labelwidth{1em}} does a lot more to the appearance of the table notes than just affect the indentation amount. Unless you want to clobber the default properties of \TPTnoteSettings, you really ought to run \apptocmd{\TPTnoteSettings}{\setlength\labelwidth{1em}}{}{}.
    – Mico
    Jan 27, 2021 at 20:55

1 Answer 1

1

The following solution achieves your formatting objective. Observe that it's not a good idea to execute \def\TPTnoteSettings{\setlength\labelwidth{1em}}, as doing so clobbers the default setting of the macro. That's why the code below contains the instruction

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

enter image description here

In the code below, I've also cleaned up and simplified your preamble code. By the way, the booktabs package is utterly unrelated to "support centering of table". Instead, it provides macros -- such as \toprule and \bottomrule -- to draw well-spaced horizontal lines. Note also that the \begin{threeparttable} instruction should come before, not after, the \caption statement.

\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}
4
  • Thank you for that answer. I can not really recall where booktabs was advised. I removed it now, and everything works as before so far. Regarding \begin{threeparttable} and \caption: Putting \begin{threeparttable} before \caption does not work for me. This scrambles my formatting. I display an image between the table caption and the table itself. To show you this I would need some time to prepare the sample.
    – wewa
    Jan 28, 2021 at 7:40
  • @wewa - The threeparttable environment has three formal components (hence its name) :a \caption statement, a tabular-like environment, and a tablenotes environment. By not including the \caption statement inside the threeparttable environment, you're not using the package's machinery appropriately. It's not clear what you mean by "scrambles the formatting"; did you maybe fail to place the \centering before the \begin{threeparttable} directive? (Observe that in my answer, \centering comes before \begin{threeparttable} which, in turn, comes before \caption.)
    – Mico
    Jan 28, 2021 at 7:48
  • Here you can see how I use it currently: gist.github.com/wewa00/a657bc6dadbcda51f6e68e4c1fff0246. If \begin{threeparttable} comes before \caption, the image and caption are not aligned centered.
    – wewa
    Jan 28, 2021 at 7:55
  • 1
    I misused the answer feature of StackExchange to illustrate the issue I have here: tex.stackexchange.com/a/580788/231568
    – wewa
    Jan 28, 2021 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .