加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

LaTeX技巧329:表格标题居左如何实现?

(2010-08-02 21:58:21)
标签:

latex

表格

居左

标题

杂谈

分类: 表格制作

QQ群:91940767/145316219/141877998/80300084/194770436
淘宝店:http://latexstudio.taobao.com
技巧续篇:http://latexstudio.net/
常见数学公式问题集下载

在没有其他控制命令的时候,我们的表格标题默认位置,如下示例:

\documentclass[12pt,letterpaper]{report}

\newcommand\T{\rule{0pt}{2.6ex}}
\newcommand\B{\rule[-1.2ex]{0pt}{0pt}}

\begin{document}
\setcounter{table}{3}
\begin{table}[h!b!p!]
\caption{Table (default placement of caption)}
\begin{tabular}{lll}
\hline
% \T and \B would not work if it is placed here (needs to go inside cell)
Alphabet Character \T \B & Vowel & Number \\
\hline
A \T & Yes & 1 \\
B & No & 2 \\
C \B & No & 3 \\
\hline
\end{tabular}
\label{table4}
\end{table}
\end{document}
https://www.msu.edu/~harris41/latex_tablespacing4.png
有时,我们需要把表格的标题和表格一起居左,那么可以使用如下代码:

% Example LaTeX document 5
% table with modified placement of caption
\documentclass[12pt,letterpaper]{report}

% These commands can be placed in the preamble (to be a global definition)
% or locally inside the \begin{table}...\end{table} syntax.
\newcommand\T{\rule{0pt}{2.6ex}}
\newcommand\B{\rule[-1.2ex]{0pt}{0pt}}

% Here it is: the code that adjusts justification and spacing around caption.
\makeatletter
% This does spacing around caption.
\setlength{\abovecaptionskip}{6pt}   % 0.5cm as an example
\setlength{\belowcaptionskip}{6pt}   % 0.5cm as an example
% This does justification (left) of caption.
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1: #2}%
  \ifdim \wd\@tempboxa >\hsize
    #1: #2\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}
\makeatother

\begin{document}
\setcounter{table}{4}
\begin{table}[h!b!p!]
\caption{Table (modified placement of caption)}
\begin{tabular}{lll}
\hline
% \T and \B would not work if it is placed here (needs to go inside cell)
Alphabet Character \T \B & Vowel & Number \\
\hline
A \T & Yes & 1 \\
B & No & 2 \\
C \B & No & 3 \\
\hline
\end{tabular}
\label{table5}
\end{table}
\end{document}
https://www.msu.edu/~harris41/latex_tablespacing5.png
也可用
\usepackage[justification=justified,singlelinecheck=off]{caption}
即可,参考http://bbs.chinatex.org/forum.php?mod=redirect&tid=5144&goto=lastpost#lastpost

参见:https://www.msu.edu/~harris41/latex_tablespacing.html

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有