9

I have a tikzcd diagram

\begin{center}
\begin{tikzcd}
F \arrow[r] \arrow[d] 
& * \arrow[d] \\
X \arrow[r, "f"] & Y \\
\end{tikzcd}
\end{center}

which looks like this:

Pullback square

I wish to add a symbol which indicates that this is a pullback square. Having looked both here and here, I have found the solution to create my own tikz-cd symbol, and insert that into the diagram.

The code for my symbol is this:

\newcommand{\foo}[1]{%
\begin{tikzpicture}[#1]%
\draw (0,0) -- (1ex,0ex);%
\draw (1ex,0ex) -- (1ex,1ex);%
\end{tikzpicture}%
 }

This is basically the bottom and right hand edge of a square.

To add this symbol into the diagram, I am changing the code for the diagram to:

\begin{center}
\begin{tikzcd}
F \arrow[r] \arrow[d] 
\arrow[dr, phantom, "\foo{} " , very near start, color=black]
& * \arrow[d] \\
X \arrow[r, "f"] & Y \\
\end{tikzcd}
\end{center}

As far as I know, this should be creating an invisible arrow, and putting my symbol at its head. Indeed, something does appear, but its not my what I want:

enter image description here

What should appear is something like this (designed in MSpaint):

enter image description here

Which is the same thing except the symbol with the correct symbol.

What's going wrong? Should I be approaching this in a different way?

9

Your approach nests tikzpictures. The standard way to avoid that is to use \saveboxes.

\documentclass{article}
\usepackage{tikz-cd}
\newsavebox{\pullback}
\sbox\pullback{%
\begin{tikzpicture}%
\draw (0,0) -- (1ex,0ex);%
\draw (1ex,0ex) -- (1ex,1ex);%
\end{tikzpicture}}
\begin{document}
\begin{center}
\begin{tikzcd}
F \arrow[r] \arrow[d] 
\arrow[dr, phantom, "\usebox\pullback" , very near start, color=black]
& * \arrow[d] \\
X \arrow[r, "f"] & Y \\
\end{tikzcd}
\end{center}
\end{document}

enter image description here

You defined your command with a parameter, which you did not use. Let's assume that there is a need for such parameters. Then \saveboxes are unhandy. Therefore I add an alternative: a path picture with as many things fixed as you can think of. E.g. - is to say that there should not be an arrow, etc. (I understand that it is very unlikely that you want the symbol to be red, this is just to illustrate that parameters work here.)

\documentclass{article}
\usepackage{tikz-cd}
\tikzset{pullback/.style={minimum size=1.2ex,path picture={
\draw[opacity=1,black,-,#1] (-0.5ex,-0.5ex) -- (0.5ex,-0.5ex) -- (0.5ex,0.5ex);%
}}}
\begin{document}
\begin{center}
\begin{tikzcd}
F \arrow[r] \arrow[d] 
\arrow[dr, phantom," " {pullback=red}, very near start, color=black]
& * \arrow[d] \\
X \arrow[r, "f"] & Y \\
\end{tikzcd}
\end{center}
\end{document}

enter image description here

5

Inside a tikzpicture, along a path, you can put not only node but also pic.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[bmr/.pic={
\draw (2mm,0)--++(-90:2mm)--++(180:2mm);
}]
\path
(0,0)     node (F) {$F$}
+(-45:.2) pic[scale=.8,red]{bmr}
+(0:1.5)  node (star) {$*$}
++(-90:1) node (X) {$X$}
+(0:1.5)  node (Y) {$Y$};
\draw[->] (F)--(star);
\draw[->] (F)--(X);
\draw[->] (X)--(Y) node[midway,above,scale=.6]{$f$};
\draw[->] (star)--(Y);
\end{tikzpicture}   
\end{document}
5

Why don't you simply insert the \lrcorner symbol?

 \documentclass[svgnames]{article}
\usepackage{tikz-cd, amsmath, amssymb}%

\begin{document}

\begin{center}
\begin{tikzcd}
F \arrow[r] \arrow[d]
\arrow[dr, phantom, "\scalebox{1.5}{\color{IndianRed}$\lrcorner$}" , very near start, color=black]
& * \arrow[d] \\
X \arrow[r, "f"] & Y \\
\end{tikzcd}
\end{center}

\end{document} 

enter image description here

  • I should perhaps have stated - I don't like the way this looks and so am looking for alternatives – Matt Aug 9 at 22:19
  • I don't see any difference with the other images, except perhaps in size. Would you have a link to what you'd like? – Bernard Aug 9 at 22:24
  • Size is indeed my problem. – Matt Aug 9 at 22:25
  • 1
    And with a \scalebox (please see my update)? – Bernard Aug 9 at 22:44
  • This indeed would be great - I have marked another as the answer already but this works well. – Matt Aug 9 at 23:41

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.