[Tex/LaTex] Change the font size in longtabu table

fontsizelongtable

I was searching here to find a way to change the font size from normal to \footnotesize for the longtabu tables. However, the answer in longtable question didn't work in my case. They made corrections for scriptbook style.

Basically, the question is the same: I want to change the font size of the main text in table without changing the caption size. Here is the example I tried to use what have been suggested: {\footnotesize …
}
But it makes the caption footnotesized.

Here is the MWE:

\documentclass[12pt,oneside]{report} 
\usepackage{tabu}
\usepackage{longtable}
\usepackage{booktabs, multicol, multirow}

\begin{document}
\chapter{Minimum Working Example}
Composition of samples
{\footnotesize
\begin{longtabu} to \linewidth{X[l3.0] X[c] X[c] X[c] X[c] X[c]} 
\caption{Composition of samples} \\ 
\toprule
\textbf{Component} & \textbf{Text1} & \textbf{Text2} & \textbf{Text3} & \textbf{Text4} & \textbf{Text5} \\
\midrule
H$_2$   & 3.94  & 3.81  & 4.03  & 3.88  & 4.01 \\
O$_2$   & 0.38  & 0.10  & 0.30  & 0.91  & 0.99 \\
C$_1$    & 11.98 & 11.30 & 10.98 & 11.94 & 11.09 \\
C$_2$    & 0.44  & 0.39  & 0.43  & 0.91  & 0.33 \\
N$_2$   & 3.94  & 3.81  & 4.03  & 3.88  & 4.01 \\
S$_2$    & 0.81  & 0.81  & 0.81  & 0.11  & 0.83 \\
C$_3$    & 9.19  & 9.01  & 9.10  & 9.84  & 9.18 \\
H$_2$   & 3.94  & 3.81  & 4.03  & 3.88  & 4.01 \\
O$_2$   & 0.38  & 0.10  & 0.30  & 0.91  & 0.99 \\
C$_1$    & 11.98 & 11.30 & 10.98 & 11.94 & 11.09 \\
C$_2$    & 0.44  & 0.39  & 0.43  & 0.91  & 0.33 \\
N$_2$   & 3.94  & 3.81  & 4.03  & 3.88  & 4.01 \\
S$_2$    & 0.81  & 0.81  & 0.81  & 0.11  & 0.83 \\
C$_3$    & 9.19  & 9.01  & 9.10  & 9.84  & 9.18 \\
H$_2$   & 3.94  & 3.81  & 4.03  & 3.88  & 4.01 \\
O$_2$   & 0.38  & 0.10  & 0.30  & 0.91  & 0.99 \\
C$_1$    & 11.98 & 11.30 & 10.98 & 11.94 & 11.09 \\
C$_2$    & 0.44  & 0.39  & 0.43  & 0.91  & 0.33 \\
N$_2$   & 3.94  & 3.81  & 4.03  & 3.88  & 4.01 \\
S$_2$    & 0.81  & 0.81  & 0.81  & 0.11  & 0.83 \\
C$_3$    & 9.19  & 9.01  & 9.10  & 9.84  & 9.18 \\
H$_2$   & 3.94  & 3.81  & 4.03  & 3.88  & 4.01 \\
O$_2$   & 0.38  & 0.10  & 0.30  & 0.91  & 0.99 \\
C$_1$    & 11.98 & 11.30 & 10.98 & 11.94 & 11.09 \\
C$_2$    & 0.44  & 0.39  & 0.43  & 0.91  & 0.33 \\
N$_2$   & 3.94  & 3.81  & 4.03  & 3.88  & 4.01 \\
S$_2$    & 0.81  & 0.81  & 0.81  & 0.11  & 0.83 \\
C$_3$    & 9.19  & 9.01  & 9.10  & 9.84  & 9.18 \\
\bottomrule
\end{longtabu}}

\end{document}

Best Answer

I've cut your code down a bit for demonstration purposes, to make it a bit more minimal. But one way to do this is to specify the font size for each entry through the setup of the longtabu environment. For example:

\documentclass{report}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{booktabs}

\begin{document}

Composition of samples

\begin{longtabu} to \linewidth{>{\footnotesize}X[l3.0] *{5}{>{\footnotesize}X[c]}}
\caption{Composition of samples} \\
\toprule
\textbf{Component} & \textbf{Text1} & \textbf{Text2} & \textbf{Text3} & \textbf{Text4} & \textbf{Text5} \\
\midrule
H$_2$   & 3.94  & 3.81  & 4.03  & 3.88  & 4.01 \\
\bottomrule
\end{longtabu}

\end{document}

Because the declaration \footnotesize affects only the relevant column, it does not affect the caption. However, you do need to specify it for each column. If you have several consecutive columns with the same definition, however, you can combine those using the *{<number>}{<column specification>} syntax as I've done for 5 of the 6 columns in this case.

This produces:

Footnotesize text in <code>longtabu</code> with regular sized caption