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}
7
  • Welcome to TeX.SE! What exactly do you mean by "more beautiful"? The alignment, the font, the spacing, ... Mar 3, 2023 at 8:36
  • 1
    You're question isn't really clear, but are you maybe looking for \usefonttheme[onlymath]{serif}? Mar 3, 2023 at 8: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. Mar 3, 2023 at 8:59
  • @samcarter_is_at_topanswers.xyz I have edited the question, is it clear enough now? Mar 3, 2023 at 9: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 3, 2023 at 9:25

1 Answer 1

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

9
  • Thanks for the answer, I appreciate it. However, I don't aim to use serif font, since the language of my presentation is Persian and I want to use persian fonts and Xepersian package. what do you suggest I should do? Limit my expectations...? :)) Mar 3, 2023 at 9:11
  • @AmirrezaTaghizadeh Then please edit your question to include a minimal working example of your actual problem. If you want math to look like i.sstatic.net/TUGrF.png then you want to use serif math, because that's what you show in your image. Mar 3, 2023 at 9:14
  • I edited my question. I would appreciate it if you could consider reopening it. I think it is a problem when you are writing in Persian and using beamer since I've seen a persian presentation with this issue. Mar 3, 2023 at 9:23
  • @AmirrezaTaghizadeh Your question does not show any code with Persian fonts Mar 3, 2023 at 9:26
  • Let me edit that once more. Mar 3, 2023 at 9:27

You must log in to answer this question.

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