3

How to properly align Tikz pictures in Latex environment to get the following picture?

enter image description here

My trial code does not compile,

\documentclass[preview]{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}

\begin{equation*}
    A = \frac{%
        \begin{tikzpicture}
            \draw (0,0) to[bend left] (1,0) to[bend left] (0,0);
        \end{tikzpicture}
    }{%
        \begin{tikzpicture}
            \def\L{1.0} 
            \matrix[column sep=.1cm, row sep=2mm]
            {   
                \draw (0,0) to[bend left] (\L,0) to[bend left] (0,0);
                &
                \node at (0,0) {$-$};
                &
                \draw[dashed] (0,0) -- (\L,0);
                \draw[xshift=\L cm] (0,0) to[bend left] (\L,0) to[bend left] (0,0); \\
            };
        \end{tikzpicture}
    }
\end{equation*}

\end{document}
  • please, extend your code fragment to complete small document ... – Zarko Dec 16 '18 at 3:05
3

Generally you can control the vertical alignment with the baseline option.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{equation*}
    A = \frac{%
        \begin{tikzpicture}[baseline={(0,-0.1)}]
            \draw (0,0) to[bend left] (1,0) to[bend left] (0,0);
        \end{tikzpicture}
    }{%
    \begin{tikzpicture}[baseline={(0,-0.1)}]
            \draw (0,0) to[bend left] (1,0) to[bend left] (0,0);
     \end{tikzpicture}
     -
    \begin{tikzpicture}[baseline={(0,-0.1)}]
            \draw (0,0) to[bend left] (1,0) to[bend left] (0,0);
            \draw[dashed](0,0) -- (-1,0);
     \end{tikzpicture}
    }
\end{equation*}

\end{document}

enter image description here

I don't know what these objects represent, so you may want to use another baseline.

Note that you can use a TikZ matrix:

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}

\begin{equation*}
    A = \frac{%
        \begin{tikzpicture}[baseline]
            \draw (0,0) to[bend left] (1,0) to[bend left] (0,0);
        \end{tikzpicture}
    }{%
        \begin{tikzpicture}[baseline]
            \def\L{1.0} 
            \matrix[column sep=.1cm, row sep=2mm,ampersand replacement=\&]
            {   
                \draw (0,0) to[bend left] (\L,0) to[bend left] (0,0);
                \&
                \node at (0,0) {$-$};
                \&
                \draw[dashed] (0,0) -- (\L,0);
                \draw[xshift=\L cm] (0,0) to[bend left] (\L,0) to[bend left] (0,0); \\
            };
        \end{tikzpicture}
    }
\end{equation*}

\end{document}

enter image description here

  • Thanks! It seems that the more versatile matrix in tikzpicture does not work with \frac. Although baseline is one answer to this figure, it will become difficult to deal with multiple rows of figure in the denominator. – Kevin Powell Dec 16 '18 at 6:14
  • @KevinPowell You can definitely use a matrix, just add ampersand replacement=\& and replace & by \&. – marmot Dec 16 '18 at 7:42
  • That's quite neat! Why [baseline] option centers the figure in the numerator? It is black magic for me. – Kevin Powell Dec 17 '18 at 7:42
4
\documentclass{article}
\usepackage{tikz}

\begin{document}
\[
A = \frac{\tikz[baseline=1pt]{\draw  (-1.5,0) to[bend left] (-0.5,0) to[bend left] (-1.5,0);}}
         {\tikz{\draw  (-1.5,0) to[bend left] (-0.5,0) to[bend left] (-1.5,0)
                       ( 0.5,0) to[bend left] ( 1.5,0) to[bend left] ( 0.5,0);
                \draw[dashed, shorten >=1mm, shorten <=1mm] (-0.5,0) -- (0.5,0);}
         }
\]
\end{document}

enter image description here

  • How is that different from my answer except that you define \M but do not use it? The only thing apart from the unused definition I can see is the use of baseline, which is precisely what I am using. – marmot Dec 16 '18 at 3:38
  • @marmot the denominator is different. I think there's an error here, because the minus is missing. – CarLaTeX Dec 16 '18 at 4:04
  • 2
    I would create a pic for the shapes, and suggest to use dots instead of dashes, which could be confused with the minus (@marmot, too). – CarLaTeX Dec 16 '18 at 4:43
  • @CarLaTeX That's a brilliant idea! – Kevin Powell Dec 16 '18 at 6:10
  • @marmot, definition of \M is left from some my experiments (now deleted). baseline is used slightly differently. also coordinates of elements are different. however you still can look on my answer as small variation of yours ... (but i wrote it without seeing yours). – Zarko Dec 16 '18 at 7:22

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.