Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

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

share|improve this answer
    
Very ql! Exactly what I needed! –  RoflcoptrException Jul 17 '12 at 20:12
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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