How to decrease the font size of a table in an \input file

I have:

\documentclass[11pt]{article}
\begin{document}
This is the main tex document.
\input{tables}
\end{document}


In the tables.tex file, I only have numerical tables. I want to decrease the size of fonts used in the table, without modifying tables.tex. Is there proper commands that I can enter right before \input{tables}?

FYI, tables.tex looks like:

\begin{table}[htbp]
\caption{table caption}
\begin{tabular}{rr}
$u$   & 0.00
\end{tabular}
\end{table}

-
Do you want to change the font size of the tabular only, or also that of the caption? –  Werner Nov 11 '11 at 4:22
@Werner tabular only, but either is okay. –  FEQ Nov 11 '11 at 4:23
The title here is actually misleading. Font changes have nothing to do if the content is in a \input file or not. Your issue here is that the table environment changes the font itself. –  Martin Scharrer Nov 11 '11 at 16:31

This works for me:

{\renewcommand\normalsize{\tiny}%
\normalsize
\input{tables}}

-
This does not work for my files. I added more details. –  FEQ Nov 11 '11 at 4:22
Sorry, I was wrong. Corrected. –  Boris Nov 11 '11 at 4:29
You don't need to keep wrong answers around. Old versions of all post can anyway be viewed. Simply remove and update any incorrect things. –  Martin Scharrer Nov 11 '11 at 16:33
@martin-sharrer Wrong answers actually might be useful to show the traps, but just for brevity I've deleted it. –  Boris Nov 11 '11 at 17:58

You can use the etoolbox package to tap into the start of the tabular environment and modify the font size. In the MWE below, the tabular font size is set to \Huge:

\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\BeforeBeginEnvironment{tabular}{\Huge}% Adjust tabular font size to \Huge

\begin{filecontents*}{table.tex}
\begin{table}[htbp]
\centering
\caption{table caption}
\begin{tabular}{rr}
$u$ & 0.00
\end{tabular}
\end{table}
\end{filecontents*}

\begin{document}
Here is some dummy text.

\input{table}%

Here is some more dummy text.
\end{document}


As the name states, \BeforeBeginEnvironment{<env>}{<stuff>} command inserts <stuff> before the beginning of the environment <env> - tabular in this case.

If you're interested in modifying only the tables that are included using \input, then it would be best to define your own \input command, say \myinput, and combine it with @Boris' answer. Here's an example of how to do just that:

\documentclass{article}

\usepackage{filecontents}% http://ctan.org/pkg/filecontents
\begin{filecontents*}{table.tex}
\begin{table}
\centering
\caption{A table included via \texttt{input}}
\begin{tabular}{rr}
$u$ & 0.00
\end{tabular}
\end{table}
\end{filecontents*}

\newcommand{\myinput}[1]{%
\begingroup%
\input{#1}%
\endgroup%
}
\begin{document}
Here is some dummy text.

\myinput{table}%

Here is some more dummy text.

\begin{table}
\centering
\caption{A table in the main document}
\begin{tabular}{rr}
$u$ & 0.00
\end{tabular}
\end{table}

\end{document}


Grouping within the \myinput{<file>} command (using \begingroup...\endgroup) ensures that the \normalsize redefinition remains local.

-
This works good for me. Just for the future use, would it be possible to impact only the tabular's in the tables.tex file? I want all other tables in the main tex file normal, but only tables in the external file tiny (or huge). –  FEQ Nov 11 '11 at 4:46
@Chang: See my updated answer. –  Werner Nov 11 '11 at 15:46

In the following example I define a new command \CFTable with one optional argument, which redefines the table and table* environments as defined by the standard document classes; the optional argument will select the font size switch to be applied to the tables (it will not have any effect on the captions); the valid values for the optional argument are tiny, scriptsize, footnotesize, small (default), normalsize, large, Large, LARGE, huge, and Huge:

\RequirePackage{filecontents}
\begin{filecontents*}{testtables.tex}
\begin{table}
\centering
\caption{Some test table}
\begin{tabular}{cc}
text & text \\
123 & 234\\
123 & 234\\
123 & 234\\
123 & 234\\
123 & 234\\
\end{tabular}
\end{table}
\end{filecontents*}

\documentclass{article}

\makeatletter
\newcommand\CTFont[1][small]{
\renewenvironment{table}
{\@float{table}\csname#1\endcsname}
{\end@float}
\renewenvironment{table*}
{\@dblfloat{table}\csname#1\endcsname}
{\end@dblfloat}
}
\makeatother
\begin{document}

\begingroup
\CTFont% tables in \small size
\input{testtables}
\endgroup

\begingroup
\CTFont[tiny]% tables in \tiny size
\input{testtables}
\endgroup

\begingroup
\CTFont[Large]% tables in \Large size
\input{testtables}
\endgroup

\end{document}


The filecontents package and the filecontents* environment are only to provide a complete compilable example; you don't need them in your actual code.

With the code above, the change in the font size will only affect the table contents but not the captions; to achieve a simultaneous change to the caption font size, it's enough to load the caption package:

\usepackage{caption}


and change the definition of \CFTable to

\makeatletter
\newcommand\CTFont[1][small]{
\captionsetup[table]{font=#1}
\renewenvironment{table}
{\@float{table}\csname#1\endcsname}
{\end@float}
\renewenvironment{table*}
{\@dblfloat{table}\csname#1\endcsname}
{\end@dblfloat}
}
\makeatother


now, however, the only valid values for the optional argument are scriptsize, footnotesize, small (default), normalsize, large, and Large.

-
Both methods do not work for my files. I added more details. –  FEQ Nov 11 '11 at 4:14
@Chang: I've updated my answer according to the new information in your question. –  Gonzalo Medina Nov 11 '11 at 16:28

You don't mention by how much you want to reduce the font's size. Latex gives you four choices -- \small, \footnotesize, \scriptsize, and \tiny -- to reduce the font size below \normalsize. I'll assume that, for the sake of argument, you're looking to employ the size \small, which is generally 1pt smaller than \normalsize.

If you place the following code snippet in your document's preamble

\makeatletter
\renewenvironment{table}%
\renewcommand\normalsize{\small} % or \footnotesize, \scriptsize, \tiny, as needed
\@float{table}}
{\end@float}
\makeatother


no further changes to your code should be necessary. Note that the meaning of \normalsize will be unchanged outside of table environments.

If you want the fontsize-changing command to affect only tables in the tables.tex file, but no other tables, you could just insert the command

\renewcommand\normalsize{\small} % or \footnotesize, \scriptsize, \tiny, as needed


immediately before the \input tables instruction. (Your MWE seems to indicate that these tables are at the end of the document, so there's no need to encase the statements in a pair of braces.)

-
don't forget \scriptsize. –  Gonzalo Medina Nov 11 '11 at 4:08
This does not work for my files. I added more details. –  FEQ Nov 11 '11 at 4:14
Thanks, will add it. –  Mico Nov 11 '11 at 4:14
@Chang: Please add some information: do you get an error message, a warning message? Which font family are you using? –  Mico Nov 11 '11 at 4:17
@Mico I exactly used the codes in my question. I do not get any error/warning message. It simply does not change the font size of the table. –  FEQ Nov 11 '11 at 4:20