I am looking to create a command that adjusts my page layout, here is a sample:

\pdfpageheight 297mm
\pdfpagewidth 210mm
\newgeometry{lmargin=31.5mm, rmargin=31.5mm, includemp, marginparsep=5mm, marginparwidth=52mm}

It basically just adjusts the margins to have a 52mm margin on the right hand side, and then I have other layouts too, which I all call with different commands, such as \margin, \nomargin, \marginlandscape, and this brings me to my problem.

Ideally, I would want to only have to use one command, such as


but I have no idea how to create such a command, I've tried to do it myself and I've looked all over the place, but can find no answers. So, how do I code a newcommand that would give me the desired results?


You can use the same mechanism as used for \pagestyle (using its original simpler definition without error checking here)

\def\mypagestyle#1{\csname myps#1\endcsname}

then just define \mypsmargin \mypsnomarginlandscape to do whatever ever you want and then you can use the syntax


to call the internal command \mypsnomarginlandscape

| improve this answer | |
  • I'm not sure I quite understand, sorry, I'm new to Tex. Where would I define nomargin, etc? And then how would I add a new definition, of say nomarginlandscape? – akuritsu Jul 10 '13 at 6:31
  • Just change the definition in your question from \newcommand{\margin}{ to \newcommand{\mypsmargin}{ then \mypagestyle{margin} will work. Add similar definitions at the same place – David Carlisle Jul 10 '13 at 13:27

This might be overkill, but I normally use the xstring package for these sort of thing:

Further Enhancements:

  • This only tests for margin but this could easily be extended to support multiple values. If there is just two cases then simply add and another \IfStrEq, but for more than two options I would recommend using the IfStrEqCase See for instance Checking if a macro expands to one of two given strings.



       Setting "#1": % Adjust settings here
       \newgeometry{lmargin=31.5mm, rmargin=31.5mm, includemp, marginparsep=5mm, marginparwidth=52mm}
       Setting "#1": % Adjust settings here
       \newgeometry{lmargin=31.5mm, rmargin=31.5mm, includemp, marginparsep=5mm, marginparwidth=52mm}    }%


| improve this answer | |
  • That looks good, but do you know of a way where I do not need any extra packages? Thanks for the prompt response though. – akuritsu Jul 10 '13 at 0:54

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.