It is always true that placing the float element at the center of any document enhances the beauty of the document.
Because of this, you will notice that the tables and figures are centered in the Maximum document.
But, the table environment will always keep your table in left alignment. So what is the solution for center ligament? Yes, there is more than one solution for this.
Use \centering command
The simplest and most popular solution is to use \centering
command. Because maximum number of people in the LaTeX community change alignment of table by inserting this command.
Syntactically, this command’s position is before the tabular
environment. Look at the syntax below to make the concept clearer.
\begin{table}{...} \centering \begin{tabular}{...} ...... ...... \end{tabular} \end{table}
\documentclass[12]{article}
\usepackage{lipsum}
\usepackage[margin=1.5cm]{geometry}
\begin{document}
\section*{Default alignment}
\lipsum[1][1-8]
\vspace{.5cm}
\begin{table}[ht]
\begin{tabular}{|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 \\
\hline
Data 11 & Data 12 & Data 13 \\
\hline
Data 21 & Data 22 & Data 23 \\
\hline
Data 31 & Data 32 & Data 33 \\
\hline
Data 31 & Data 42 & Data 43 \\
\hline
\end{tabular}
\end{table}
\section*{Table move to center}
\lipsum[2][1-10]
\vspace{.5cm}
\begin{table}[ht]
\centering
\begin{tabular}{|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 \\
\hline
Data 11 & Data 12 & Data 13 \\
Data 21 & Data 22 & Data 23 \\
Data 31 & Data 32 & Data 33 \\
Data 31 & Data 42 & Data 43 \\
\hline
\end{tabular}
\end{table}
\vspace{.5cm}
\lipsum[2][1-7]
\vspace{.5cm}
\begin{table}[ht]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 & column 4 \\
\hline
Data 11 & Data 12 & Data 13 & Data 14 \\
\hline
Data 21 & Data 22 & Data 23 & Data 24\\
\hline
Data 31 & Data 32 & Data 33 & Data 34 \\
\hline
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
\end{tabular}
\end{table}
\lipsum[3]
\end{document}
Output :
Use center environment
Our second solution is center
environment, but this environment must be used within the table environment.
\begin{table}{..} \begin{center} \begin{tabular}{...} % Your table code here ....... ....... \end{tabular} \end{center} \end{table}
\documentclass[12pt]{article}
\usepackage{lipsum}
\usepackage[margin=1.5cm]{geometry}
\begin{document}
\section*{Without center environment}
\lipsum[1][1-8]
\vspace{.6cm}
\begin{table}[ht]
\begin{tabular}{|c|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 & column 4 \\
\hline
Data 11 & Data 12 & Data 13 & Data 14 \\
\hline
Data 21 & Data 22 & Data 23 & Data 24\\
\hline
Data 31 & Data 32 & Data 33 & Data 34 \\
\hline
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
\end{tabular}
\end{table}
\section*{With center environment}
\lipsum[2][1-8]
\begin{table}[ht]
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column3} & \textbf{Column 4} \\
\hline
Data 11 & Data 12 & Data 13 & Data 14 \\
Data 21 & Data 22 & Data 23 & Data 24\\
Data 31 & Data 32 & Data 33 & Data 34 \\
Data 31 & Data 42 & Data 43 & Data 44 \\
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
\end{tabular}
\caption{Center Table}
\end{center}
\end{table}
\lipsum[3][1-5]
\begin{table}[ht]
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column3} & \textbf{Column 4} \\
\hline
Data 11 & Data 12 & Data 13 & Data 14 \\
\hline
Data 21 & Data 22 & Data 23 & Data 24\\
\hline
Data 31 & Data 32 & Data 33 & Data 34 \\
\hline
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
\end{tabular}
\caption{Center Table}
\end{center}
\end{table}
\lipsum[4][1-5]
\end{document}
Output :
Using the adjustbox Package
Third is adjustbox
environment, which is present in adjustbox
package. But, the syntax is different in this case.
You need to pass the argument along with the environment for alignment. You can pass left
, right
and center
arguments as per requirement.
But, in this case, center
alignment must pass.
\usepackage{adjustbox} ... \begin{adjustbox}{center} \begin{tabular}{...} ... \end{tabular} \end{adjustbox}
\documentclass[12pt]{article}
\usepackage{lipsum,adjustbox}
\usepackage[margin=1.5cm]{geometry}
\begin{document}
\lipsum[1][1-8]
\vspace{.8cm}
\begin{adjustbox}{center}
\begin{tabular}{|c|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 & column 4 \\
\hline
Data 11 & Data 12 & Data 13 & Data 14 \\
\hline
Data 21 & Data 22 & Data 23 & Data 24\\
\hline
Data 31 & Data 32 & Data 33 & Data 34 \\
\hline
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
\end{tabular}
\end{adjustbox}
\vspace{.5cm}
\section*{With caption}
\lipsum[2][1-10]
\vspace{.8cm}
\begin{table}[ht]
\begin{adjustbox}{center}
\begin{tabular}{|c|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 & column 4 \\
\hline
Data 11 & Data 12 & Data 13 & Data 14 \\
\hline
Data 21 & Data 22 & Data 23 & Data 24\\
\hline
Data 31 & Data 32 & Data 33 & Data 34 \\
\hline
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
Data 31 & Data 42 & Data 43 & Data 44 \\
\hline
\end{tabular}
\end{adjustbox}
\caption{Add Caption}
\end{table}
\vspace{.8cm}
\lipsum[3][1-10]
\begin{table}[ht]
\begin{adjustbox}{center}
\begin{tabular}{|c|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 & column 4 \\
\hline
\hline
Data 11 & Data 12 & Data 13 & Data 14 \\
\hline
Data 21 & Data 22 & Data 23 & Data 24\\
\hline
Data 21 & Data 22 & Data 23 & Data 24\\
\hline
\end{tabular}
\end{adjustbox}
\caption{Add Caption}
\end{table}
\end{document}
Output :