0

I have the following table, I would like to vertical align the content but I cannot solve the problem with the suggestions I have found online. can you help me?

\begin{table}[]

\begin{center}
\caption{My caption}
\label{my-label}

\begin{tabular}{ | >{\centering}p{2.75cm} | >{\centering}p{1.75cm} | >{\centering}p{1.75cm}  | >{\centering}p{1.75cm} | }
    \hline\hline
    \textbf{Title / Title} & \textbf{X}     & \textbf{Y}     & \textbf{Z}   \\[5pt]  \tabularnewline\hline\
    \textbf{A}  & a\% & b\%  & c\%\\[5pt] \tabularnewline\hline
    \textbf{B}  & d\% & e\% & f\%\\[5pt] \tabularnewline\hline
    \textbf{C}  & g\% & h\%  & i\%\\[5pt] \tabularnewline\hline
    \textbf{D}  & j\% & k\% & l\%\\[5pt] \tabularnewline\hline
\end{tabular}

\end{center}

\end{table}
user25954
  • 155
  • please fix your example so that it may be run to see the issue. What do you mean by vertically align here, what do you want to align with what? A tabular is essentially a \halign which arranges the horizontal alignment of cells. – David Carlisle Feb 18 '17 at 14:33
  • I guess that for vertical alignment I mean what is commonly mean. Namely, the space above and below each cell's content (e.g. a, b, A, Y or X) shall be the same. I have centered on horizontal dimension I would like to center also for vertical dimension. Actually table is a package but I can't exacly identify which one is right now... I am afraid I have added it a lot of time ago and forgot the name. Thanks – user25954 Feb 18 '17 at 14:44
  • 1
    That isn't really alignment it doesn't align anything but in any case you should fix the example so it can be run. probably you just want something like \setlength\extrarowheight{2pt} to add a bit of space above the entries. You don't really want vertical centering otherwise for example the letters with descenders such as g would be out of line with those without such as a. – David Carlisle Feb 18 '17 at 15:00

1 Answers1

3

I guess that you like to obtain something like this:

enter image description here

\documentclass{article}
\usepackage{makecell}
\setcellgapes{5pt}

\begin{document}
    \begin{table}[]
\centering
    \caption{My caption}
    \label{my-label}
\makegapedcells
\begin{tabular}{ | >{\centering}p{2.75cm} | *{3}{>{\centering\arraybackslash}p{1.75cm} |}}
    \hline\hline
\textbf{Title / Title} 
            & \textbf{X}    & \textbf{Y}    & \textbf{Z}    \\   \hline\hline
\textbf{A}  & a\%           & b\%           & c\%           \\  \hline
\textbf{B}  & d\%           & e\%           & f\%           \\  \hline
\textbf{C}  & g\%           & h\%           & i\%           \\  \hline
\textbf{D}  & j\%           & k\%           & l\%           \\  \hline
\end{tabular}
    \end{table}
\end{document}

In your code snipped I remove all surplus vertical spacing ([5pt]), instead \begin{center} ... \end{center} it is better to use just \centering, for more vertical space I use macro \makegapedcells from package makecell. This all should serve at list as starting point :-).

Zarko
  • 296,517