![如何将下表单元格对齐到中间?](https://linux22.com/image/354004/%E5%A6%82%E4%BD%95%E5%B0%86%E4%B8%8B%E8%A1%A8%E5%8D%95%E5%85%83%E6%A0%BC%E5%AF%B9%E9%BD%90%E5%88%B0%E4%B8%AD%E9%97%B4%EF%BC%9F.png)
我有下表,我想让它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}