I'm new with LaTeX and I'm trying to make a table with the elements centered vertically and horizontally. I've searched for this question, it seems like most people were trying to do things a little more complicated than this, resulting in complicated answers I couldn't understand. The table below is already centered horizontally, but the elements are aligned to the top of the cells instead of the center. How do I fix this?
\begin{tabular}{*{5}{|c}|}
\hline
$p$ & $q$ & $p \land q$ & $p \lor q$ & $p \to q$\\
\hline
T & T & T & T & T\\
\hline
T & F & F & T & F\\
\hline
F & T & F & T & T\\
\hline
F & F & F & F & T\\
\hline
\end{tabular}
Best Answer
The vertical skip from baseline to baseline within regular text is given by
\baselineskip
. Withintabular
, this is0pt
but it is still accessible as\normalbaselineskip
. Using your example as reference, it is clear to see that the vertical baseline skip still holds when drawing a vertical1pt
rule of height\normalbaselineskip
:If you have a very particular table, like the one in your example, where baseline alignment may seem to be inadequate, you could play around with the addition of a vertical "strut" like in the following example:
Using the
array
package, it allows you to insert<stuff>
before every table column entry using>{<stuff>}
. Using them{<width>}
column specification, I've fixed the column widths (I think it looks cleaner that way) and reverted back to the centering supplied byc
-columns.Although this may be a moot point based on personal preference, consider using the
booktabs
package to typeset tables: