I would like to find an easy way to adjust cells in my longtable
to centered, while still using the p{}
definition of the columns.
The code I'm using is:
\documentclass[a4paper]{article}
\usepackage{lipsum}
\usepackage{longtable}
\usepackage{colortbl}
\usepackage{xcolor}
\newlength\mylength
\begin{document}
\lipsum
\setlength\mylength{\dimexpr\textwidth-5\arrayrulewidth-8\tabcolsep}
\begin{longtable}{|p{.25\mylength}|p{.25\mylength}|p{.25\mylength}|p{.25\mylength}|}
\rowcolor{white}\caption{Test table\label{tab:test1}}
\hline
\rowcolor{blue}\textcolor[rgb]{1,1,1}{Term 1} & \textcolor[rgb]{1,1,1}{Term 2} & \textcolor[rgb]{1,1,1}{Term 3} & \textcolor[rgb]{1,1,1}{Term 4}\\
\hline
Test 1 & Test 2 & Test 3 & Test 4\\
\hline
\end{longtable}
\end{document}
Which gives the following output:
How do I center the cells of the table? I would like to be able to perform both options:
- Center all the cells in the table
- Center some cells individually, and keep the others as they are
array
package then>{\centering\arraybackslash}p{...
– David Carlisle Sep 9 '15 at 13:31