0

I am getting quite frustrated trying to center a three-part table

\documentclass{article}
\usepackage[flushleft]{threeparttable}
\usepackage{booktabs,xcolor,siunitx}
\definecolor{lightgray}{gray}{0.9}
\begin{document}

\begin{table}[!ht]
\caption[Table]{Text\tnote{a}.}\label{table1}
\begin{threeparttable}
    \begingroup\setlength{\fboxsep}{0pt}
    \colorbox{lightgray}{% for grey shade
        \begin{tabular}{l l l}
            \hline \hline
            \vspace{-0,2cm}&&\\
            \textbf{1st Column} & \textbf{2nd Column} & \textbf{3rd Column} \\ \midrule
            test\tnote{\textdagger}   &                     &                      \\
            \bottomrule
        \end{tabular}
    }\endgroup % for grey shade
    \begin{tablenotes}
        \item[\textdagger] test
    \end{tablenotes}
\end{threeparttable}    
\end{table}

\end{document}

I tried several times putting it in a center-environment, tried out several times with \centering, but nothing worked. Apparently, the problem is with

\begingroup\setlength{\fboxsep}{0pt}

Has anyone a solution? I would greatly appreciate any help.

The table looks like: enter image description here

  • If you want your table to be horizontally centered why do you use threeparttable's option flushleft? – leandriis Mar 17 '18 at 10:59
  • I must have overlooked the flushleft option, thanks! If I then put the center environment before the threepart table, it works! However, the table notes are then out of place... – elio rico Mar 17 '18 at 11:38
  • 1
    Welcome to TeX SX! Your use of the flushleft option was correct: it is the tables notes only which are flushleft. It seems there is an incompatibility of this option with the use of \colorbox – Bernard Mar 17 '18 at 12:37
  • Dear Bernard, thanks for your comment, as well as your solution posted below which works perfectly, I thank you a lot!! – elio rico Mar 18 '18 at 13:28
0

Here is a work-around:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage[flushleft]{threeparttablex}%
\usepackage{booktabs,longtable, caption, cellspace, hhline}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\definecolor{lightgray}{gray}{0.9}

\begin{document}

\begin{table}[!ht]
\centering\captionsetup{skip = 4pt}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\setlength{\cellspacetoplimit}{5pt}
\setlength{\cellspacebottomlimit}{5pt}
\begin{threeparttable}
\caption[Table]{Text\tnote{a}.}\label{table1}
\rowcolors{1}{lightgray}{lightgray}
 \begin{tabular}{Cl l l}
            \toprule\arrayrulecolor{lightgray}\midrule[0.5ex]\arrayrulecolor{black} \midrule
            \textbf{1st Column} & \textbf{2nd Column} & \textbf{3rd Column} \\ \midrule
            test\tnote{\textdagger} & & \\
            \bottomrule
        \end{tabular}
    \begin{tablenotes}
        \item[\textdagger] test
    \end{tablenotes}
\end{threeparttable}
\end{table}

\end{document} 

enter image description here

0

This is a work-around; put the colorbox inside an extra tabular.

\documentclass{article}
\usepackage[flushleft]{threeparttable}
\usepackage{booktabs,xcolor,siunitx}
\definecolor{lightgray}{gray}{0.9}
\begin{document}

\begin{table}[!ht]\centering
\caption[Table]{Text\tnote{a}.}\label{table1}
\begin{threeparttable}\begin{tabular}{@{}c@{}}%
    \begingroup\setlength{\fboxsep}{0pt}%    <-----
    \colorbox{lightgray}{% for grey shade
        \begin{tabular}{l l l}
            \hline \hline
            \vspace{-0,2cm}&&\\
            \textbf{1st Column} & \textbf{2nd Column} & \textbf{3rd Column} \\ \midrule
            test\tnote{\textdagger}   &                     &                      \\
            \bottomrule
        \end{tabular}%
    }\endgroup % for grey shade
    \end{tabular}                       %    <-----
    \begin{tablenotes}
        \item[\textdagger] test
    \end{tablenotes}
\end{threeparttable}    
\end{table}

\end{document}

enter image description here

  • Thanks a lot for your contribution, your solution actually works perfectly fine !! Really appreciate your help – elio rico Mar 18 '18 at 13:29
0

Here is another work-around using a parbox to enclose the tablenotes environment.

\documentclass{article}
\usepackage{threeparttable}
\usepackage{booktabs,xcolor,siunitx}
\definecolor{lightgray}{gray}{0.9}
\begin{document}

\begin{table}[!ht]
\centering
\caption[Table]{Text\tnote{a}.}\label{table1}
\begin{threeparttable}
    \begingroup\setlength{\fboxsep}{0pt}
    \colorbox{lightgray}{% for grey shade
        \begin{tabular}{l l l}
            \hline \hline
            \vspace{-0,2cm}&&\\
            \textbf{1st Column} & \textbf{2nd Column} & \textbf{3rd Column} \\ \midrule
            test\tnote{\textdagger}   &                     &                      \\
            \bottomrule
        \end{tabular}
    }\endgroup % for grey shade

    \parbox{\linewidth}{
    \begin{tablenotes}[flushleft]
     \item[\textdagger] test
    \end{tablenotes}}
\end{threeparttable}    
\end{table}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.