Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to adjust vertical spacing after the title in a thesis class by measuring the title length (actually, height). To achieve this, I put the title in a box and compute the total height of the box.

First, commands to define the title and its styling:

\newcommand{\UL@maintitle}{}
\newcommand{\titre}[1]{\renewcommand{\UL@maintitle}{#1}}
\newcommand*{\UL@fonttitle}{\normalfont\huge\bfseries\sffamily}

Next, the title box:

\newsavebox{\UL@titlebox}
\sbox{\UL@titlebox}{%
  \begin{minipage}{\textwidth}
    \centering%
    \UL@fonttitle\UL@maintitle\par
  \end{minipage}}

Finally, computation the total box height:

\newlength{\UL@titleboxtotht}
\setlength{\UL@titleboxtotht}{\dimexpr\ht\UL@titlebox+\dp\UL@titlebox}

This works fine in a document (.tex) file itself. I get, say, that \UL@titleboxtotht is 48.48pt. With above commands defined in the class (.cls) file, I cannot get a hold of the dimension I'm looking for; I only get that \UL@titleboxtotht is 2.73pt. It seems the actual content of the box is never evaluated. Any idea?

share|improve this question
    
There is a problem with \setlength statement; improper bracing. Does the class include the calc package? Also, you can only calculate the title dimensions once it has been set. Would you be able to provide a complete minimal example that shows your usage within the special "thesis" class? Also provide a link to the .cls file. –  Werner Jan 12 '13 at 21:31
    
Fixed the bracing; this was not the problem, just bad copy-pasting. Sorry for the noise. No calc package. "... once it has been set": that was my impression, but when/how is it set? When \titlepage is issued? –  Vincent Goulet Jan 12 '13 at 23:32
    
Where is the .cls located? Please provide a link. Also include a complete minimal working example (MWE) of your problem case. It may be related to the code, or the sequence of commands executed. –  Werner Jan 13 '13 at 4:41
    
Ok, I put an edited and minimally commented version of the class file, a MWE and a required image file in a zip archive. FWIW, the current official version of the class is on CTAN. –  Vincent Goulet Jan 13 '13 at 14:52
add comment

migrated from stackoverflow.com Jan 13 '13 at 15:40

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 4 down vote accepted

You have to defer the measurement to when the title is known, which is when you are expanding \pagetitre; so I'd say

%% 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
  }}
share|improve this answer
    
Ah ha! That's the trick! Works exactly as expected, thanks very much! –  Vincent Goulet Jan 13 '13 at 18:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.