First of all, TeX language is not "free form", so there's a big difference between
\newcommand{\pink}[1]{
\colorbox{red!20}{#1}
}
and
\newcommand{\pink}[1]{\colorbox{red!20}{#1}}
In the first case two spaces are added before and after the \colorbox
, because end-of-lines are converted into spaces and they become part of the replacement text. So your first attempt is equivalent to do
\newcommand{\pink}[1]{ \colorbox{red!20}{#1} }
and the source of the spacing is now evident.
However, there's also another catch: \colorbox
adds a padding around the text; its thickness is controlled by the parameter \fboxsep
.
Here is a more complex definition for taking into account a problem that will be clear from the last example:
\documentclass{article}
\usepackage{xcolor}
\newcommand{\reducedstrut}{\vrule width 0pt height .9\ht\strutbox depth .9\dp\strutbox\relax}
\newcommand{\pink}[1]{%
\begingroup
\setlength{\fboxsep}{0pt}%
\colorbox{red!20}{\reducedstrut#1\/}%
\endgroup
}
\begin{document}
laugh\pink{ing}
laugh\pink{ing}
lau\pink{f}ing
lau\begingroup\fboxsep=0pt\colorbox{red!20}{\reducedstrut f}\endgroup ing
\end{document}
I've used \reducedstrut
in order that the colored box does not touch possible other colored boxes in the lines above or below. With \strut
, instead of \reducedstrut
, the colored boxes in the first two lines would merge. Finally, the "italic correction" \/
ensures that the whole contents is covered by the pink background, as it's clear from the last two lines (the last one has the same construction, but without \/
).
Add the following lines in the preamble:
\makeatletter
\@ifpackageloaded{moderncvstyleclassic}{%
\let\oldsection\section%
\renewcommand{\section}[1]{\leavevmode\unskip\vspace*{-\baselineskip}\oldsection{#1}}%
}{%
}
\makeatother
The redefinition of \section
is applied only when you choose the style classic
so if you want to change style, you have no problems.
To have better spacing, now choose -0.5em
instead of -1.2em
when the \cventry
contains lists.
MWE:
\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic} % banking, casual, classic, empty, oldstyle options
\moderncvcolor{blue} % black, blue, green, grey, orange, purple, red options
\usepackage[scale=0.85]{geometry} % default scale=0.7. height= scale * layoutheight
\firstname{John}
\familyname{Doe}
\title{R\'esum\'e} % optional
\makeatletter
\@ifpackageloaded{moderncvstyleclassic}{%
\let\oldsection\section%
\renewcommand{\section}[1]{\leavevmode\unskip\vspace*{-\baselineskip}\oldsection{#1}}%
}{%
}
\makeatother
\begin{document}
\makecvtitle
\section{Professional Experience}
\cventry{Year--Year}{Intern}{Company}{Nowhere}{State}{
\begin{itemize}
\item Did something important here.
\end{itemize}}
% problem with vertical space-------------------------------------------------
\section{Education}
\cventry{06/11}{Bachelor of Arts \LaTeX}{University of \LaTeX}{}{\textit{4.0/4.0}}{}
%\vspace*{-6mm} %this will fix vertical spacing for \moderncvstyle{classic}, but create vertical spacing issues for other \moderncvstyle{xyz}.
% problem with vertical space -------------------------------------------------
\section{Skills}
\cvitem[-0.5em]{}{
\begin{itemize}
\item \LaTeX
\end{itemize}}
%\vspace*{-6mm} %this will fix vertical spacing for \moderncvstyle{classic}, but create vertical spacing issues for other \moderncvstyle{xyz}.
\section{Languages}
\cvitem[-0.5em]{}{
\begin{itemize}
\item TeX-speak
\end{itemize}}
% \cvitem{}{job description text here}
\end{document}
Output:
Best Answer
\textquotedblleft
and\textquotedblright
(as well as most other commands without arguments, which do not use the xspace package) gobble their following space (as if the name was\textquotedblleft␣
). To get a space character there, you need to use\textquotedblleft{}
and\textquotedblright{}
. You could also use explicit space (e.g.\␣
(slash space) or\hspace{1em}
), but you want the space to be stretchable, dont't you? Alternatively, as suggested by cgnieder, the csquotes package can be used for quotes.