如何將下面的表格單元格居中對齊?

如何將下面的表格單元格居中對齊?

我有下表,我希望它1顯示在左列的中心。

\documentclass{article}

\begin{document}

\begin{tabular}{|l|p{1in}|}
\hline
1 & a b c d e f g h i j k l m n o p q r s t u v w x y z \\
\hline
\end{tabular}

\end{document}

答案1

我已經在 David 的解決方案中添加了寬度,\myw以具有字串的精確寬度的列1,如果您還有 2 或 3 位數字,只需更改\settowidth{\myw}{...}或在列定義中放置您喜歡的任何寬度m{...}

\documentclass{article}
\usepackage{array}
\newlength{\myw}
\settowidth{\myw}{1}

\begin{document}
    \noindent\emph{David's solution (with \textbackslash\texttt{array} package)}

    Note that both colums must have \texttt{m\{\dots\}} type.
    \begin{center}
    \begin{tabular}{|m{\myw}|m{1in}|}
        \hline
        1 & a b c d e f g h i j k l m n o p q r s t u v w x y z \\
        \hline
    \end{tabular}
    \end{center}

    \noindent\emph{Steven's solution (with no extra packages)}

    Note that it's necessary to explicity give the height of the \arraybackslash\texttt{parbox}. 
    Otherwise, the lines overlap the text.
    \begin{center}
    \begin{tabular}{|l|p{1in}|}
        \hline
        1 & \parbox[c][1.2\height]{1in}{a b c d e f g h i j k l m n o p q r s t u v w x y z}\\
        \hline
    \end{tabular}
    \end{center}
\end{document}

在此輸入影像描述

相關內容