What's the recommend way of changing the font size in a particular table? Is there a better way than enclosing all values with, for example, the \tiny function.
- 250,273
- 5,218
4 Answers
Scale down your table to the textwidth
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}
\resizebox{\textwidth}{!}{%
\begin{tabular}{cc}
Knuth & Lamport
\end{tabular}}
\end{table}
\end{document}
then you have the optimal font size. However, all tabular lines are also scaled down which doesn't matter because it looks nicer.
-
Now if this would only work with text wrapping as well and eliminate the need to manually specify columns widths, that would be awesome. Is there a way to use your functionality and also have automatic text wrapping? – Veridian Aug 09 '13 at 02:57
-
5
-
1I must report that with XeLaTeX it does work, but with LuaLaTeX does not. – djnavas Feb 10 '16 at 06:45
-
I must add, that the problem is caused by "xetex" option with package "xcolor".
– djnavas Feb 10 '16 at 07:10\usepackage[xetex]{xcolor}, -
sure, in that case it works only with a
xetexdriver. However, in general you do not need such an option forgraphicx– Feb 10 '16 at 07:34 -
9It was not stated but the caption,
\caption{demo table}, and label,\label{tab:demo}, go outside of the\resizeboxarea. – Steven C. Howell Feb 01 '17 at 19:09 -
3I have a table in landscape
\begin{landscape}. When I used\textwidthfor defining the width of the resized box, the resulting box had the width of the text of a portrait oriented page. For anybody having the same problem, use\linewidthinstead of\textwidth, it solved the problem in my case. Source: https://tex.stackexchange.com/a/7686/118906 – a tiger Apr 26 '17 at 13:14 -
Herbert's answer is very elegant, but it responds strangely with \newpage: - in an environment that goes: [\newpage text table] it outputs in a different order [table text]
- in an environment that goes: [table \newpage text] it doesn't follow the \newpage command
-
-
8Never use
\resizeboxwith tables. If used on multiple tables with different number of columns, it will yield a different font size for each table in the document. It will be ugly. – leermeester Aug 27 '20 at 10:15 -
1It is not only the inconsistency of the font sizes. This will produce a more obvious inconsistency in the thickness of the table lines. A font a bit different of
\smallor\footnotesizecould go unnoticed at some extent, but lines too thin or too thick attract attention too much, showing that little effort has been put into the design of the document. – Fran Sep 13 '23 at 08:27
Write \tiny immediately after \begin{table}. If you don't use a (floating) table environment, enclose your (e.g.) tabular environment in a group and write \tiny after \begingroup.
\documentclass{article}
\begin{document}
\begin{table}
\tiny
\centering
\begin{tabular}{cc}
Knuth & Lamport
\end{tabular}
\end{table}
\end{document}
EDIT: To change the fontsize for all tables (or even floats of every type), one may use the floatrow package (this also saves typing \centering in every table):
\documentclass{article}
\usepackage{floatrow}
\DeclareFloatFont{tiny}{\tiny}% "scriptsize" is defined by floatrow, "tiny" not
\floatsetup[table]{font=tiny}
\begin{document}
\begin{table}
\begin{tabular}{cc}
Knuth & Lamport
\end{tabular}
\end{table}
\end{document}
- 250,273
-
7Just one quick additional remark: whenever your figure/table has a caption, be sure to change the font size only after you've specified the caption. This is particularly important if you're specifying
tinyorscriptsizefor the font size. – Mico Aug 31 '11 at 17:26 -
1Anyway to specify font sizes between \tiny and \small? \tiny is too small for me to read and \small is the same as normal font size – Veridian Aug 13 '13 at 00:16
-
3
-
1Dredging up the past... @Mico, I don't see this behaviour at all. None of my captions (specified with
\caption) are affected in any way with a fontsize declaration before them inside atableenvironment. – a different ben Jan 21 '14 at 23:21
An easier way to change the font size for ALL tables:
\usepackage{etoolbox}
\AtBeginEnvironment{tabular}{\tiny}
- 91
-
4Very, very dangerous. A
tabularmay be hidden in places you do not suspect. For example in\maketitle. – campa Dec 02 '20 at 15:00 -
I tried but didn't find any differences using
\maketitle. If it happens, we should set a particular font size for any special tables. – DianChao Lin Dec 16 '20 at 16:35 -
3That was just an example; not every class defines
\maketitleusing atabularbut some do (e.g. the standard classes for the author). My point is that there might be atabularhidden somewhere where you do not expect it, and changing the default behaviour oftabularmight have unforeseeable consequences. So I stand by my opinion that this is dangerous. (I haven't said "bad" or "wrong". Just dangerous.) – campa Dec 16 '20 at 16:45
The easiest way is using \fontsize:
\documentclass{article}
\usepackage{anyfontsize}
\begin{document}
\begin{table}
\fontsize{9pt}{9pt}\selectfont
\begin{tabular}{cc}
Knuth & Lamport
\end{tabular}
\end{table}
\end{document}
More information about the syntax may be found here.
\scalebox{}{}of thegraphicxpackage as mentioned here: http://tex.stackexchange.com/a/56035/92521 – daniel.heydebreck Apr 06 '16 at 10:09