9

I realise that this is somewhat of a special question, but is it possible to have regular characters in formulas, where the left half is colored e.g. in red and the right half is colored in blue, similar to the image below?

Character with two colors as desired

17

I'm not sure what this would be used for, but the only method I see is to typeset two copies of the same glyph, clipped and differently colored.

\documentclass{article}
\usepackage{trimclip,xcolor}

\newcommand{\Atwo}{%
  \mbox{%
    \def\Ahalf##1{\dimexpr.5\width ##1 0.025em\relax}
    \textcolor{red}{\clipbox{0 0 {\Ahalf+} 0}{A}}%
    \textcolor{blue}{\clipbox{{\Ahalf-} 0 0 0}{A}}%
  }%
}

\begin{document}
\Atwo
\end{document}

enter image description here

The little correction depends on the character: the vertex of the A doesn't lie at the exact half.

The risk of optical effects is very big: here the horizontal stem doesn't seem to connect properly, but just because of the choice of the colors.

  • What do you mean by optical effect? There actually is a bright line between the two colors, it's not just an optical illusion. – Overv Sep 17 '14 at 18:08
6

Why not with tikz (I know for sure... it is heavy).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\Atwo}[3][A]{%
  \begin{tikzpicture}
    \begin{scope}
      \node[inner sep=0pt,outer sep=0pt] (a) {\phantom{#1}};
      \clip (a.south west) rectangle ($(a.north)-(0.5\pgflinewidth,0)$);
      \node[inner sep=0pt,outer sep=0pt,text=#2]  {#1};
    \end{scope}
    \clip (a.south east) rectangle ($(a.north)-(0.5\pgflinewidth,0)$);
      \node[inner sep=0pt,outer sep=0pt,text=#3]  {#1};
  \end{tikzpicture}
}

\begin{document}
\Atwo{blue}{red} \Atwo[B]{green}{magenta}
\end{document}

enter image description here

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.