4

How can I properly design a symbol, such as \oiint with Tikz?

I've found something like this on the internet

\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\[
\oint\iint
{\tikz \node[draw, ellipse, inner xsep=-3.6pt, inner ysep=-9pt] {$\displaystyle\iint$};}
\]

\end{document}

Which outpouts

enter image description here

and has a vertical misalignment and doesn't work with subscripts. How can I fix this? Also, how can i change the ellipse's thinkness?

7
  • 1
    Just to make sure: you know that there are packages which provide \oiint? May 24 at 13:44
  • 1
    They're all ugly.. I like stix one but I don't want the whole package so I'm trying to reproduce it.
    – Nolord
    May 24 at 13:48
  • 2
    The ellipse's thickness is easily adjusted. Use a different linewidth for the node. Though I would approach this differently by drawing an explicit ellipse instead of using a shape with negative inner seps. May 24 at 14:23
  • 1
    Your code needs \documentclass{article} \usepackage{amsmath} to be compilable, I think. But to solve your problem: add anchor=base, baseline to the \tikz command, so that it becomes \tikz[anchor=base, baseline]. This adjusts the contents of the node to the baseline of the surrounding stuff. May 24 at 14:44
  • 1
    This may be helpful: tex.stackexchange.com/q/622906 May 24 at 18:12

2 Answers 2

7

There are probably better ways.

\documentclass{article}
\usepackage{amsmath}
\usepackage{esint}

\usepackage{tikz}
\usetikzlibrary{shapes}

\DeclareRobustCommand{\oiint}{%
  \mathop{}\!%
  \vcenter{\hbox{%
    \makebox[0pt][l]{%
      \sbox0{$\displaystyle\phantom{\iint}$}%
      \makebox[\wd0]{%
        \begin{tikzpicture}
          \node[
            line width=0.5pt,
            draw,
            ellipse,
            inner xsep=-0.15ex,
            inner ysep=-0.15ex,
          ] {\phantom{+\,}};
        \end{tikzpicture}%
      }%
    }%
  }}\!%
  \iint
}

\begin{document}

\[
\oint_{X} \quad \iint_X \quad \oiint_X
\]

\[
X\iint X
\]

\[
X\oiint X
\]

\end{document}

The idea is to insert an empty mathop in order to get the right spacing before the symbol; then we insert a negative thin space because we add an ordinary symbol, namely the ellipse set to a zero width box that has inside it a box as wide as the integral, containing the ellipse. Next another negative thin space to cancel the one that's inserted in front of \iint. Thus limits will be appended to \iint.

enter image description here

9

The solution without usage of TikZ can be:

\def\circle{.5 0 m .5 .276 .276 .5 0 .5 c -.276 .5 -.5 .276 -.5 0 c
                  -.5 -.276 -.276 -.5 0 -.5 c .276 -.5 .5 -.276 .5 0 c }
\protected\def\oiint{%
  \mathop{\vcenter{
     \pdfliteral{q 10 0 0 6 7 0 cm .06 w \circle S Q}
       }}\!\iint
}

test:
$$
  \oint, \iint_X, \oiint_X
$$

The \pdfliteral is pdfTeX primitive. You can define \def\pdfliteral#1{\special{pdf:literal #1}} in XeTeX or \def\pdfliteral{\pdfextension literal} in LuaTeX.

4
  • I have no idea what that does, but that does the job lol. Could you at least explain how to change the dimensions of the ellipse? So i can do the same with \oiiint.
    – Nolord
    May 24 at 19:36
  • 1
    @Nolord the width of the ellipse is 10, the height is 6 and the shift is 7 bp. If you want to draw an ellipse over \iiint, try 15 0 0 6 9 0 cm. The cm PDF operator sets the current matrix of linear transformation.
    – wipet
    May 24 at 20:01
  • Thanks a lot ! I'm gonna accept the other answer because of what I asked, but I'll definitely use your method.
    – Nolord
    May 25 at 11:17
  • Do you know any way to adapt the macro to different sizes?
    – Nolord
    May 25 at 11:40

You must log in to answer this question.

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