0

I want to create a table where in each column I need to write something in two (or more than) lines. I also want that in each cell all the entries will be aligned at the centre.

I tried one code as follows. It serves the "two or more line" condition. But I am unable to make the alignment at centre. Any help?

Code:

\begin{table}[h]
\centering \def\arraystretch{1.5} \small

\begin{tabular}{|p{3cm}|p{1cm}|p{1cm}|}

    \hline

    quantum electrodynamics & hello \par left & aligned \par efgh \\ \hline

    electromagnetism & hello \par left & aligned \par efgh \\ \hline

    classical physics & hello \par world & abcd \par efgh \\ \hline

\end{tabular}

\end{table}

The output is:

enter image description here

1 Answers1

0

enter image description here

\documentclass[demo]{article}
\usepackage{nicematrix}

\usepackage{booktabs}

\newcolumntype{Y}[1]{>{\centering\arraybackslash}p{#1\textwidth}} \begin{document} \begin{NiceTabular}{Y{0.4}Y{0.6}} \toprule[2pt] Vantagens & Desvantagens \ \midrule Rede mais simples & Difícil correcção e detecção de erros \ \midrule Implementação mais barata & Uma quebra no cabo pode comprometer o acesso dos dispositivos à rede \ \midrule Não são necessários equipamento complexos & Problemático ao adicionar e remover dispositivos da rede \ \bottomrule[2pt] \end{NiceTabular} \end{document}

In case only left aligned text is required use

   \begin{NiceTabular}{p{0.4\textwidth}p{0.6\textwidth}}

in place of the Y type column

Result

enter image description here

js bibra
  • 21,280