7

I'm trying to add a fourth argument to the address command in the moderncv class. I've looked for a solution around the internet and tried a few things including attempting to edit the moderncv class file, but I haven't got anything to work properly. The closest I came was using this method; How can I add a new address line within moderncv style, which did get the end result that I wanted except that the last line of the address (Country) and the phone are on the same line. The code and result it produces are as follows:

\documentclass[12pt,a4paper,sans]{moderncv}
\moderncvtheme[blue]{classic}
\usepackage[scale=0.75]{geometry}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\makecvtitle}{\ifthenelse{\equal{\@addresscountry}{}}}%
{\ifstrempty{\@addresscountry}}{}{}
\makeatother

\firstname{John}
\familyname{Smith}
\title{Curriculum Vitae}
\address{42 Apartment complex}{Street}{City\\Country}
\mobile{0000000000}
\email{email@email.email}

Country and phone on same line

Does anyone have any solution to offer, preferably to add a fourth argument to the command, but I would take an amendment to the above code that would move the country onto its own line? Any help is appreciated.

3
  • See if this helps:tex.stackexchange.com/questions/58586/…. Anyway, by only adding \\ after country I got country and cell on two different lines. But I guess this is not the elegant solution. – Umz Dec 30 '13 at 22:39
  • @Umz , thank you for the response. True, it isn't the most elegant but it does what I need it to. I saw that answer when I was investigating, but it seems too long and complicated for me to apply to my problem, being a slight noob. – davly Dec 30 '13 at 23:03
  • I think trying to replace less rather than more is safer in terms of updates etc. That is, any hack may break unexpectedly when a package is updated but the more stuff you change, the more likely that usually is, other things being equal. And I'm not so clear that shows how to hack the \address command to use a fourth argument. But I'm sure my answer is subject to its own problems! – cfr Dec 30 '13 at 23:08
13

Maybe something like this if I've understood correctly:

\documentclass[12pt,a4paper,sans]{moderncv}
\moderncvtheme[blue]{classic}
\usepackage[scale=0.75]{geometry}
\usepackage{etoolbox}

\makeatletter
\RenewDocumentCommand{\address}{mG{}G{}G{}}{%
  \def\@addressapartment{#1}\def\@addressstreetonly{#2}\def\@addresscity{#3}\def\@addresscountry{#4}%
  \def\@addressstreet{%
  \ifthenelse{\isundefined{\@addressapartment}}{}{\@addressapartment}%
  \ifthenelse{\isundefined{\@addressstreetonly}}{}{\makenewline\@addressstreetonly}%
  }}
\makeatother

\firstname{John}
\familyname{Smith}
\title{Curriculum Vitae}
\address{42 Apartment complex}{Street}{City}{Country}
\mobile{0000000000}
\email{email@email.email}

\begin{document}
    \makecvtitle
\end{document}

Hacked moderncv output

6
  • That's exactly what I was looking for, thank you very much! I tried to edit the class file directly similar to that but I didn't know what to do with the {mG{}G{}G{}} part. – davly Dec 30 '13 at 23:08
  • I actually guessed that bit. I'm about to go try to find some documentation. I'm guessing that each bit represents one argument because when I just used {mG{}G{}} it complained that #4 was not permitted. So I guessed that m is a mandatory argument and that G is optional with {} giving the default if you don't define it. So I just added another one and it seemed to work. But I want to know more as I've not come across \NewDocumentCommand before. – cfr Dec 30 '13 at 23:10
  • That is roughly what it is doing according to the xparse documentation. Now I've read the documentation I vaguely remember coming across this before but I can't say I have a real feel for the possibilities offered by that package. By the way, never edit the class file directly. If you really need this, copy the file to your personal texmf tree, rename it and then edit the renamed class and use that. Otherwise, your edits will be lost when you update and you may forget and think that your code will produce the same result for somebody with the standard class. – cfr Dec 30 '13 at 23:20
  • I made a backup before I changed it, and when it didn't work, I reverted to the backup just in case I had messed anything else up, but good to know. Thanks again. – davly Dec 30 '13 at 23:32
  • I'm sure this is a basic extension @cfr, but could you point out how I would add an additional (fifth) line? – gammapoint Aug 17 '16 at 19:39

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.