I'm using two columns style. I would like to modify a table so it can fit with keeping clarity. Two of the cells their texts should be in two lines. The second line should be in the center.
\documentclass[11pt,twocolumn]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{amsmath}
\usepackage{pbox}
\begin{document}
\begin{table}[h]
\caption{An Example of a Table}
\label{table_example}
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
A & B & C & D & Q & W & error $\%$ in x & \pbox{20cm}{error $\%$ \\ in x } \\
\hline
23 & 1 & 80.9281 & 80.9281 & 80.9281 & aa & aa &\\
\hline
23 & 1 & 80.9281 & 80.9281 & 80.9281 & aa & aa &\\
\hline
23 & 1 & 80.9281 & 80.9281 & 80.9281 & aa & aa &\\
\hline
23 & 1 & 80.9281 & 80.9281 & 80.9281 & aa & aa &\\
\hline
23 & 3 & 80.9281 & 80.9281 & 80.9281 & aa & aa &\\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
This is the picture of the code
Best Answer
You should use the
makecell
package for that. It's dedicated to common formatting of multiline cells and defines a\thead
and a\makecell
command a multirow version of these. The default alignment in such cells is centred (vertically and horizontally) with keywords to choose amongt, b, c
andl, r, c
, independently of the column specifier. Here are two examples using \thead, for which I specify to use a boldface font.Also I added the
caption
package to have a proper vertical spacing between caption and table, and thecellspace
package to ensure a minimal spacing between the top of a cell and the line above, and between the bottom of a cell and the line below; it works defining anS
pre-specifier for columns.Another solution to get soacing between rows is to use the
booktabs
package; it defines new commands for horizontal rules of variable thickness, with some vertical spacing above and below; it this spacing is not enough, you have the\addlinespace
command.Finally I replaced the
center
environment withcentering
(center adds unwanted here vertical spacing):