LATEX 固定表格列宽并居中

来源:互联网 发布:java 获取jar包中资源 编辑:程序博客网 时间:2024/06/05 05:21

方法1: 使用p{x cm}能固定列宽,但是不能修改是否居中、左对齐、右对齐。只能使用默认格式

\documentclass{article}\begin{document}\begin{tabular}{|p{1cm}|p{2cm}|p{3cm}|}\hline1 cm width & 2 cm  width & 3 cm  width \\\hlinetest 1 & test 2 & test 3\\\hline\end{tabular}\end{document}

效果图:
方法2: 
The alignment of the cells could be changed by using the package tabularx and define three new row-types: flush left fixed width:\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}center fixed width:\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}flush right fixed width:\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
示例如下:
\documentclass{article}\usepackage{tabularx}\begin{document}\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}\begin{tabular}{|L{1cm}|C{2cm}|R{3cm}|}\hline1 cm width & 2 cm  width & 3 cm  width \\\hlinetest 1 & test 2 & test 3\\\hline\end{tabular}\end{document}
效果图:


0 0
原创粉丝点击