如何垂直对齐表格列

如何垂直对齐表格列

我正在努力垂直对齐下表列内的文本。我希望获得这种垂直对齐以提高表格的可读性...我尝试在交替行上添加颜色,但它取消了行的左右板。如果您知道如何解决这个问题,请也添加它。

谢谢

\documentclass[margin=5pt]{article}

\usepackage{float}
\usepackage{caption}
\usepackage{tabularx,ragged2e,booktabs}
\usepackage{array}
\usepackage[table,x11names]{xcolor}
\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\xmark}{\ding{53}}%

\begin{document}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{f}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{table}
\caption[AM process/material matrix.]{AM processes comparison based on materials processable. }
\label{tab:AM_material_matrix}
\centering
\begin{tabular}{|f{3cm}|P{1.5cm}|P{1.5cm}|P{1.5cm}|P{1.5cm}|P{1.5cm}|P{1.5cm}|P{1.5cm}|}
\hline
                             & Material extrusion & Material jetting & Binder jetting & Vat photopolymerization & Sheet lamination & Powder bed fusion & Directed energy depositon \\
                             \hline 
Polymers, polymer blends     & \xmark                  & \xmark                & \xmark              & \xmark                       & \xmark                & \xmark                 &                           \\
Composites                   & \xmark                  & \xmark                & \xmark              & \xmark                       &                  & \xmark                 &                           \\
Metals                       &                    &                  & \xmark              &                         & \xmark                & \xmark                 & \xmark                         \\
Graded/hybrid metals         &                    &                  &                &                         & \xmark                &                   & \xmark                         \\
Ceramics                     &                    &                  & \xmark              & \xmark                       &                  & \xmark                 &                           \\
Investement casting patterns &                    & \xmark                & \xmark              & \xmark                       &                  & \xmark                 &                           \\
Sand molds and cores         & \xmark                  &                  & \xmark              &                         &                  & \xmark                 &                           \\
Paper                        &                    &                  &                &                         & \xmark                &                   &    \\                      
\hline
\end{tabular}
\end{table}


\end{document}

答案1

正如您所说的“垂直对齐”,如果您指的是示例中的列名和行名(例如“聚合物,聚合物共混物”),则另一种方法是:

\newcommand\minitab[2][c]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}
\begin{tabular}{|c|l|c|r|}
  \hline
  & \minitab[l]{Column\\ 1} & \minitab{Column\\ 2} & \minitab[r]{Column\\ 3}\\
  \hline
  \minitab{Multiple\\ line} & 2 & 2 & 2\\
  \hline
  Single & 1 & 1 & 1\\
  \hline
\end{tabular}

在此处输入图片描述

相关内容