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.

magyar
  • 43
  • 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 07 '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 07 '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 07 '15 at 14:20
  • One file head=10cm the other head=11cm. – Johannes_B Jan 07 '15 at 15:01
  • Hmmm, that was a typo from some of the many attempts at my working around this. The exact same issue occurs when head=10cm on both. – magyar Jan 07 '15 at 19:10
  • Workaround discovered (see above) but it makes absolutely no sense to me and defeats the purpose of defining a new class. – magyar Jan 07 '15 at 20:04
  • Why does it defeat the purpose? That is, why do you want to not just use a distinct, custom class? Why do you want to do something equivalent in the preamble? I'm trying to get a sense of what your purpose is in order to properly understand the problem. Right now, I can see why you have an outstanding question (why does this work?!) but not why you have an outstanding problem. – cfr Jan 07 '15 at 21:15
  • 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 07 '15 at 21:26
  • Finally! Yes, the answer I was looking for was putting \AtBeginDocument{...} in the .cls file. Kind of confused as to why exactly (I'm looking at several example classes that do not use \AtBeginDocument{...} for the exact same font sizing commands I use). Also thank you for correcting my usage of \sf. – magyar Jan 07 '15 at 22:00
  • @cfr Wanna write up an anser? :-) – Johannes_B Jan 08 '15 at 09:47
  • Yes, I will write up an answer for this. Just want to experiment around a bit more first (and finish my poster). – magyar Jan 08 '15 at 10:29
  • @magyar The suggestion was that I write an answer (because my comment seems to have been useful to you). Hopefully that will be helpful? – cfr Jan 08 '15 at 15:38
  • @Johannes_B Done ;). – cfr Jan 08 '15 at 16:00

1 Answers1

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.

cfr
  • 198,882
  • pt is fixed, em really is dependant of the font size. :-) – Johannes_B Jan 08 '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 08 '15 at 17:10