4

Consider the following example.

\documentclass{report}

\usepackage{color}
\usepackage[percent]{overpic}

\DeclareSymbolFont{extraup}{U}{zavm}{m}{n}
\DeclareMathSymbol{\varheart}{\mathalpha}{extraup}{86}
\DeclareMathSymbol{\vardiamond}{\mathalpha}{extraup}{87}
\renewcommand{\heartsuit}{\color{red} \varheart}
\renewcommand{\diamondsuit}{\color{red} \vardiamond}

\begin{document}
    \begin{overpic}[width=2.5 in,grid,tics=10]{images/Strike.jpg}
        \put (5,93) {\parbox{0.6cm}{\centering \LARGE \textbf{\textit{
            \color{red}3}} \\
            $\heartsuit$
        }}
    \end{overpic}
    \begin{overpic}[width=2.5 in,grid,tics=10]{images/Strike.jpg}
        \put (5,93) {\parbox{0.6cm}{\centering \LARGE \textbf{\textit{
            3}} \\
            $\heartsuit$
        }}
    \end{overpic}
\end{document}

In the first overpic, the 3 is red, and in the second overpic the 3 is black. Unfortunately, by making the 3 red, it appears that the \color{red} command has changed the spacing around the 3 so that it is both higher on the image and also more offset to the right.

How can I make the 3 colored red without impacting its position?

6

Because you have line breaks in the code immediately after each \textbf{\textit{ directive, LaTeX inserts a space. This is evidently not what you want.

You should either terminate the lines with a % (comment) character or omit the line breaks in the first place. Furthermore, as David Carlisle has pointed out in a comment, for the sake of robustness you should also use \textcolor{...}{...} instead of \color{...}.... This is because \color moves the first baseline, whereas \textcolor does not.

The relevant code snippet should therefore either be

\begin{overpic}[width=2.5 in,grid,tics=10]{images/Strike.jpg}
    \put (5,93) {\parbox{0.6cm}{\centering \LARGE \textbf{\textit{%
        \textcolor{red}{3}}} \\
        $\heartsuit$
    }}
\end{overpic}
\begin{overpic}[width=2.5 in,grid,tics=10]{images/Strike.jpg}
    \put (5,93) {\parbox{0.6cm}{\centering \LARGE \textbf{\textit{%
        3}} \\
        $\heartsuit$
    }}
\end{overpic}

or

\begin{overpic}[width=2.5 in,grid,tics=10]{images/Strike.jpg}
    \put (5,93) {\parbox{0.6cm}{\centering\LARGE\textbf{\textit{\textcolor{red}{3}}} \\
                 $\heartsuit$
    }}
\end{overpic}
\begin{overpic}[width=2.5 in,grid,tics=10]{images/Strike.jpg}
    \put (5,93) {\parbox{0.6cm}{\centering\LARGE\textbf{\textit{3}} \\
                 $\heartsuit$
    }}
\end{overpic}
  • 3
    I switched to \textcolor because \color at start of a box moves the first baseline (less important in the default vertical centering, but still...) – David Carlisle Nov 23 '16 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.