5

I am using the classic style of the moderncv package and I want to align the right margin of the address box with the right margin of all the other content and get rid of the offset marked in this image:

enter image description here

I can of course use the geometry package to change the margins in total, but whatever I try, the right margin of the address box continues to be shifted compared to the right margin of my cv entries.

By searching this forum I already figured out that I most likely will have to reconfigure the \makecvtitle command, but I am not good enough to understand how to do it without further help... :-/

Here is the minimal example that was used to generate the attached picture (vertical lines were drawn manually for clarity):

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue}
\usepackage[utf8]{inputenc}

%%%% adjust the page margins
\usepackage[scale=0.78, top=2.5cm, bottom=2.5cm, footskip=1cm]{geometry}

% personal data
\name{My}{Name}
\title{My title}
\address{Street}{City}{Country}
\phone[mobile]{1234567890}
\email{e@mail.com}

\usepackage{eurosym}

\begin{document}

\makecvtitle

\section{Education}
\cventry{from -- to}{Student}{This is a very long description of my education and what I have done with the only purpose to completely fill up the lane}{}{}{}

\end{document}
Werner
  • 603,163
Andrea
  • 53

2 Answers2

6

The construction of the CV header - done inside \makecvhead - stores much of its content in boxes:

  • \makecvheaddetailsbox: For address information

  • \makecvheadpicturebox: Picture, if supplied

  • \makecvheadnamebox: Name and title

The construction of \makecvheaddetailbox has a spurious space that ends up on the right of the tabular that contains the addresses - a bug in the package. Typically, spurious spaces are difficult to remove without copying the entire macro and inserting the appropriate % where needed. However, in this case we can slip a non-argument macro after \end{tabular}:

enter image description here

\documentclass[sans]{moderncv}

\moderncvstyle{classic}
\moderncvcolor{blue}

% personal data
\name{My}{Name}
\title{My title}
\address{Street}{City}{Country}
\phone[mobile]{1234567890}
\email{e@mail.com}

\usepackage{etoolbox}
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\makecvhead}{\end{tabular}}{\end{tabular}\relax}{}{}

\begin{document}

\makecvtitle

\section{Education}
\cventry{from -- to}{Student}{This is a very long description of my education and 
  what I have done with the only purpose to completely fill up the lane}{}{}{}

\end{document}
Werner
  • 603,163
3

I looked at the code and found no direct reason for this shift. A work around would be to make a copy of moderncvheadi.sty in your local TeXMF root (you'll have create it if you don't already have one), put it in LocalTeXMF\tex\latex\moderncv\ and modify this file in the following way: replace line 77:

\if@left\begin{tabular}[b]{@{}r@{}}\fi%

with

\if@left\begin{tabular}[b]{@{}r@{\hspace{-0.25em}}}\fi%

enter image description here

Bernard
  • 271,350
  • Great, thank you for this very fast reply! This solution immediately worked on my Windows system (on which I use MikTeX).

    However, as an information for Linux/TexLive users: I could not yet find the moderncvheadi.sty file on my Debian system (and generally, there are far less files in the corresponding folder) but it could simply be that my version is outdated. Also, I have to admit that I am very inexperienced with Linux and that I did not spent too much time on trying to solve the issue under Linux after it was already fixed on Windows -- so it might just be me...

    – Andrea Mar 14 '17 at 15:18
  • @Andrea: There is a spurious space in the code that leads to the mis-alignment. See my answer for the correct solution, and What is the use of percent signs (%) at the end of lines? for a discussion on these issues. – Werner Mar 14 '17 at 15:25