第 1 行有一行,每个单元格居中。
第 2 行。第 1 列有两 (2) 行。每行居中。
第 2 行。第 2 列有一行。水平和垂直居中。
第 2 行。第 3 列文本换行。两端对齐。
第 3 行和第 4 行重复第 1 行。
答案1
\documentclass{article}
\usepackage{array}
\newcolumntype{L}{>{\centering\arraybackslash}m{3cm}}
\begin{document}
\begin{table}
\begin{tabular}{|L|c|L|}\hline
one & two & three \\\hline
This is two line thing and centered & only one line& \multicolumn{1}{m{3cm}|}{This is justified and may go to second line as well, neatly}\\\hline
one & two & three \\\hline
one & two & three \\\hline
\end{tabular}
\end{table}
\end{document}
答案2
谢谢您的回答,它启发了我制作一些自定义列类型,我很乐意与大家分享它们。
\documentclass[a4paper,13pt]{article}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{center}
\begin{tabular}{ | C{0.45\textwidth} | C{0.45\textwidth} | }
\hline
Correct (from the reader) & Experimental (HyperChem) \\ \hline
\end{tabular}
\begin{tabular}{ | L{0.45\textwidth} | m{0.45\textwidth} | }
\includegraphics[width=0.45\textwidth]{as1correlationcorrect} & \includegraphics[width=0.45\textwidth]{as1correlationbondorderbonddissociationenergyexperiment} \\ \\
\textbf{Figure 3: }Correlation between bond-order and Dissociation Energy, with the literature-experiment values for D\(_0\). & \textbf{Figure 4: }Correlation between bond-order and Dissociation Energy, with the computer-experiment values for D\(_0\).
\\ \hline
\end{tabular}
\end{center}
\end{document}
答案3
无需调用\newcolumntype
,我们可以使用内置命令,即>{\centering\arraybackslash}m{length}
,其中变量“长度”指定文本跨越的宽度
\begin{table}[H]
\centering
\begin{tabular}{>{\centering\arraybackslash}m{3.7cm}|>{\centering\arraybackslash}m{3.7cm}|>{\centering\arraybackslash}m{3.7cm}}
\hline
Only one line here. & Same for column two. & Same for column three. \\
\hline
We have two lines here, each line centered. & This cell will have three lines and each line centered as well. & Here is a justified cell, please check this out! \\
\hline
This cell has one line. & So does this one. & And this one, too! \\
\hline
\end{tabular}
\end{table}
输出如下
文本在每个单元格中水平和垂直居中。如果您希望文本垂直对齐到顶部,请使用>{\centering\arraybackslash}p{3.7cm}
。