2

When I put a formula inside a node in tikzpicture while using beamer, it doesn't show it as it does when I don't use beamer. Consider the code here:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{frame}
    \begin{equation}
        x^2
    \end{equation}
    \begin{tikzpicture}
        \node at(0,0) (Example:) {
            \begin{minipage}{2cm}
                $x^2$
            \end{minipage}
        };
    \end{tikzpicture}
\end{frame}
\end{document}

here is the output: enter image description here

I have tried compiling it with both XeLatex and PdfLatex, still no luck!

How can I get a more beautiful $x^2$ when using beamer and tikzpicture simultaneously?

This $x^2$ is what I get when I don't use beamer document and use article mode:

enter image description here

Edit: As for the answer of @samcarter_is_at_topanswers.xyz, I aim to use Persian fonts and Xepersian in beamer because the language of my presentation is Persian and hence using Serif font is of no good here. This is what I want to have in my presentation:

enter image description here This is the code for the image above:

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{xepersian}
\settextfont{Yas}
\setdigitfont{Yas}
\begin{document}
    \begin{equation}
        x^2
    \end{equation}
    \begin{tikzpicture}
        \node at(0,0) (Example:) {
            \begin{minipage}{2cm}
                $x^2$
            \end{minipage}
        };
    \end{tikzpicture}
\end{document}
  • Welcome to TeX.SE! What exactly do you mean by "more beautiful"? The alignment, the font, the spacing, ... – Οὖτις Mar 03 '23 at 08:36
  • 1
    You're question isn't really clear, but are you maybe looking for \usefonttheme[onlymath]{serif}? – samcarter_is_at_topanswers.xyz Mar 03 '23 at 08:57
  • @Οὖτις The font I guess, since it is not the same when I'm not using beamer but entering a the same formula inside a node. Maybe I'll need to edit the question to clarify "more beautiful" more regorously. – Amirreza Taghizadeh Mar 03 '23 at 08:59
  • @samcarter_is_at_topanswers.xyz I have edited the question, is it clear enough now? – Amirreza Taghizadeh Mar 03 '23 at 09:05
  • 1
    If the problem depends on the use of a Persian font, then the code of the MWE in the question should show that too, so in particular use a (free) Persian font. – cabohah Mar 03 '23 at 09:25
  • @cabohah I've tried with a Persian font (Yas) but the problem exists in beamer mode but not in article mode. – Amirreza Taghizadeh Mar 03 '23 at 09:34
  • I've not said, you the code should use article. I've said, the code should show the problem. So if it depends on beamer and a Persian font, the code should use beamer and a Persian font. The MWE is not just for fun. We just should be able to reproduce the issue without any changes to the code. Otherwise the code is not a MWE. – cabohah Mar 03 '23 at 09:49

1 Answers1

2

Beamer uses a sans serif font by default. If you would like to use serif font for math, you can use \usefonttheme[onlymath]{serif}:

\documentclass{beamer}
\usepackage{tikz}
\usefonttheme[onlymath]{serif}
\begin{document}
\begin{frame}
    \begin{equation}
        x^2
    \end{equation}
    \begin{tikzpicture}
        \node at(0,0) (Example:) {
            \begin{minipage}{2cm}
                $x^2$
            \end{minipage}
        };
    \end{tikzpicture}
\end{frame}
\end{document}

enter image description here


If you'd like to use custom fonts, use the professionalfonts theme:

% !TeX TS-program = xelatex
\documentclass{beamer}
\usepackage{tikz}
\usefonttheme{professionalfonts}
\usepackage{xepersian}
\settextfont{Yas}
\setdigitfont{Yas}
\begin{document}
\begin{frame}
    \begin{equation}
        x^2
    \end{equation}
    \begin{tikzpicture}
        \node at(0,0) (Example:) {
            \begin{minipage}{2cm}
                $x^2$
            \end{minipage}
        };
    \end{tikzpicture}
\end{frame}
\end{document}

enter image description here