4

I've designed a poster layout that will most likely be used again, so I decided to define a new document class using all the settings from my preamble. However, when I compile a document using my newly defined class, the page layout is not identical to the original. I am not a LaTeX beginner, however this is my first time making a document class. I've been stumped on this one for hours.

Original tex:

\documentclass{article}

%        main packages
\usepackage{fancyhdr}

%        core layout                                                          
\usepackage[paperwidth=48in,paperheight=36in,textwidth=112cm,
top=15cm,head=11cm,foot=2cm,bottom=6cm,hcentering]{geometry}
\pagenumbering{gobble}

%        resize fonts and symbols
\usepackage{mathpazo}
\usepackage{textcomp}
\usepackage[scaled=0.95]{helvet}
\renewcommand{\huge}{\fontsize{100pt}{120pt}\selectfont}
\renewcommand{\Large}{\fontsize{64pt}{72pt}\selectfont}
\renewcommand{\normalsize}{\fontsize{36pt}{44pt}\selectfont}

%        header
\newcommand{\header}[2]{\fancyhead[C]{\begin{center}
\begin{sf}
{\textbf{{\huge {#1}}}}\\[1cm]
{\Large {#2}}\\[0.5cm]
{\Large UWEC}
\end{sf}
\end{center}}}

%        footer
\newcommand{\footer}[2]{
\fancyfoot[L]{\vspace{1pt}\normalsize {#1}}
\fancyfoot[R]{\vspace{1pt}\normalsize {#2}}}
\renewcommand{\footrulewidth}{2pt}   

\begin{document}

\header{title}{author}

\footer{advisor}{special thanks to...}

\pagestyle{fancy}
testing

testing

\end{document}

Which results in:

example 1!

New document class:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{testclass}

\LoadClass{article}

%        main packages
\usepackage{fancyhdr}

%        core layout                                                          
\usepackage[paperwidth=48in,paperheight=36in,textwidth=112cm,
top=15cm,head=11cm,foot=2cm,bottom=6cm,hcentering]{geometry}
\pagenumbering{gobble}

%        resize fonts and symbols
\usepackage{mathpazo}
\usepackage{textcomp}
\usepackage[scaled=0.95]{helvet}
\renewcommand{\huge}{\fontsize{100pt}{120pt}\selectfont}
\renewcommand{\Large}{\fontsize{64pt}{72pt}\selectfont}
\renewcommand{\normalsize}{\fontsize{36pt}{44pt}\selectfont}

%        header
\newcommand{\header}[2]{\fancyhead[C]{\begin{center}
\begin{sf}
{\textbf{{\huge {#1}}}}\\[1cm]
{\Large {#2}}\\[0.5cm]
{\Large UWEC}
\end{sf}
\end{center}}}

%        footer
\newcommand{\footer}[2]{
\fancyfoot[L]{\vspace{1pt}\normalsize {#1}}
\fancyfoot[R]{\vspace{1pt}\normalsize {#2}}}
\renewcommand{\footrulewidth}{2pt}  

\endinput

and new tex:

\documentclass{testclass}

\begin{document}

\header{title}{author}

\footer{advisor}{special thanks to...}

\pagestyle{fancy}
testing

testing

\end{document}

that results in:

example 2!

The preamble in example one is identical to the class description in example two, so why is there this spacing difference? Getting pretty frustrated. Thanks in advance.

Alright, so I discovered a workaround, but it makes no sense to me why it makes a difference and defeats the purpose of defining a new class.

If I include the line:

\renewcommand{\normalsize}{\fontsize{36pt}{44pt}\selectfont}

in the document preamble and not the .cls, the layout is identical as it should be.

  • 3
    Honestly speaking your question is too broad for the general audience. If you want my advice, please segregate your questions into smaller problems and post them one at a time. That is likely to get better response. – Masroor Jan 7 '15 at 12:29
  • 3
    This is as noted a lot of code and probably could be cut down to show just the issue at hand. My guess something is using an end-of-class or end-of-file hook which alters the 'timing' of layout changes. (There is a warning from fancyhdr about headheight, but only in the 'own class' case.) – Joseph Wright Jan 7 '15 at 13:10
  • Thanks for the feedback. I simplified my code so that only the specific spacing problem is highlighted, if that helps at all. I was under the impression that I could just move the entire preamble right into a .cls with identical results. – magyar Jan 7 '15 at 14:20
  • One file head=10cm the other head=11cm. – Johannes_B Jan 7 '15 at 15:01
  • 2
    Or is it that you want the preamble format? In that case, try putting the changes to the font sizing commands in \AtBeginDocument{...} in the .cls file so that the code is not triggered in the class itself. What is \begin{sf}...\end{sf} supposed to do? If you mean to switch to sans, you need \sffamily. \sf is deprecated more than 20 years ago and it never was an environment. These are switches - effective until the end of the group. {\sffamily sans text} and serif. – cfr Jan 7 '15 at 21:26
6

\begin{document} issues a \normalsize command which affects the size of units such as em and ex which depend on the standard font size. That is, if you say 50em, this is larger if your document is set with the class option 12pt than it would be if using the default 10pt. See this question for details. I found egreg's answer especially helpful.

I am not sure of the details but I think that when you have the commands in your preamble, the dimensions are being set with the original font size for the document and not the sizes you have specified, whereas when you set them in a class file, they are being set with the customised font size. So the spacing ends up larger with the class than with the preamble.

One way to avoid this is to defer the changes to the font sizes until the beginning of the document so that \normalsize gets executed first, setting the value of pt etc., and the font sizes are only then overridden. You can do this by putting the commands which change the font sizes into \AtBeginDocument{...} in the class file.

Off-topic

  • sf is both long deprecated and never was an environment. \sf was a LaTeX 2.09 command but is deprecated in LaTeX-2e. It was, in any case, a font switch. Instead use either \sffamily which switches the font until the end of the group or \textsf{} which typesets just its argument in sans. If you need the former, but want to limit its effects, you can just surround it by curly brackets e.g. {\sffamily sans text and }back to serif.

  • Note that \usepackage is a preamble command. You should prefer \RequirePackage in a class or package file.

  • pt is fixed, em really is dependant of the font size. :-) – Johannes_B Jan 8 '15 at 16:01
  • @Johannes_B Thanks. I don't know why I always think pts is variable. (It makes no sense to think so.) But now I don't understand why it matters so maybe this is completely the wrong answer anyway. – cfr Jan 8 '15 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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