Center A Table That Uses Resizebox


Answer :

There is no centering environment. And issuing \centering inside \resizebox doesn't make sense anyway: it should be outside, because you want to center the resized box.

\documentclass[11pt,english,titlepage]{article} \usepackage{graphicx}  \begin{document}  \begin{table} \centering \caption{mytable} \resizebox{.5\textwidth}{!}{% <------ Don't forget this %   \begin{tabular}{rrr}   A              & B            & C \\   \hline   A1             & B1           & C1 \\   A2             & B2           & C2 \\   A3             & B3           & C3 \\   \end{tabular}% <------ Don't forget this % } \end{table}  \end{document} 

Here an alternative answer using adjustbox. It covers the functionality of \resizebox and is also able to center its content. It also removes the need of escaping the line breaks with % as seen in egregs answer, as the adjustbox environment removes the spaces added by them.

It is even possible to produce the table environment using adjustbox keys, or even to get the whole tabular environment replaced. This saves you a lot of typing in the long run. Note that the order of most adjustbox keys matter.

\documentclass[11pt,english,titlepage]{article} \usepackage{adjustbox}  \begin{document}  \begin{table} \caption{mytable}% will not give you proper skip as it is configured for placement below the content \begin{adjustbox}{width=.5\textwidth,center}   \begin{tabular}{rrr}   A              & B            & C \\   \hline   A1             & B1           & C1 \\   A2             & B2           & C2 \\   A3             & B3           & C3 \\   \end{tabular} \end{adjustbox} \end{table}  % shorter, also covering the `table` environment \begin{adjustbox}{width=.5\textwidth,center,caption=mytable,float=table}   \begin{tabular}{rrr}   A              & B            & C \\   \hline   A1             & B1           & C1 \\   A2             & B2           & C2 \\   A3             & B3           & C3 \\   \end{tabular} \end{adjustbox}  % even shorter, now also covering the `tabular` environment \begin{adjustbox}{tabular=rrr,width=.5\textwidth,center,caption=mytable,float=table}   A              & B            & C \\   \hline   A1             & B1           & C1 \\   A2             & B2           & C2 \\   A3             & B3           & C3 \\ \end{adjustbox}  \end{document} 

Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Change The Font Size Of Visual Studio Solution Explorer