2

I want to draw a a line like that in blue. In my code snippet, i use the variable color1 which is given by moderncv itself.

\documentclass[11pt,a4paper,sans]{moderncv}        

\usepackage{fontenc} 
\usepackage{graphicx} 
\usepackage{xcolor}

\moderncvstyle{casual}                        
\moderncvcolor{blue}                                
\usepackage[scale=0.75]{geometry} 
\name{John}{Doe}

\renewcommand*{\rule}[2]{\def\@rule{\color{color1}{#1}{#2}}}


\begin{document} 
\makecvtitle 
\hbox{
        \hspace*{0.2\textwidth}
        \rule{5pt}{\textwidth}
        \hspace*{0.05\textwidth} 
} 

\end{document}

why does that not work here? When compiling that with latexmk -xelatex $file i just get a plain white site with just the name John Doe on it.

5
  • 2
    Why do you redefine \rule instead of using \textcolor{color1}{\rule{5pt}{\textwidth}}? (And where did you get this curious redefinition?) Apr 3, 2016 at 15:00
  • @UlrikeFischer Ah, I didn't knew this was that simple. Thanks. Would you mind to put you comment into an answer so i can mark it solved?
    – toogley
    Apr 3, 2016 at 15:04
  • But out of curiosity - I would still like to know what was the problem with that redefinition, although my problem is basically solved.
    – toogley
    Apr 3, 2016 at 15:05
  • You are defining \rule to define another command. So why should it print anything? (Beside the fact that you don't know about \makeatletter). Apr 3, 2016 at 15:09
  • @UlrikeFischer Well, i tried to adapt tex.stackexchange.com/a/299974/76157 for my needs. And this answer used the redefinition.
    – toogley
    Apr 3, 2016 at 15:12

2 Answers 2

2

The answer you mention in comments indeed has

\renewcommand*{\opening}[1]{\def\@opening{{\color{color1}#1}}}

but it's a completely different situation. The definition of \opening by moderncv is

\newcommand*{\opening}[1]{\def\@opening{#1}}

which means that the argument to \opening is saved in \@opening for later usage. The redefinition instead saves the argument along with the desired color setting.

The definition of \rule is completely different:

% latex.ltx, line 4984:
\DeclareRobustCommand\rule{\@ifnextchar[\@rule{\@rule[\z@]}}%

Imagine \DeclareRobustCommand like \newcommand. The purpose of the definition is to check whether [ follows and to pass control to the internal command \@rule. There's a fundamental difference between the two cases: \@opening is just a container, \@rule is a macro with arguments which is in charge of producing the rule.

You are instead trying to redefine \@rule and this is unfortunately wrong.

What you should do is to define a new command, because \rule might get used in other situations (perhaps internally, without you knowing). Do

\newcommand{\colorrule}[3][0pt]{\textcolor{color1}{\rule[#1]{#2}{#3}}}

and use \colorrule where you need a colored rule.

0

This works I think.

\documentclass[11pt,a4paper,sans]{moderncv}        
\usepackage{fontenc} 
\usepackage{graphicx} 
\usepackage{xcolor}
\moderncvstyle{casual}                        
\moderncvcolor{blue}                                
\usepackage[scale=0.75]{geometry} 
\name{John}{Doe}

\begin{document} 

\parbox[b]{0.75\textwidth}{%
\hbox{\hspace*{0.2\textwidth}
\color{blue}
\rule{1pt}{\textheight} 
\hspace*{0.05\textwidth}}}  
\vskip-9in  
\vtop{\makecvtitle \hspace{2in}Hello World}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .