1

I'm trying to change the margins manually from the file bk10.clo, where I want that in twoside mode the margins are symmetric to 3cm and in oneside mode the margins are top = 3cm, left = 4cm, right = 2cm, bottom = 3cm.

This is my code but I think it's not right.

\if@twocolumn
    \setlength\marginparsep {10\p@}
\else
    \setlength\marginparsep{7\p@}
\fi
\setlength\marginparpush{5\p@}
\if@compatibility
    \setlength\oddsidemargin   {.5in}
    \setlength\evensidemargin  {1.5in}
    \setlength\marginparwidth {.75in}
  \if@twocolumn
    \setlength\oddsidemargin  {30\p@}
    \setlength\evensidemargin {30\p@}
    \setlength\marginparwidth {48\p@}
  \fi
\else
  \if@twoside
    \setlength\@tempdima        {\paperwidth}
    \addtolength\@tempdima      {-\textwidth}
    \setlength\oddsidemargin    {.4\@tempdima}
    \addtolength\oddsidemargin  {-1in} 
    \addtolength\oddsidemargin  {-0.3in} % we add -0.3in to get 3cm of left side margin
    \setlength\marginparwidth   {.6\@tempdima}
    \addtolength\marginparwidth {-\marginparsep}
    \addtolength\marginparwidth {-0.4in}
    %\addtolength\textwidth         {1.36in} % we add 1.36in to get 3cm of right side margin
  \else
    \setlength\@tempdima        {\paperwidth}
    \addtolength\@tempdima      {-\textwidth}
    \setlength\oddsidemargin    {.5\@tempdima}
    \addtolength\oddsidemargin  {-1in}
    \addtolength\oddsidemargin  {-0.28in} % we add -0.28in to get 4cm of left side margin
    \setlength\marginparwidth   {.5\@tempdima}
    \addtolength\marginparwidth {-\marginparsep}
    \addtolength\marginparwidth {-0.4in}
    \addtolength\marginparwidth {-.4in}
    %\addtolength\textwidth     {1.36in} % we add 1.36in to get 2cm of right side margin
  \fi
  \addtolength\textwidth        {1.36in} % we add 1.36in to get 3cm (resp. 2cm) of right side margin in mode twoside (resp. mode oneside). 
  \ifdim \marginparwidth >2in
     \setlength\marginparwidth{2in}
  \fi
  \@settopoint\oddsidemargin
  \@settopoint\marginparwidth
  \setlength\evensidemargin  {\paperwidth}
  \addtolength\evensidemargin{-2in}
  \addtolength\evensidemargin{-\textwidth}
  \addtolength\evensidemargin{-\oddsidemargin}
  \@settopoint\evensidemargin
\fi
\if@compatibility
  \setlength\topmargin{.75in}
\else
  \setlength\topmargin{\paperheight}
  \addtolength\topmargin{-2in}
  \addtolength\topmargin{-\headheight}
  \addtolength\topmargin{-\headsep}
  \addtolength\topmargin{-\textheight}
  \addtolength\topmargin{-\footskip}     % this might be wrong!
  \addtolength\topmargin{-.5\topmargin}
  \addtolength\topmargin{-0.56in} % we add -0.56in to get 3cm of top margin
  \addtolength\textheight{1in} % we add 1in to get 3cm of bottom margin (from the limit of the page at body)
  \addtolength\footskip{0.066in} % we add 0.066in to get 2cm of bottom margin (from the limit of the page at footer)
  \@settopoint\topmargin
\fi

Thanks in advance.

EDIT: Using

\makeatletter
\setlength{\oddsidemargin}{-1in} 
\if@twoside
\addtolength{\oddsidemargin}{3cm} 
\else
\addtolength{\oddsidemargin}{4cm}
\fi 
\setlength{\evensidemargin}{\oddsidemargin} 
\setlength{\textwidth}{\paperwidth}
\addtolength{\textwidth}{-6cm} % left+ right margins
\setlength{\topmargin}{-1in}
\addtolength{\topmargin}{-\headheight}
\addtolength{\topmargin}{-\headsep} 
\addtolength{\topmargin}{3cm}
\setlength{\textheight}{\paperheight}
\addtolength{\textheight}{-6cm} % top + bottom margins
\makeatother

with geometry

without geometry

I appreciate any help...

  • 6
    Why? Why don't you want to use packages? Why have you tagged this tex-core when it seems to have nothing to do with it? – cfr Aug 26 '18 at 1:49
  • 2
    Why would adding -0.3in get you 3cm left of anything? You are 0.3in to the left of the left edge of the paper as far as I can tell. However, without complete code, it is hard to say. Add \usepackage[pass,verbose]{geometry} to see what's happening. Better yet, use geometry to do it. – cfr Aug 26 '18 at 1:52
  • 4
    Somebody else figured out all you are trying to do now and put the result as a nice package. Namely geometry. There is no point in reinventing the wheel. – Johannes_B Aug 26 '18 at 4:14
4

try to understand this

\makeatletter
\setlength{\oddsidemargin}{-1in} 
\if@twoside
\addtolength{\oddsidemargin}{3cm} 
\else
\addtolength{\oddsidemargin}{4cm}
\fi 
\setlength{\evensidemargin}{\oddsidemargin} 
\setlength{\textwidth}{\paperwidth}
\addtolength{\textwidth}{-6cm} % left+ right margins
\setlength{\topmargin}{-1in}
\addtolength{\topmargin}{-\headheight}
\addtolength{\topmargin}{-\headsep} 
\addtolength{\topmargin}{3cm}
\setlength{\textheight}{\paperheight}
\addtolength{\textheight}{-6cm} % top + bottom margins
\makeatother
| improve this answer | |
  • Thanks for your help. I followed your suggestion but seeing the pdf file you can see some margins regarding the pdf file generated with the geometry package, why its that? – Joan Jan 25 '19 at 21:16
  • I think is for the type of paper, i.e, in book class the paper is letterpaper by default and geometry change it for a4paper (?)... – Joan Jan 25 '19 at 21:23
  • It is always good to load showframe just to see the margins and text/header/footer area. – Sigur Jan 25 '19 at 21:26

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.