[Tex/LaTex] How to have automatic line breaks in cvitem within cventry in moderncv

moderncv

I would be really grateful, if anybody could help with this. If I compile the code (see MWE below) the text that is written in the second argument of cvitem continues beyond the right margin until the very end of the paper. What do I need to do in order to have automatic line breaks in the second argument of \cvitem?

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue}
\usepackage[scale=0.75]{geometry}
\AtBeginDocument{\hypersetup{colorlinks,linkcolor=cyan,urlcolor=cyan}}


\firstname{Jane}
\familyname{Doe}
\title{Curriculum Vitae}
\address{Street}{City}{}
\mobile{Number}
\email{email}

\begin{document}
\makecvtitle

\section{Education}
\cventry
{2020--2025}
{Degree}
{University}
{Location}
{Some info including a link in my real document. The automatic linebreak works here, but not below}
{\cvitem{Item 1}{This is the description of item 1 and it is very long so I need an automatic linebreak here so the text doesn't go beyond the linewidth.}
\cvitem{Item 2}{This is the description of item 2 and it is very long so I need an automatic linebreak here which I don't know how to create.}
\cvitem{Item 3}{This is the description of item 3 and it is even longer and spans across multiple lines so I need an automatic linebreak so the text doesn't go beyond the linewidth, but I don't know how to create this.}
}

\end{document}

Best Answer

The line break does happen automatically. The problem is that you are missing an argument to \cventry, then it takes the \cvitems as argument.

From moderncv's GitHub page, the arguments to \cventry are:

\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description} % arguments 3 to 6 can be left empty

and you didn't have \textit{Grade}. You must have this argument, even if empty ({}).

I also removed the braces that were grouping the `\cvitem`s.

If you want to change the alignment of the \cvitems you should, instead, increase the value of \hintscolumnwidth and decrease that of \maincolumnwidth. The \cvitems are typeset using a tabular with two columns each with one of those two widths.

For example, to make indentation of Item X be 4cm:

\setlength{\hintscolumnwidth}{4cm}% The width of the "hints" column
\setlength{\maincolumnwidth}{\dimexpr\linewidth-\hintscolumnwidth-\separatorcolumnwidth}% Recompute the size of the remaining text.

enter image description here

Compilable MWE:

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue}
\usepackage[scale=0.75]{geometry}
\AtBeginDocument{\hypersetup{colorlinks,linkcolor=cyan,urlcolor=cyan}}

\firstname{Jane}
\familyname{Doe}
\title{Curriculum Vitae}
\address{Street}{City}{}
\mobile{Number}
\email{email}

\begin{document}
\makecvtitle

\section{Education}

\cventry
{2020--2025}
{Degree}
{University}
{Location}
{\textit{Grade}}% Missing this
{Some info including a link in my real document. The automatic linebreak works here, but not below}

\setlength{\hintscolumnwidth}{4cm}
\setlength{\maincolumnwidth}{\dimexpr\linewidth-\hintscolumnwidth-\separatorcolumnwidth}

\cvitem{Item 1}{This is the description of item 1 and it is very long so I need an automatic linebreak here so the text doesn't go beyond the linewidth.}
\cvitem{Item 2}{This is the description of item 2 and it is very long so I need an automatic linebreak here which I don't know how to create.}
\cvitem{Item 3}{This is the description of item 3 and it is even longer and spans across multiple lines so I need an automatic linebreak so the text doesn't go beyond the linewidth, but I don't know how to create this.}

\end{document}