我想通过测量标题长度(实际上是高度)来调整论文类中标题后的垂直间距。为了实现此目的,我将标题放在一个框中并计算该框的总高度。
首先,定义标题及其样式的命令:
\newcommand{\UL@maintitle}{}
\newcommand{\titre}[1]{\renewcommand{\UL@maintitle}{#1}}
\newcommand*{\UL@fonttitle}{\normalfont\huge\bfseries\sffamily}
接下来是标题框:
\newsavebox{\UL@titlebox}
\sbox{\UL@titlebox}{%
\begin{minipage}{\textwidth}
\centering%
\UL@fonttitle\UL@maintitle\par
\end{minipage}}
最后计算盒子的总高度:
\newlength{\UL@titleboxtotht}
\setlength{\UL@titleboxtotht}{\dimexpr\ht\UL@titlebox+\dp\UL@titlebox}
这在 document ( .tex
) 文件中运行良好。我得到的结果\UL@titleboxtotht
是 48.48pt。使用 class ( .cls
) 文件中定义的上述命令,我无法获得我正在寻找的尺寸;我只得到\UL@titleboxtotht
2.73pt。似乎从未评估过框的实际内容。有什么想法吗?
答案1
你必须将测量推迟到知道标题的时候,也就是你正在扩展的时候\pagetitre
;所以我想说
%% Here we play with the title (and subtitle)
\newsavebox{\UL@titlebox}
\newsavebox{\UL@subtitlebox}
\newlength{\UL@titleboxtotht}
\newlength{\UL@subtitleboxtotht}
\newcommand{\UL@measuretitle}{%
\setbox\UL@titlebox=\vbox{\centering\UL@fonttitle\UL@maintitle}
\setlength{\UL@titleboxtotht}{\dimexpr\ht\UL@titlebox+\dp\UL@titlebox}
%% Repeat above commands for subtitle, if there is one
\ifthenelse{\boolean{UL@hassubtitle}}{%
\setbox\UL@subtitlebox=\vbox{\centering\UL@fontsubtitle\UL@subtitle}
\setlength{\UL@subtitleboxtotht}{\dimexpr\ht\UL@subtitlebox+\dp\UL@subtitlebox}}
{}%
}
%% Adjust spacing between title and "doc id" depending on height of
%% the title and subtitle block
\newlength{\UL@spacing}
\setlength{\UL@spacing}{90pt}
%% Define analogue of the \titlepage command
\newcommand{\pagetitre}{{%
\clearpage
\thispagestyle{empty}
\SingleSpacing\setlength{\parskip}{0pt}
\centering
\UL@fontbase
%%%% COMPUTE THE DIMENSIONS
\UL@measuretitle
\addtolength{\UL@spacing}{-\UL@titleboxtotht}
\addtolength{\UL@spacing}{-\UL@subtitleboxtotht}
%%%%
\ifthenelse{\UL@typenum > 1}{\vspace*{0pt}\par}{%
\includegraphics[height=40px,keepaspectratio=true]{ul_p}\par}
\vspace{72pt}
\box\UL@titlebox
\vspace{\baselineskip} %%%% SOME SPACE BETWEEN TITLE AND SUBTITLE
\box\UL@subtitlebox
\vspace{\UL@spacing}
\UL@docid
\vspace{72pt}
{\UL@fontauthor\UL@author}\par
\UL@details
\vfill
{\textcopyright} \UL@author, \UL@year\par
\clearpage
}}