Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to use TikZ figures as part of an equation, but I am only able make either the positioning or the scaling appear correctly.

For instance, giving my figures the correct size using "resizebox" makes them appear as follows (enlarged for ease of viewing):

example

If I specify the baseline, then it appears that the resizing is skipped.

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{tikz}
    \usetikzlibrary{calc}
\newcommand{\leftribbon}{%
\resizebox{!}{10pt}{
\begin{tikzpicture}%[baseline={($ (current bounding box) - (0,0pt) $)}]
        \node (start) at (0,1) {};
        \node (end) at (1,1) {};
        \node (bottom) at (0.5,0) {};

        \path[color=black, line width=2pt] [out=180, in=-135] (bottom.center) edge (end.west);
        \path[color=white, line width=6pt] [out=-45, in=0] (start.east) edge (bottom.center);
        \path[color=black, line width=2pt] [out=-45, in=0] (start.east) edge (bottom.center);
\end{tikzpicture}
}%
}

\newcommand{\rightribbon}{%
\resizebox{!}{10pt}{
\begin{tikzpicture}%[baseline={($ (current bounding box) - (0,0pt) $)}]
\begin{scope}[xscale=-1]
    \node (start) at (0.3,1) {};
    \node (end) at (0.7,1) {};
    \node (bottom) at (0.5,0) {};

    \path[color=black, line width=2pt] [out=180, in=-135] (bottom.center) edge (end.west);
    \path[color=white, line width=6pt] [out=-45, in=0] (start.east) edge (bottom.center);
    \path[color=black, line width=2pt] [out=-45, in=0] (start.east) edge (bottom.center);
\end{scope}
\end{tikzpicture}
}%
}

\newcommand{\ribcup}{%
\resizebox{!}{10pt}{
\begin{tikzpicture}%[baseline={($ (current bounding box) - (0,0pt) $)}]
\begin{scope}[xscale=1]
    \node (start) at (-0.5,1) {};
    \node (end) at (0.5,1) {};
    \node (bottom) at (0,0) {};

    \path[color=black, line width=2pt] [out=0, in=-135] (bottom.center) edge (end.west);
    \path[color=black, line width=2pt] [out=-45, in=180] (start.east) edge (bottom.center);
\end{scope}
\end{tikzpicture}
}%
}

\begin{document}
    \[  \langle \leftribbon \rangle = -A^3\langle\ribcup\rangle \]
\end{document}
share|improve this question
    
You code can't compile. The first ` \end{scope}` closes nothing. –  Alain Matthes Jan 31 '12 at 14:07
    
@Altermundus Thanks for catching that, I obviously didn't clean up the code properly before posting it. –  Raeder Jan 31 '12 at 14:13
    
@Raeder, did you try use a raisebox? \raisebox{lift}[extend-above-baseline][extend-below-baseline]{text}. For example: \raisebox{-2pt}{\leftribbon} –  szantaii Jan 31 '12 at 14:38
    
No need to use \raisebox, baseline is enough with the tikzpicture. –  Alain Matthes Jan 31 '12 at 15:14
    
The code compiles with article but not with standalone with the last TL updated. –  Alain Matthes Jan 31 '12 at 15:15
add comment

1 Answer

up vote 5 down vote accepted

To answer at your question , you need only to use baseline like this :

\newcommand{\leftribbon}{%
\resizebox{!}{10pt}{
\begin{tikzpicture}[baseline]
        \node[inner sep=0pt] (start) at (0,1) {};
        \node[inner sep=0pt] (end) at (1,1) {};
        \node[inner sep=0pt] (bottom) at (0.5,0) {};

        \path[color=black, line width=2pt] [out=180, in=-135] (bottom.center) edge (end.west);
        \path[color=white, line width=6pt] [out=-45, in=0] (start.east) edge (bottom.center);
        \path[color=black, line width=2pt] [out=-45, in=0] (start.east) edge (bottom.center);
\end{tikzpicture}
}%
}

In your case you need to add .base for example like this :

\newcommand{\leftribbon}{%
\resizebox{!}{10pt}{
\begin{tikzpicture}[baseline= {($(current bounding box.base)-(-2pt,-2pt)$)}]
        \node[inner sep=0pt] (start) at (0,1) {};
        \node[inner sep=0pt] (end) at (1,1) {};
        \node[inner sep=0pt] (bottom) at (0.5,0) {};

        \path[color=black, line width=2pt] [out=180, in=-135] (bottom.center) edge (end.west);
        \path[color=white, line width=6pt] [out=-45, in=0] (start.east) edge (bottom.center);
        \path[color=black, line width=2pt] [out=-45, in=0] (start.east) edge (bottom.center);
\end{tikzpicture}
}%
}

I update your code and I remove the \resizebox (I think that it's not necessary here) Firstly : coordinate is better here than node if you want than you need to add inner sep=0pt. I added some styles to modify the result easily.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{char/.style = { color=black,line width=.6pt}}
\tikzset{effet/.style = { color=white,line width=1.2pt}} 

\newcommand{\leftribbon}[1][1]{%
\begin{tikzpicture}[baseline,scale=#1]
        \coordinate (start) at (0,10pt) ;
        \coordinate (end) at (10pt,10pt) ;
        \coordinate (bottom) at (5pt,0) ;

        \draw[char] [out=180, in=-135] (bottom.center) edge (end.west);
        \draw[effet] [out=-45, in=0] (start.east) edge (bottom.center);
        \draw[char] [out=-45, in=0] (start.east) edge (bottom.center);
\end{tikzpicture}
}%  


\newcommand{\rightribbon}[1][1]{%    
\begin{tikzpicture}[baseline,scale=#1]  
\begin{scope}[xscale=-1]
    \coordinate (start) at (3pt,10pt);
    \coordinate (end) at (7pt,10pt) ;
    \coordinate (bottom) at (5pt,0);

    \draw[char] [out=180, in=-135] (bottom.center) edge (end.west);
    \draw[effet] [out=-45, in=0] (start.east) edge (bottom.center);
    \draw[char] [out=-45, in=0] (start.east) edge (bottom.center);
\end{scope}
\end{tikzpicture}
}%


\newcommand{\ribcup}[1][1]{%    
\begin{tikzpicture}[baseline,scale=#1]
    \coordinate (start) at (-5pt,10pt) ;
    \coordinate (end) at (5pt,10pt) ;
    \coordinate (bottom) at (0pt,0pt);

    \path[char] [out=0, in=-135] (bottom.center) edge (end.west);
    \path[char] [out=-45, in=180] (start.east) edge (bottom.center);
\end{tikzpicture}
}%


\begin{document}
     \[
      \langle \leftribbon[.8]\rangle = -A^3   \langle\ribcup[.8]\rangle
    \]  
\end{document} 

enter image description here

share|improve this answer
    
If you want to add \resizebox, now I think it's possible but not necessary. –  Alain Matthes Jan 31 '12 at 15:02
    
Just out of curiosity, why is coordinate better than node here? –  Roelof Spijker Jan 31 '12 at 15:25
    
First the node is empty and in this case, I prefer to use coordinate and here inner sep changes the drawing. You can try with an without inner sep=0pt. But if you use nodewith precaution, the result is the same. –  Alain Matthes Jan 31 '12 at 15:36
    
Ah yes, the inner sep is indeed important. –  Roelof Spijker Jan 31 '12 at 15:41
    
Thanks for you help! With some small modifications, this (making the picture sizes absolute, in terms of pt) solves my problem. –  Raeder Feb 3 '12 at 10:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.