6

I include the TikZ image "One-Point.tex" inside an aligned environment in an equation. However, since it's not exactly the same height above and below the center of the loop, it's not vertically aligned with the rest of the equation.

I was thinking about defining the baseline of the TikZ image from the coordinate (0,0) and somehow have that information be carried over from the standalone file to the main document. Is that possible? Or is there a simpler solution?

enter image description here

Equation

\begin{align}\label{eqn:one-point flow}
    \partial_k \Gamma_{k,a}^{(1)}(q)
    = -\frac{1}{2} \hspace{-5ex} \begin{aligned}
        \includestandalone{"Images/One-Point"}
    \end{aligned}.
\end{align}

One-Point.tex

\documentclass[tikz]{standalone}

\usetikzlibrary{patterns}
\usepackage{icomma}

\tikzset{
    cross/.style={path picture={\draw[black]
        (path picture bounding box.south east) -- (path picture bounding box.north west)
        (path picture bounding box.south west) -- (path picture bounding box.north east);}}
}
\def\radius{1}

\begin{document}
\begin{tikzpicture}[font=\small,pin edge={shorten <=6*\radius},baseline=(0,0)]

    % Loop
    \draw[very thick] (0,0) circle (\radius);
    \node[right] at (45:\radius) {$G_{k,ij}(p_1,p_2)$};
    \node[right] at (-45:\radius) {$G_{k,jk}(p_2,p_3)$};
    \draw[fill=white,cross] (\radius,0) circle (0.175*\radius) node[right=6pt] {$\partial_k R_{k,ij}(p_1,p_2)$};

    % External line
    \draw (-2*\radius,0) -- (-\radius,0) node[pos=0.4,below] {$\varphi_a$};
    \draw[->,semithick,yshift=5pt,shorten >=5pt,shorten <=5pt] (-2*\radius,0) -- (-1.25*\radius,0) node[midway,above] {$q$};

    % Vertex
    \draw[fill=white,postaction={pattern=north east lines}] (-\radius,0) circle (0.2*\radius) coordinate[pin={[shift={(-0.75*\radius,0.1*\radius)}]$\Gamma_{k,aik}^{(3)}(q,p_1,p_3)$}] (lv);

\end{tikzpicture}
\end{document}
  • What options do you use for the standalone package in your main document? – TonioElGringo Sep 14 '17 at 13:11
  • @TonioElGringo The main doc includes \usepackage[subpreambles=true,mode=buildnew]{standalone}. – Casimir Sep 14 '17 at 13:20
7

It is possible to store coordinates from one document and use them in another.

As an example take this standalone picture:

\documentclass[tikz]{standalone}

\usetikzlibrary{tikzmark}

\begin{document}
\begin{tikzpicture}[]

    \draw[red] (-1,-1)-- (2,3);
    \draw[blue] (-1,0)--++(2,0)node[midway,above]{baseline};
    \tikzmark{baseline}{(0,0)};

\end{tikzpicture}
\end{document}

it creates such a picture:

enter image description here

In the aux-file one can find the line

  \pgfsyspdfmark {pgfid1}{1877785}{1877787}

This are the coordinates of the baseline point in sp. This can then be used in a document:

\documentclass{article}
\usepackage{graphicx}

%\pgfsyspdfmark {pgfid1}{1877785}{1877787}
\begin{document}

xxx \raisebox{-1877787sp}{\includegraphics{tikzinput}}

\end{document}

enter image description here

It is also possible to take the math axis into account:

\documentclass{article}
\usepackage{graphicx}

%\pgfsyspdfmark {pgfid1}{1877785}{1877787}
\begin{document}

xxx $\frac{a}{b}\raisebox{\dimexpr -1877787sp+\fontdimen22\textfont2}{\includegraphics{tikzinput}}$

\end{document}

enter image description here

The whole system can be automated rather easily: One needs a version of the \tikzmark command which writes the values not the aux-file (which can contain other stuff that could be problematic) but to some other file, and the main document can then import this values. (I have code for this but currently only for tikzmarks which are used outside of tikzpictures).

  • Wow, that's cool stuff. You say this could be automated rather easily. Then I think this functionality should become part of the standalone package. I hope @Michael Scharrer sees this answer. – Casimir Sep 15 '17 at 10:35
  • Imho it is more the tikzmark library who should add such a functionality. (I developed it for a A4-formular and didn't use standalone there). The main problem is that tikzmark write to the aux, and that makes it difficult for other document to access the values (aux-files can contain a lot of code that other documents should better not see). If I find some time I will perhaps write the author, but not this week. – Ulrike Fischer Sep 15 '17 at 11:01
4

Several problems here.

First, a minor one. To specify a pair of coordinates as baseline, they should be "protected" by curly braces, i.e: baseline={(0,0)}.

But now the real problem. Even if you specify correctly the baseline, that won't work because you don't want the center of your circle to be aligned with the baseline of the text, but instead with the line of the fraction (which is not at the baseline of the equation).

Unfortunately \vcenter won't work here either, because of the small asymmetry of the figure you already noticed.

The usual approach would be force the tikz figure to have a bounding box which includes only the "symmetrical" part (i.e: leaves out the annotation with Gamma). This can be achieved by adding the following line before the code which creates the annotation:

% ... Previous drawing commands
\path [use as bounding box] (current bounding box.south west) rectangle (current bounding box.north east);

% Vertex
% remaining \draw command

Usually this would produce the desired result. However, in this case, since the figure is created in a standalone document, this won't work either, because standalone package clips the contents of the TikZ figure to its bounding box, and thus it will clip part of the Gamma expression.

Using this in your main document:

% ...
= -\frac{1}{2}\hspace{-3ex}\vcenter{$\includestandalone{figs/One-Point}$}

Produces this:

Result

You can see that the vertical alignment is correct, but the part of the figure outside of the bounding box is missing, because standalone clipped it.

I don't know how to solve this, except for not using standalone for this particular figure. Using this approach, this is my complete code:

Main file:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{patterns}
\tikzset{
    cross/.style={path picture={\draw[black]
        (path picture bounding box.south east) -- (path picture bounding box.north west)
        (path picture bounding box.south west) -- (path picture bounding box.north east);}}
}
\begin{document}
\begin{align}\label{eqn:one-point flow}
    \partial_k \Gamma_{k,a}^{(1)}(q)
    = -\frac{1}{2}\hspace{-3ex}\vcenter{$\input{figs/onepoint}$}
\end{align}

\end{document}

figs/onepoint.tex:

\begin{tikzpicture}[font=\small,pin edge={shorten <=6*\radius}]
\def\radius{1}

    % Loop
    \draw[very thick] (0,0) circle (\radius);
    \node[right] at (45:\radius) {$G_{k,ij}(p_1,p_2)$};
    \node[right] at (-45:\radius) {$G_{k,jk}(p_2,p_3)$};
    \draw[fill=white,cross] (\radius,0) circle (0.175*\radius) node[right=6pt] {$\partial_k R_{k,ij}(p_1,p_2)$};

    % External line
    \draw (-2*\radius,0) -- (-\radius,0) node[pos=0.4,below] {$\varphi_a$};
    \draw[->,semithick,yshift=5pt,shorten >=5pt,shorten <=5pt] (-2*\radius,0) -- (-1.25*\radius,0) node[midway,above] {$q$};

    \path [use as bounding box] (current bounding box.south west) rectangle (current bounding box.north east);
    % Vertex
    \draw[fill=white,postaction={pattern=north east lines}] (-\radius,0) circle (0.2*\radius) coordinate[pin={[shift={(-0.75*\radius,0.1*\radius)}]$\Gamma_{k,aik}^{(3)}(q,p_1,p_3)$}] (lv);
\end{tikzpicture}

Result:

Result

  • Thanks for pointing out all the options! Perhaps it's simplest to just do some manual tinkering in this case and go with \raisebox{1ex}{\includestandalone{"Images/One-Point"}}... – Casimir Sep 14 '17 at 14:20

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.