Latex表格固定列宽并设置靠左、居中或靠右

1 环境

\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}}

2 用法

  1. 靠左且设置宽度:L{ n n ncm},其中 n > 0 n>0 n>0 (虽然 ≤ \leq 也不会报错)
  2. 居中且设置宽度:L{ n n ncm}
  3. 靠右且设置宽度:R{ n n ncm}
  4. 注意:数值过小时会导致表格错位

3 示例

\documentclass{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{tabular}{lcrL{2cm}C{3cm}R{1cm}}
21.1  & 1.23  & 1.10  & 21.1  & 1.23  & 1.10\\
11.11 & 12.34 & 11.11 & 11.11 & 12.34 & 11.11\\
\end{tabular}

\end{document}

4 效果

5 参考

  1. https://gist.github.com/LanternD/1edd0fcc64f287d841b6da3ec38c69a2
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值