我对 harvard-thesis 模板版本 0.4 中的表格有一个问题。我无法使用 p、m、b 等列类型甚至自定义列类型来设置列宽。如果我将宽度设置为任何列,则无论我使用的值是什么,该列都会填充整个文本宽度。
我正在使用 xelatex 构建
文件内容harvard-thesis.cls
:
% https://github.com/TruePath/LaTeX-template-for-Harvard-dissertation/blob/master/harvard-thesis.cls
\NeedsTeXFormat{LaTeX2e}
%################################################################################
%################################## harvard-thesis.cls starts here ##############
%################################################################################
\ProvidesClass{harvard-thesis}[2012/04/05 v0.4 Harvard University Thesis Class]
\LoadClass[12pt, oneside, letterpaper]{book}
\RequirePackage{graphicx}
\RequirePackage{hyperref}
\RequirePackage{listings}
\RequirePackage{afterpage}
\hypersetup{ linktocpage, colorlinks,
citecolor=Crimson, filecolor=black, linkcolor=black,
urlcolor=Crimson, }
\lstset{ float=h, frame=single,
basicstyle=\scriptsize, breaklines=true,
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}
\hookrightarrow\space}}
}
\RequirePackage[title,titletoc]{appendix}
\usepackage{lipsum}
\usepackage{array,etoolbox}
\preto\tabular{\setcounter{magicrownumbers}
{0}
}
\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}
\arabic{magicrownumbers}
}
\usepackage{makecell}
\usepackage[colorinlistoftodos, textwidth=4cm, shadow]{todonotes}
\RequirePackage[centertags]{amsmath}
\RequirePackage{amssymb}
\RequirePackage[numbers,comma,sort&compress]{natbib}
\RequirePackage[small, md, sc]{titlesec}
\RequirePackage[tight,nice]{units}
\RequirePackage{verbatim}
\RequirePackage{textcomp}
\RequirePackage{color}
\definecolor{Crimson}
{rgb}
{0.6471, 0.1098, 0.1882}
\RequirePackage{url}
\RequirePackage[titles]{tocloft}
\setcounter{tocdepth}
{1}
\renewcommand{\cftchapfont}
{\normalsize \scshape}
\renewcommand\bibname{References}
\renewcommand\listfigurename{Listing of figures}
\RequirePackage{pdfsync}
\usepackage[closeFloats, noSeparatorLine]{fltpage}
\RequirePackage{afterpage}
\usepackage{float}
\synctex=1 \RequirePackage{bibentry}
\nobibliography* \RequirePackage{lettrine}
\RequirePackage[width=5in, letterpaper]{geometry}
\RequirePackage{fancyhdr}
\pagestyle{plain}
\RequirePackage[palatino]{quotchap}
\definecolor{chaptergrey}
{rgb}
{0.6,0,0}
\RequirePackage{titling}
\RequirePackage{setspace}
\RequirePackage{booktabs,tabularx}
\RequirePackage[labelfont={sf,bf,small}
,textfont={sf,small}
,justification=RaggedRight,margin=0pt, figurewithin=section, tablewithin=section]{caption}
\onehalfspacing \parindent 12pt \RequirePackage{mathspec}
\RequirePackage{graphicx}
\RequirePackage{enumitem}
\usepackage[no-sscript]{xltxtra}
\newcommand{\add}
[1]{\textcolor{orange}
{\ul{#1}
}
}
\newcommand{\remove}
[1]{\textcolor{red}
{\textst{#1}
}
}
\newcommand{\change}
[2]{\textcolor{red}
{\textst{#1}
}
\textcolor{green}
{\ul{#2}
}
}
\newcommand{\hide}
[1]{}
\RequirePackage{xunicode,soul}
\def\degreeyear#1{\gdef\@degreeyear{#1}
}
\def\degreemonth#1{\gdef\@degreemonth{#1}
}
\def\degree#1{\gdef\@degree{#1}
}
\def\advisor#1{\gdef\@advisor{#1}
}
\def\department#1{\gdef\@department{#1}
}
\def\field#1{\gdef\@field{#1}
}
\def\university#1{\gdef\@university{#1}
}
\def\universitycity#1{\gdef\@universitycity{#1}
}
\def\universitystate#1{\gdef\@universitystate{#1}
}
\renewcommand{\maketitle}
{ \singlespacing \thispagestyle{empty}
\vspace*{\fill}
\vspace{150pt}
\begin{center}
\Huge \textcolor{Crimson}
{\textit{\thetitle}
}
\normalsize \\ \sc \vspace{100pt}
a dissertation presented \\ by\\ \theauthor\\ to\\ The \@department\\ \vspace{12pt}
in partial fulfillment of the requirements\\ for the degree of\\ \@degree\\ in the subject of\\ \@field\\ \vspace{12pt}
\@university\\ \@universitycity, \@universitystate\\ \@degreemonth\ \@degreeyear \end{center}
\vspace*{\fill}
}
\newcommand{\copyrightpage}
{ \newpage \thispagestyle{empty}
\vspace*{\fill}
\sc \noindent \copyright~\textit{\@degreeyear \hspace{3pt}
~- \theauthor}
\\ \noindent All rights reserved. \vspace*{\fill}
\newpage \rm }
\newcommand{\abstractpage}
{ \newpage \pagenumbering{roman}
\setcounter{page}
{3}
\pagestyle{fancy}
\lhead{Thesis advisor: \@advisor}
\rhead{\@author}
\renewcommand{\headrulewidth}
{0.0pt}
\begin{center}
\vspace*{1pt}
\Large \textcolor{Crimson}
{\textit{\@title}
}
\normalsize\\ \vspace*{15pt}
\sc Abstract \\ \rm \end{center}
\doublespace \input{frontmatter/abstract}
\doublespace \newpage \lhead{}
\rhead{}
\cfoot{\thepage}
\onehalfspacing }
\newcommand{\dedicationpage}
{ \pagestyle{fancy}
\newpage \thispagestyle{fancy}
\vspace*{\fill}
\sc \noindent \input{frontmatter/dedication}
\vspace*{\fill}
\newpage \rm }
\newcommand{\authorlist}
{ \pagestyle{fancy}
\newpage \thispagestyle{fancy}
\chapter*{Author List}
\noindent \input{frontmatter/authorlist}
\newpage \rm }
\newcommand{\acknowledgments}
{ \chapter*{Acknowledgments}
\noindent \input{frontmatter/thanks}
\vspace*{\fill}
\newpage \setcounter{page}
{1}
\pagenumbering{arabic}
}
\providecommand\newthought[1]{ \addvspace{1.0\baselineskip plus 0.5ex minus 0.2ex}
\noindent\textsc{#1}
}
\usepackage{tikz}
%################################################################################
%################################## harvard-thesis.cls ends here ##############
%################################################################################
示例文档(必须使用 XeLaTeX 编译):
\documentclass{harvard-thesis}
\begin{document}
\pagestyle{plain}
\begin{table}
\scriptsize \caption{My table}
\label{table1}
\centering \begin{tabular*}
{\textwidth}
{|c|c|c|p{.3\textwidth}
|p{5cm}
|}
\hline 1 & 2 & 3 & 4 & consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Suspendisse id velit vitae ligula volutpat condimentum. Aliquam erat volutpat. Sed quis velit. Nulla facilisi. Nulla libero. Vivamus pharetra posuere sapien. Nam consectetuer. Sed aliquam, nunc eget euismod ullamcorper, lectus nunc ullamcorper orci, fermentum bibendum enim nibh eget ipsum. Donec porttitor ligula eu dolor. Maecenas vitae nulla consequat libero cursus venenatis. Nam magna enim, accumsan eu, blandit sed, blandit a, eros.\\ \hline \end{tabular*}
\bigskip \caption{With \texttt{@{\string\extracolsep\{\string\fill\}
\}
}
}
}
\begin{tabular*}
{\textwidth}
{@{\extracolsep{\fill}
}
cccp{.3\textwidth}
p{5cm}
@{}
}
\hline 1 & 2 & 3 & 4 & consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Suspendisse id velit vitae ligula volutpat condimentum. Aliquam erat volutpat. Sed quis velit. Nulla facilisi. \\ \hline \end{tabular*}
\end{table}
\end{document}
harvard-thesis.cls 最初来自 Jordan 这里https://github.com/suchow/Dissertate/blob/master/Dissertate.cls
但似乎已经更新。我已将其内容包含在代码中。
答案1
(注意:在 OP 发布有问题的论文类的代码后,我已经彻底修改了这个答案。)
感谢您发布您使用的论文类的代码。事实证明,这个类文件加载了包pdfsync
,这会导致各种问题。在我之前一篇题为桌子太宽了,我写了以下内容:
该软件包的用户指南pdfsync
建议
如果与其他软件包发生严重冲突,请尝试
\usepackage[novbox]{pdfsync}
果然,添加该novbox
选项可以解决眼前的问题。
说实话,我对这个软件包了解不够多,pdfsync
无法告诉你是否有更好的解决方案。引用软件包用户指南的“Bugs”部分:
pdfsync
使用极其[敏感]的代码。您不应pdfsync
在最终文档上使用,因为它可能会显著改变布局(不同的分页符/换行符是最明显的变化)。
这并不是最自信或最能激发信心的言论,不是吗?
回到你的文档:你的论文类似乎没有理由加载这个包。因此,我强烈建议你删除该语句\RequirePackage{pdfsync}
。如果删除该语句,修改后的tabular*
环境可以正常编译。