# \centering just a table instead of all text

I'm having problems with this my code because once I added the tables all the text following them was no longer justified. here is the code

\begin{document}
\chapter{1}
\centering\large
\begin{tabular}{>{$}l<{$}|r|r|r}
\toprule
\multicolumn{4}{c}{Tabella Circuito 1}\\
\midrule
& Teorico& Reale& Spice\\
\midrule
R_\mathrm{B}&\SI{2.2}{\mega\ohm}&\SI{2.24}{\mega\ohm}&\SI{2.2}{\mega\ohm}\\
R_\mathrm{C}&\SI{5.6}{\kilo\ohm}&\SI{5.56}{\kilo\ohm}&\SI{5.6}{\kilo\ohm}\\
\end{tabular}
\chapter{2}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{document}


I tried removing

 \centering\large


or just to move it after \begin{tabular}, or to put it after mid/top rule,but i got multiple errors. I also tried to add {} before

\centering


and after

 \end{tabular}


and this time the text was justified but the table was no longer centered.

How can this problem be solved

-
If you don't use a table environment, you're best served with a center environment instead of \centering. –  egreg May 17 at 17:35

If you want the tabular centred, you need to provide some scope within which \centering acts. In your instance \centering is engaged but never disengaged. As such, everything following \centering will be centred.

My suggestion is to use the center environment:

\begin{center}
\large
\begin{tabular}{>{$}l<{$}rrr}
\toprule
\multicolumn{4}{c}{Tabella Circuito 1}\\
\midrule
& Teorico & Reale & Spice\\
\midrule
R_\mathrm{B} & \SI{2.2}{\mega\ohm} & \SI{2.24}{\mega\ohm} & \SI{2.2}{\mega\ohm} \\
R_\mathrm{C} & \SI{5.6}{\kilo\ohm} & \SI{5.56}{\kilo\ohm} & \SI{5.6}{\kilo\ohm} \\
\bottomrule
\end{tabular}
\end{center}


The scope of "\centering" in the above example is limited by the center environment (it forms a group).

Note that I've dropped the vertical rules between the columns, as suggested in the booktabs documentation:

You will not go far wrong if you remember two simple guidelines at all times:

1. Never, ever use vertical rules.

2. Never use double rules.

These guidelines may seem extreme but I have never found a good argument in favour of breaking them. For example, if you feel that the information in the left half of a table is so different from that on the right that it needs to be separated by a vertical line, then you should use two tables instead.

Alternatively, ragged2e provides \justifying that you can use to switch back to fully-justified text without having to provide scope. Make sure though you leave an empty line (or an explicit \par) between these justification changes in order for them to take effect.

-

\centering is a declaration that tells TeX “from now on, center my text”. However, the end of a group will also end the scope of this declaration. You don't have a group, so TeX happily complies with your request. Use a center environment.

\documentclass{book}

\usepackage{array,booktabs,siunitx}

\begin{document}

\chapter{1}

\begin{center}
\large
\begin{tabular}{>{$}l<{$}rrr}
\toprule
\multicolumn{4}{c}{Tabella Circuito 1}\\
\midrule
& Teorico& Reale& Spice\\
\midrule
R_\mathrm{B}&\SI{2.2}{\mega\ohm}&\SI{2.24}{\mega\ohm}&\SI{2.2}{\mega\ohm}\\
R_\mathrm{C}&\SI{5.6}{\kilo\ohm}&\SI{5.56}{\kilo\ohm}&\SI{5.6}{\kilo\ohm}\\
\end{tabular}
\end{center}

\chapter{2}

blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah

\end{document}


Note that \end{center} also ends the scope of \large. Use \centering when the tabular is in a table environment.

-