如何将列宽度固定的 LaTeX 表格的单元格内容居中?
考虑下面的 LaTeX 代码:
\begin{tabular}{p{1in}p{1in}}
A & B\\
C & D\\
\end{tabular}
如何使每个单元格的内容在单元格的中心而不是左侧对齐? 请注意,我想确保列的宽度是固定的,因此我无法使用“c”位置属性而不是“p{.1in}”来居中单元格内容。
Consider the following piece of LaTeX code:
\begin{tabular}{p{1in}p{1in}}
A & B\\
C & D\\
\end{tabular}
How can I make the contents of each cell aligned in the center of the cell rather than the left?
Note that I want to make sure that the widths of my columns are fixed, so I cannot use the "c" position attribute instead of "p{.1in}" to center my cell contents.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
序言中的
\usepackage{array}
然后是这样的:
请注意,固定列的“m”是由 array 包提供的,并且将为您提供垂直居中(如果您不希望这样)返回“p”
\usepackage{array}
in the preamblethen this:
note that the "m" for fixed with column is provided by the array package, and will give you vertical centering (if you don't want this just go back to "p"
您可以将
\centering
与 parbox 一起使用来执行此操作。更多信息此处< /a> 和 此处。
(抱歉,谷歌缓存的链接;我原来的链接不再工作了。)
You can use
\centering
with your parbox to do this.More info here and here.
(Sorry for the Google cached link; the original one I had doesn't work anymore.)
我认为这个答案是最好的来源。您可以在标题中声明
newcolumntype
,然后在必要时使用它:我只添加了垂直线
|
来使列宽度(1in
)并且居中在输出中更加明显:I think that this answer is the best source. You can declare the
newcolumntype
in the header and then use it when necessary:I only added the vertical lines
|
to make the column width (1in
) and the centering more evident in the output: