Go to page:

Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

ModernCVClassIssues

Categories: CV, moderncv, example
<< CV Bruce Pourciau | Page list | BigFigureOrTable >>

How to Correct a Few Flaws in the LyX Output Using the moderncv Class

As of LyX version 1.5.2, LyX has a couple of problems generating correct PDF output for the popular moderncv document class [CTAN]. The first issue discussed below is easily fixed by a workaround; the second requires hacking the style file. These are both minor edits, but they correct noticeable flaws that affect the impression the CV will make.

Dropped labels for first entries in sections

Note: This problem is fixed in version 0.7 of moderncv, and in LyX 1.5.7

Note the dropped labels (2003-present and Mon Year-Mon Year) in the Education and Professional Experience sections here (LyX file here). This is the what you get with a standard use of the class in LyX. We need to move those labels up to the proper alignment.

This problem has to do with how LyX handles the \section{} command; it puts extra blank lines in the source TeX code after the \section{} command and before the first \cventry{}. Each new section in moderncv starts a two-column longtable with a heading line. The section command ends by using \\[1ex] to start a new row of the table, positioning the "cursor" in the left column. The \cvline command, which is used to format the next entry, checks a boolean flag to see if this is the first line of the section and, if not, starts a new row with another \\. The problem is that LyX inserts a couple of blank lines between the end of the section command and the \cvline command (for source code readability); those blank lines are interpreted as a \par and become part of the left column entry of the first table row after the heading. It only happens in the first entry after a section starts, because for other entries the first-line flag is false and \\ is inserted after any blank lines LyX stuck in.

The simple workaround involves some ERT (raw LaTeX code) in LyX. Remove the Section header (the entire environment) and the first entry (ditto) and put them into a single ERT box. The relevant code to put in ERT here is:

\section{Education}

\cventry{2003--present}{Ph.D., How to Study Stuff}{University}{School}{City}{Dissertation title: \emph{Learning by Osmosis -- It Really Works} (Major advisor: Dr. I. Wanna Study)}

These entries can go into the same box on two lines, one below the other. The easy way to achieve this is activate "View source", focus the desired "Section", copy the latex code from the "source buffer", remove the "Section environment", create a "Standard" environment, there paste the code into an ERT, then follow the sequence for the first \cventry or \cvitem.

Note that the label for the Education section is fixed here (LyX file here).

In case you're wondering, you cannot edit the LaTeX source in LyX to remove the blank lines and fix this problem. And, if you export the LaTeX source, edit the blank lines out in the .tex file and then reopen the file in LyX, it will re-insert them (as well as cause other problems).

You CAN accomplish the fix by exporting the LaTeX code, removing the blank lines in the .tex file, and running pdflatex on the file separately (as is required to accomplish Issue #2 below). However, note that line breaks specified in LyX will be missing (and for CVs more than one page, you'll almost always need some to get things the way you want them). I was not able to use \newpage or \pagebreak to create them, but some cleverly placed \vspace commands should push things down where needed.

For our simple example, the labels for both errant sections are easily corrected in this way; shown here (TeX file here). (Using the standard style file for the classic theme, see Issue #2.)

Formatting the header of the CV

Two minor issues related to the formatting of the CV header (name/title and address area). Both require hacking the style file, but are very easy.

Expanding the area in the upper right to accommodate more stuff

If you don't intend to put a photo in the upper right (as here: http://tug.ctan.org/get/macros/latex/contrib/moderncv/examples/template_en_classic_green.pdf), it's nice to use more of the white space at the top to include a web address or other information.

For example, a long place name would get wrapped a lot using the standard style file, as shown here. The same thing would happen if you used a web address in this area.

A simple change to one line of the style file (moderncvthemeclassic.sty) fixes this. You'll need to make a copy of the style file and edit it. Preserve the old one in its original location in your TeX distribution to avoid complications. You can put the edited style file in the same directory as the TeX file that you'll run pdflatex on, and pdflatex will find it there without additional instruction. The TeX file is your CV file; you can make one that looks good in LyX -- except for these issues -- and export the LaTeX from LyX to edit. (NOTE: You can edit the style file where it resides and LyX will use it, which is a solution that allows all PDF generation from LyX. However, I prefer the external processing. If you update the moderncv LaTeX package, it might overwrite your edits.)

Start by changing the name of the style file that you'll edit to something like moderncvthemeclassichack.sty. Then edit the TeX file for the CV to indicate that it will use your edited style file. Around line 15 there should be a line that reads something like this:

\moderncvtheme[blue, roman]{classic}

Using our example, you'll change it to this:

\moderncvtheme[blue, roman]{classichack}

The name of the edited style file should correspond to "moderncvtheme" plus whatever is in the curly brackets.

The edit to the style file will be on or around line 122, a line that reads like this:

\begin{minipage}[b]{.225\textwidth}%

Change it to this:

\begin{minipage}[c]{.5\textwidth}%

in order to add more space to the section on the right. Our example here. Notice that the name/title of the CV gets pushed around as well, and may not be satisfactory. A good fix requires one more edit to the style file (next).

Vertically centering the name/title

On or around line 112 will be a line that reads like this:

\begin{minipage}[b]{.525\textwidth}%

Change it to this (same as above):

\begin{minipage}[c]{.5\textwidth}%

Our example here. This may not be entirely correct tinkering for the minipages (e.g., pdflatex generates an error about overflow), but it works. You get the idea if you need to tinker with it some more.

How you generate the PDF from the TeX file and the edited style file will depend on your operating system. For Windows, it's as simple as having both files in the same directory, navigating to that directory from a command prompt, and typing:

pdflatex filename.tex

Once the run completes, press the Up arrow and run the same command another three times in a row (you might only need 2, but do 3 for good measure). The PDF (and three files you don't necessarily need to keep) will be created in the same directory.

Contributors

David Hewitt, Andreas Karlsson (ERT hack for #1), Liviu Andronic, Paul Rubin (explanation for #1), JPaul Rinehimer (hacks to the style file for #2)

CV, moderncv, example

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2008-10-05 02:43 CEST