That is, if the table or figure is larger than the current \linewidth, then the figure or table is automatically scaled down to fit \linewidth. If the table or figure fits within \linewidth without resizing, then leave as is.
I normally use the \resizebox command using \linewidth as the width parameter, which works well for large tables that always need to be scaled down. However, this will resize a small table up (make larger) to fit \linewidth even when it is not necessary. Given the number of tables I have and the number of different \linewidth parameters I’m dealing with, I would like to figure out a way to have this done automatically. Ideally this code or modification would be part of the table itself (external file) so that wherever the table is inserted I get the desired result. I would appreciate any help.
Below is a simple example demonstrating my point using twocolumn and onecolumn modes within the same document (just for purposes of modifying \linewidth). The first table is correctly scaled down to fit twocolumn mode. The second table in onecolumn mode, however, is scaled up. I do not want this. I want the equivalent of the third table. Remember, in my particular case I am pulling the table from an external file (using the \input command) and would like to only have one version that can be inserted into multiple documents with varying \linewidth parameters.
Code: Select all
\documentclass{article}
\usepackage{graphicx}
\newcommand{\texample}{\resizebox{\linewidth}{!}{
\begin{tabular}{ccc}
Cell 1,1 Contents & Cell 1,2 Contents & Cell 1,3 Contents \\
Cell 2,1 Contents & Cell 2,2 Contents & Cell 2,3 Contents \\
Cell 3,1 Contents & Cell 3,2 Contents & Cell 3,3 Contents \\
Cell 4,1 Contents & Cell 4,2 Contents & Cell 4,3 Contents \\
Cell 5,1 Contents & Cell 5,2 Contents & Cell 5,3 Contents \\
\end{tabular}}}
\begin{document}
\centering
\twocolumn
This table is correctly scaled down to fit two-column mode.
\texample
\onecolumn
This table is scaled up, but would fit without rescaling in one-column mode.
\texample
This is the table without scaling.
\begin{tabular}{ccc}
Cell 1,1 Contents & Cell 1,2 Contents & Cell 1,3 Contents \\
Cell 2,1 Contents & Cell 2,2 Contents & Cell 2,3 Contents \\
Cell 3,1 Contents & Cell 3,2 Contents & Cell 3,3 Contents \\
Cell 4,1 Contents & Cell 4,2 Contents & Cell 4,3 Contents \\
Cell 5,1 Contents & Cell 5,2 Contents & Cell 5,3 Contents \\
\end{tabular}
\end{document}