As per the title, I'm trying to draw an electric dipole while utilizing Cambria Math as my math font, in LuaLaTeX. Here's the MWE of my code:
\documentclass{standalone}
\usepackage{unicode-math}
\setmathfont{Cambria Math}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[gray] (0, 0) -- (4, 0);
\node[red, draw, circle] at (0, 0) {$+$};
\node[blue, draw, circle] at (4, 0) {$-$};
\end{tikzpicture}
\end{document}
As indicated by the gray line, the + and the - are not on the same line. I've tried many things, including different node anchors, setting text height and text depth, et cetera however I've not been able to get them properly aligned.
The same does not happen with the default math font, which you can see if you compile the MWE without the two lines concerning Cambria Math.
Does anybody have any idea how to do this? Thank you all in advance.
EDIT: I've tried out a few of the solutions mentioned in the comments, specifically with CambriaMath as some only seem to work without it, and here are the results of the following MWE (yes, i had fun with the colors):
\documentclass{standalone}
\usepackage{unicode-math}
\setmathfont{Cambria Math}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[every node/.style={draw, circle}]
\draw[help lines] (-1em, 1em) grid (4cm+1em, -3cm-1em);
\node[red, minimum width=1em] at (0, 0) {$+$};
\node[blue, minimum width=1em] at (4, 0) {$-$};
\node[orange, inner sep=1pt, anchor=mid] at (0, -1) {\strut$+$};
\node[green, inner sep=1pt, anchor=mid] at (4, -1) {\strut$-$};
\node[olive, minimum width=2em] at (0, -2) {$+$};
\node[purple, minimum width=2em] at (4, -2) {$-$};
\node[cyan] at (0, -3) {$+$};
\node[magenta] at (4, -3) {$-$\vphantom{$+$}};
\end{tikzpicture}
\end{document}
As can be seen in the image, the only method that seems to work with CambriaMath is the \vphantom{+}
one mentioned in the comments below.
\documentclass{standalone} \usepackage{unicode-math} \setmathfont{Cambria Math} \usepackage{tikz} \begin{document} \begin{tikzpicture}[C/.style = {circle, draw=#1}] \draw[gray] (0, 0) -- (4, 0); \node[C=red] at (0, 0) {$+$}; \node[C=blue] at (4, 0) {$-\vphantom{+}$}; \end{tikzpicture} \end{document}
\strut
adds a bit more depth that in the last case (cyan and magenta symbols), which is why they are a bit shifted upwards in the circle. You can adjusttext depth
to tackle this.text depth
and using\vphantom
, but both methods seem to be equally valid.\vphantom{$+$}
to the nodes without explicitly typing it in, you can create a style and add the optionexecute at begin node={\vphantom{$+$}}
.