6

I have a table that is wider than \textwidth. The table also has footnotes, see the following picture:

example_pic

I put the table in a threeparttable environment, and try to use \makebox command mentioned in this question to center the table horizontally. However, it does not work. Moreover, there is no space between the superscript a and (K$) in the second row. How can I solve this problem?

The following is my MWE:

\documentclass[a4paper, 10pt]{article}

\usepackage{booktabs}
\usepackage{caption}
\usepackage[flushleft]{threeparttable}
\captionsetup{labelsep=period, skip=5pt}

\begin{document}

\begin{table}[h]
\centering
\begin{threeparttable}

\caption{Optimal results of Example 2}
\label{tab: results2}
\begin{tabular}{lccccccccc}
\toprule
Item & ref. 1 & ref. 2 & ref. 3 & ref. 4 & ref. 5 & ref. 6 & ref. 7 & ref. 8 & Our method\\
\midrule
Utility (kW) & 2000 & 3800 & 4200  & & & & & & \\
Capital cost\tnote{a} (k\$) & 163.27 & & & & & & & & \\
Total annual cost (k\$) & 2268.59 & & & & - & & & & \\
\bottomrule 
\end{tabular}   
\begin{tablenotes}                  
\vspace*{-2pt}
\item[a]  {\footnotesize Based on the cost parameters from ref. 6.} 
\vspace*{-2pt}
\item[-]  {\footnotesize Not reported in literature.}   
\end{tablenotes}                
\end{threeparttable}
\end{table}

\end{document}
5

When reducing the font size to make a wide table "fit" inside the width of the text block, LaTeX doesn't shrink the amount of intercolumn whitspace proportionally. To salvage any chances of having a readable table, it's important to shrink the amount of intercolumn whitespace as well.

I suggest you (i) reorganize the table's header to collect the repeated "Ref." and (ii) use a tabular* environment instead of the basic tabular environment. With these two changes made, it's still necessary to use \scriptsize, for a 30% linear reduction of the main font size.

The first horizontal line in the screenshot is there to illustrate the width of the textblock.

enter image description here

\documentclass[a4paper, 10pt]{article}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup{labelsep=period, skip=5pt}
\usepackage[flushleft]{threeparttable}

\begin{document}
\hrule  % just to illustrate width of textblock

\begin{table}[h]
\scriptsize
\setlength\tabcolsep{0pt} % let LaTeX determine whitespace between columns
\begin{threeparttable}

\caption{Optimal results of Example 2}
\label{tab:results2}
\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}*{9}{c}}
\toprule
Item & \multicolumn{8}{c}{Ref.} & Our method\\
\cmidrule{2-9}
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\midrule
Utility (kW) & 2000 & 3800.00 & 4200.00  & 4200.00 & 4200.00 & 4200.00& 4200.00 & 4200.00 & 5000.00\\
Capital cost\tnote{a} (k\$) & 163.27 & & & & & & & & \\
Total annual cost (k\$) & 2268.59 & & & & -- & & & & \\
\bottomrule 
\end{tabular*}  

\begin{tablenotes} 
\scriptsize               
\item[a]  Based on the cost parameters from ref.~6. 
\item[--]  Not reported in literature.
\end{tablenotes}

\end{threeparttable}
\end{table}
\end{document}

If you're willing to allow line breaks in the first column, it's possible to use \footnotesize (for a 20% reduction in font size) instead of \scriptsize. If you choose this method, you could use a tabularx environment (instead of the tabular* environment used above) to simplify getting optimal line breaks in column 1. I would also suggest you contemplate aligning the numeric data in columns 2 thru 10 on their respective decimal markers, in order to improved the table's readability. I would also replace the slightly comical-looking k\$ with 10^\textsuperscript{3} \$.

enter image description here

\documentclass[a4paper, 10pt]{article}
\usepackage{booktabs,tabularx,ragged2e,dcolumn}
\newcolumntype{Y}{>{\RaggedRight}X}
\newcolumntype{d}[1]{D..{#1}}
\usepackage{caption}
\captionsetup{labelsep=period, skip=5pt}
\usepackage[flushleft]{threeparttable}
\newcommand\mc[1]{\multicolumn{1}{@{}c@{}}{#1}} % handy shortcut macro
\begin{document}
\hrule  % just to illustrate width of textblock

\begin{table}[h]
\footnotesize
\setlength\tabcolsep{1.5pt} % let LaTeX determine whitespace between columns
\begin{threeparttable}

\caption{Optimal results of Example 2}
\label{tab:results2}
\begin{tabularx}{\textwidth}{@{}Y*{9}{d{4.2}}@{}}
\toprule
Item & \multicolumn{8}{c}{Ref.} & \mc{Our method}\\
\cmidrule(lr){2-9}
& \mc{1} & \mc{2} & \mc{3} & \mc{4} & \mc{5} & \mc{6} & \mc{7} & \mc{8}\\
\midrule
Utility (kW) & 2000 & 3800.00 & 4200.00  & 4200.00 & 4200.00 & 4200.00& 4200.00 & 4200.00 & 5000.00\\
Capital cost\tnote{a} (10\textsuperscript{3}\,\$) 
& 163.27 & & & & & & & & \\
Total annual cost (10\textsuperscript{3}\,\$) 
& 2268.59 & & & & \mc{--} & & & & \\
\bottomrule 
\end{tabularx}  

\begin{tablenotes}              
\item[a]   Based on the cost parameters from ref.~6. 
\item[--]  Not reported in literature.
\end{tablenotes}

\end{threeparttable}
\end{table}
\end{document}
3

It seems \tnote relies on an internal \TPToverlap macro that makes it swallow the leading space. Redefining it not to use it works.

\renewcommand{\tnote}[1]{\textsuperscript{\TPTtagStyle{#1}}}

(I'm keeping the original behavior for styling the note marks with TPTtagStyle from the package definition.)

Centering doesn't work because the table doesn't fit the textarea. You can adjust it with the adjustbox package mentioned in the answer you linked:

\begin{adjustbox}{max width=\textwidth}
  \begin{threeparttable}
    ...                
  \end{threeparttable}
\end{adjustbox}

MWE:

\documentclass[a4paper, 10pt]{article}

\usepackage{booktabs}
\usepackage{caption}
\usepackage[flushleft]{threeparttable}
\captionsetup{labelsep=period, skip=5pt}

\pagestyle{empty}

% Add space after \tnote
\renewcommand{\tnote}[1]{\textsuperscript{\TPTtagStyle{#1}}}

% Use adjustbox to adjust the threeparttable env to textwidth
\usepackage{adjustbox}

\begin{document}

\listoftables

\begin{table}[h]
\begin{adjustbox}{max width=\textwidth}
  \begin{threeparttable}

  \caption{Optimal results of Example 2}
  \label{tab: results2}
  \begin{tabular}{lccccccccc}
  \toprule
  Item & ref. 1 & ref. 2 & ref. 3 & ref. 4 & ref. 5 & ref. 6 & ref. 7 & ref. 8 & Our method\\
  \midrule
  Utility (kW) & 2000 & 3800 & 4200  & & & & & & \\
  Capital cost\tnote{a} (k\$) & 163.27 & & & & & & & & \\
  Total annual cost (k\$) & 2268.59 & & & & - & & & & \\
  \bottomrule 
  \end{tabular}   
  \begin{tablenotes}                  
  \vspace*{-2pt}
  \item[a]  {\footnotesize Based on the cost parameters from ref. 6.} 
  \vspace*{-2pt}
  \item[-]  {\footnotesize Not reported in literature.}   
  \end{tablenotes}                
  \end{threeparttable}
\end{adjustbox}
\end{table}

\end{document}

adjusted large threeparttable

  • It works. But why does the fonts in the table become smaller? I did not see any command that changes the font size in the table. Thanks. – Nick Aug 11 '15 at 3:29
  • To henrique: I do not want to change the the table size, but want to center the table horizontally. – Nick Aug 11 '15 at 3:37
  • Just insert command: \begin{adjustbox}{center, max width=\1.5textwidth} \begin{threeparttable} ... \end{threeparttable} and the problem is solved. \end{adjustbox} – Nick Aug 11 '15 at 3:46
  • @Nick, sorry for taking so long to answer. I used adjustbox because the table was too wide to fit a page, that's why the fonts got smaller --- and i took that from the answer you linked. Anyway, Mico's answer is much more complete. – henrique Aug 18 '15 at 19:25

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.