# Table Formatting with and without threeparttable

I have been trying to generate the attached table in LaTeX. I have done it in two ways and I have query for both. The first way I have not used the threeparttable package and in the second way I have used it. This is because while searching for help adding notes under the table, I came to know about threeparttable and this was almost when I was about to finish the first way.

First I have a general question that how shall I format the text in first column which is not aligned to the left? I mean the text including the following items, (Petroleum, bituminous coal; brown coal etc). I guess there must be a better way of doing this as compared to the way I have done here in both the codes. I used \ to include space until that text is in the position where I want it to be.

In the first code I cant write the second table note in a new line as shown in the original table. Any suggestion for it?

In the second code, I cant draw the \hline after the second table note and above the last line of "Source: Energy Balance....." Any suggestion for it?

Here is the code one:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array, multirow}
\usepackage{caption,tabularx,booktabs}

\begin{document}

\begin{table}{\bfseries Primary Energy Consumption}\\[0.1ex]
\setlength{\extrarowheight}{1pt}
\begin{tabular*}{118 mm}{p{40mm}@{\hspace{30mm}} llrr @{}}

\hline
Energy Source &1975 &1980 &1986\\[-0.1ex]
\hline

Total Consumption\\
(in million tons of BCU$^{a}$) of which (percentages) \parbox[t]{15mm} &347.7 &390.2 &285.0\\
\ \ \ \ \ \ \ \ \ \ \ \ \   petroleum &52.1 &47.6 &43.2\\
\ \ \ \ \ \ \ \ \ \ \ \ \   bituminous coal &19.1 &19.8 &20.0 \\
\ \ \ \ \ \ \ \ \ \ \ \ \   brown coal &9.9 &10.0 &8.6 \\
\ \ \ \ \ \ \ \ \ \ \ \ \   natural gas &14.2 &16.5 &15.1 \\
\ \ \ \ \ \ \ \ \ \ \ \ \   nuclear energy &2.0 &3.7 &10.1 \\
\ \ \ \ \ \ \ \ \ \ \ \ \   other$^{b}$ &2.7 &2.4 &3.0 \\ \cline{1-1}

\multicolumn{4}{p{.9\textwidth}}{$^{a}$BCU = Bituminous Coal Unit (1 ton BCU corresponds to the heating equivalent of 1 ton of bituminous coal = 8140 kwh) $^{b}$Wind, water, solar energy, etc.}
\\
\hline

\end{tabular*}\\[0.1ex]

\emph{Source:} Energy Balance Study Group, Essen 1987.

\end{table}

\end{document}


Here is the second code;

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array, multirow}
\usepackage{caption,booktabs}
\usepackage[flushleft]{threeparttable}

\begin{document}

\begin{table}
\begin{threeparttable}
\caption{Primary Energy Consumption}

\begin{tabular*}{118 mm}{p{40mm}@{\hspace{30mm}} llrr @{}}
\toprule

Energy Source &1975 &1980 &1986\\[-0.1ex]

\midrule

Total Consumption\\
(in million tons of BCU$^{a}$) of which (percentages) \parbox[t]{15mm} &347.7 &390.2 &285.0\\
\ \ \ \ \ \ \ \ \ \ \ \ \   petroleum &52.1 &47.6 &43.2\\
\ \ \ \ \ \ \ \ \ \ \ \ \   bituminous coal &19.1 &19.8 &20.0 \\
\ \ \ \ \ \ \ \ \ \ \ \ \   brown coal &9.9 &10.0 &8.6 \\
\ \ \ \ \ \ \ \ \ \ \ \ \   natural gas &14.2 &16.5 &15.1 \\
\ \ \ \ \ \ \ \ \ \ \ \ \   nuclear energy &2.0 &3.7 &10.1 \\
\ \ \ \ \ \ \ \ \ \ \ \ \   other$^{b}$ &2.7 &2.4 &3.0 \\
\bottomrule

\end{tabular*} %\\[0.1ex]

\begin{tablenotes}

\small
\item $^{a}$BCU = Bituminous Coal Unit (1 ton BCU corresponds to the heating equivalent of 1 ton of bituminous coal = 8140 kwh

\item $^{b}$Wind, water, solar energy, etc.
\end{tablenotes}

\emph{Source:} Energy Balance Study Group, Essen 1987.

\end{threeparttable}

\end{table}
\end{document}


I would do it like this:

% arara: pdflatex

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{caption,booktabs}
\usepackage[flushleft]{threeparttable}
\usepackage{siunitx}

\begin{document}
\begin{table}
\centering
\begin{threeparttable}
\caption[Primary Energy Consumption]{Primary Energy Consumption (\emph{Source:} Energy Balance Study Group, Essen 1987.)}
\begin{tabular}{p{1.5cm}l*{3}{S[table-format=3.1]}} % adapt the tabbing width with the p column!
\toprule
\multicolumn{2}{l}{Energy Source} & {1975} & {1980} & {1986} \\
\midrule
\multicolumn{2}{l}{Total Consumption} & & & \\
\multicolumn{2}{l}{(in million tons of BCU\tnote{a}~)} & 347.7 & 390.2 & 285.0 \\
\multicolumn{2}{l}{of which (percentages)} & & & \\
& petroleum       & 52.1 & 47.6 & 43.2 \\
& bituminous coal & 19.1 & 19.8 & 20.0 \\
& brown coal      & 9.9  & 10.0 & 8.6  \\
& natural gas     & 14.2 & 16.5 & 15.1 \\
& nuclear energy  & 2.0  & 3.7  & 10.1 \\
& other\tnote{b}  & 2.7  & 2.4  & 3.0  \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
\item[a] BCU = Bituminous Coal Unit (\SI{1}{\tonne} BCU corresponds to the heating equivalent of \SI{1}{\tonne} of bituminous coal $= \SI{8140}{\kilo\watt\hour}$
\item[b] Wind, water, solar energy, etc.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}


I hope the code is self-explaining.

Edit: Or if you want to have the "(percentages)" aligned to the rows below (thanks to Enrico):

\begin{table}
\centering
\begin{threeparttable}
\caption[Primary Energy Consumption]{Primary Energy Consumption (\emph{Source:} Energy Balance Study Group, Essen 1987.)}
\begin{tabular}{l@{\hspace{.4cm}}l*{3}{S[table-format=3.1]}} % adapt the tabbing width with the \hspace
\toprule
\multicolumn{2}{l}{Energy Source} & {1975} & {1980} & {1986} \\
\midrule
\multicolumn{2}{l}{Total Consumption} & & & \\
\multicolumn{2}{l}{(in million tons of BCU\tnote{a}~)} & 347.7 & 390.2 & 285.0 \\
of which & (percentages) & & & \\
& petroleum       & 52.1 & 47.6 & 43.2 \\
& bituminous coal & 19.1 & 19.8 & 20.0 \\
& brown coal      & 9.9  & 10.0 & 8.6  \\
& natural gas     & 14.2 & 16.5 & 15.1 \\
& nuclear energy  & 2.0  & 3.7  & 10.1 \\
& other\tnote{b}  & 2.7  & 2.4  & 3.0  \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
\item[a] BCU = Bituminous Coal Unit (\SI{1}{\tonne} BCU corresponds to the heating equivalent of \SI{1}{\tonne} of bituminous coal $= \SI{8140}{\kilo\watt\hour}$
\item[b] Wind, water, solar energy, etc.
\end{tablenotes}
\end{threeparttable}
\end{table}

• Maybe the first two columns could be specified as l@{ }l and the third row can start with of which & (percentages), so as to get the same alignment as in the OP's image (with better spacing). – egreg Aug 19 '15 at 16:11
• @LariFaRi Thanks. I was not aware of siunitx package but you have introduced it to me. Many Many thanks for the help – Jack Aug 19 '15 at 16:44