8

This question already has an answer here:

I have a table that looks like this:

\begin{table}[h]
\centering
\caption{MYCaption}
\label{tbl:table1}
\begin{tabular}{|l|l|l|l|}
\hline
\rowcolor[gray]{.8}
\multicolumn{4}{|c|}{Team 1}\\
\hline
\textbf{Caption1} & \textbf{Caption 2} & \textbf{Caption3} & \textbf{Caption 4}\\
\hline
Some values & Some values & Some values & Some values\\
\hline
\rowcolor[gray]{.8}
\multicolumn{4}{|c|}{Team 2}\\
\hline
\textbf{Caption1} & \textbf{Caption 2} & \textbf{Caption3} & \textbf{Caption 4}\\
\hline
Some values & Some values & Some values & Some values\\
\hline
\end{tabular}
\end{table}

I also have a two column layout, but the table spreads across both columns. However, at the moment the table is too wide for the page width. Now I would like that the font size is automatically adapted so that the table always fits into the page. The solutions I could find so for are not able to do this, because they use linebreaks to fit the table. I don't want linebreaks.

marked as duplicate by Werner tables Oct 7 '17 at 2:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

9

You can use \resizebox from the graphicx package. A little example showing the table with and without the use of \resizebox for comparison purposes (I used [!ht] for this example):

\documentclass{article} 
\usepackage{graphicx}
\usepackage{lipsum}% just to generate filler text

\begin{document}  

\lipsum[2]
\begin{table}[!ht]
\centering
\caption{Test caption}
\label{tbl:table1}
\begin{tabular}{|l|l|l|l|}
\hline
Some really reallly long values & 
Some really reallly long values & 
Some really reallly long values & 
Some really reallly long values \\
\hline
\end{tabular}
\end{table}

\lipsum[2]
\begin{table}[!ht]
\centering
\caption{Test caption}
\label{tbl:table2}
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|l|l|l|}
\hline
Some really reallly long values & 
Some really reallly long values & 
Some really reallly long values & 
Some really reallly long values \\
\hline
\end{tabular}}
\end{table}

\end{document}

enter image description here

2

If you use two column mode, you can have a wide table using both column by using the a star in \begin{table}:

\begin{table*}

Your table in a two column layout where the table is using both columns:

\documentclass[a4paper,twocolumn]{article}

\usepackage{lipsum,colortbl,graphicx}

\begin{document}

\lipsum[2-10]
\begin{table*}
\centering
\caption{MYCaption}
\label{tbl:table1}

\resizebox{\linewidth}{!}{\begin{tabular}{|l|l|l|l|}
\hline
\rowcolor[gray]{.8}
\multicolumn{4}{|c|}{Team 1}\\
\hline
\textbf{Caption1} & \textbf{Caption 2} & \textbf{Caption3} & \textbf{Caption 4}\\
\hline
Some values & Some values & Some values & Some values\\
\hline
\rowcolor[gray]{.8}
\multicolumn{4}{|c|}{Team 2}\\
\hline
\textbf{Caption1} & \textbf{Caption 2} & \textbf{Caption3} & \textbf{Caption 4}\\
\hline
Some values & Some values & Some values & Some values\\
\hline
\end{tabular}
}
\end{table*}

\lipsum[2-10]

\end{document}

Not the answer you're looking for? Browse other questions tagged or ask your own question.